-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.gs
More file actions
45 lines (40 loc) · 1.04 KB
/
block.gs
File metadata and controls
45 lines (40 loc) · 1.04 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def block_c() {
use "std"
enum Block {
datatime,
nonce,
prev_hash,
transactions,
hash,
create_hash,
__init__,
mine_block,
}
Block __init__ := ldef(father, datatime, transactions, prev_hash) {
father datatime := datatime
father transactions := transactions
father nonce := 0
father prev_hash := prev_hash
father hash := n(father:create_hash(father))
}
Block mine_block := ldef (father, proof_of_work_diff) {
hash_val_temp = ""
for i = 0; i <= proof_of_work_diff; i++ {
hash_val_temp += "0"
}
n = split(to_string(father:hash), " ")
while (n[0] != hash_val_temp) {
father:create_hash(father)
n = split(father:hash, " ")
}
sout "Mined block with hash: "+father:hash+"\n"
}
Block create_hash := ldef(father) {
transactions = father:transactions
typedef string raw_data = father:prev_hash + father:datatime + get_stack("transactions") + to_string(father:nonce)
father hash := to_string(raw_data)
return raw_data
}
return Block
}
to_import("block_c")