-
Notifications
You must be signed in to change notification settings - Fork 1
/
mecenas_v1.1.spedn
executable file
·59 lines (48 loc) · 1.94 KB
/
mecenas_v1.1.spedn
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
54
55
56
57
58
59
// Mecenas Contract, version 1.1
// Changes from v. 1 :
// Challenge protege takes full preimage as an argument
// Recurring period is passed as argument instead of being hardcoded
// The last payment is claimable.
contract Mecenas(
Ripemd160 receiverPKH,
Ripemd160 patronPKH,
int pledge,
TimeSpan period
) {
challenge refresh(PubKey pk, Sig sig, bin preimage){
// preimage deserializaion
bin [ver, _] = preimage @ 4; // nVersion
bin [_, tail] = preimage @ (size(preimage) - 40); // hashOutput + nLocktime + sighash
bin [hashOutput, _] = tail @ 32;
bin [torso, _] = preimage @ (size(preimage) - 44);
bin [_, belly] = torso @ 104;
bin [scriptCode, value] = belly @ (size(belly) - 8);
verify checkSig(sig, pk);
verify checkDataSig(toDataSig(sig), sha256(preimage), pk);
int fee = 1000;
verify checkSequence(period);
verify bin2num(ver) >= 2;
if (bin2num(value) <= pledge +fee) {
verify hash160(pk) == receiverPKH;
verify checkSig(sig,pk);}
else {
bin amount2 = num2bin(pledge, 8);
bin amount1 =num2bin(bin2num(value) - pledge - fee, 8);
bin opDup = 0x76;
bin opEqual = 0x87;
bin opHash160 = 0xa9;
bin pushHash = 0x14;
bin newVarInt1 = 0x17;
bin newVarInt2 = 0x19;
bin opEqualverify = 0x88;
bin opChecksig = 0xac;
bin [_, rawscr] = scriptCode @ 3;
bin out1 = amount1 . newVarInt1 . opHash160 . pushHash . hash160(rawscr) . opEqual ;
bin out2 = amount2 . newVarInt2 . opDup . opHash160 . pushHash . receiverPKH . opEqualverify . opChecksig;
verify hash256(out1 . out2) == Sha256(hashOutput);}
}
challenge patron(PubKey patronPK, Sig sig) {
verify hash160(patronPK) == patronPKH;
verify checkSig(sig, patronPK);
}
}