forked from obscuren/jeffcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.mu
53 lines (43 loc) · 1.3 KB
/
contract.mu
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
46
47
48
49
50
51
52
53
#define DIFF 1
#define ETH_START_B 2
#define SEED 3
#define JEFF 0
#define BLOCK_F 254
#define BLOCK_N 253
#define ADDR_START 1000
// JeffCoin Genesis :)
contract.storage[BLOCK_N] = 0
// Set the initial number (so we can track block changes)
contract.storage[ETH_START_B] = block.number()
contract.storage[SEED] = 0
contract.storage[DIFF] = 3
contract.storage[JEFF] = tx.sender()
return compile {
if tx.sender() == contract.storage[JEFF] {
if this.data[0] == "die" {
suicide(contract.storage[JEFF])
}
}
var diff = contract.storage[DIFF]
var[2] ndat
ndat[0] = this.data[0]
ndat[1] = contract.storage[SEED]
var nonce = sha3(ndat, sizeof(ndat))
// Check if the mined nonce is correct
for i := 0; i < diff; i++ {
if byte(nonce, i) != 0 {
stop() // invalid nonce
}
}
var blockNo = contract.storage[BLOCK_N]
// Amount of blocks found for the block (used to determine the difficulty)
contract.storage[BLOCK_F + blockNo] = contract.storage[BLOCK_F + blockNo] + 1
// Change the seed
contract.storage[SEED] = contract.storage[SEED] + 1
// Reward 1000 JeffCoin to the miner
contract.storage[ADDR_START + tx.sender()] = contract.storage[ADDR_START + tx.sender()] + 100000
// Check if we need to increase the difficulty
if contract.storage[ETH_START_B] < block.number() {
// TODO update difficulty
}
}