-
Notifications
You must be signed in to change notification settings - Fork 5
/
Block.m
29 lines (26 loc) · 880 Bytes
/
Block.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
classdef Block < handle
properties
index % index of block
data % transcation data
previousHash % the previous hash
selfHash % current hash
nonce % random number
end
methods
function obj = Block(index, data, previousHash)
if nargin == 2 % genesis block!
obj.index = index ;
obj.data = data ;
elseif nargin == 3
obj.index = index ;
obj.data = data ;
obj.previousHash = previousHash;
end
end
% The function below converts all data on the block except 'nonce' and
% 'selfHash' into characters, which is then used to calculate selfHash.
function str = getCombined(obj)
str = strcat([num2str(obj.index), obj.previousHash, join(obj.data)]);
end
end
end