1+ pragma cashscript ^0.6.0;
2+
3+ // This is an experimental contract for a more "streaming" Mecenas experience
4+ // Completely untested, just a concept
5+ contract Mecenas(bytes4 initialBlock, int pledgePerBlock, bytes20 recipient, bytes20 funder) {
6+ function receive(pubkey pk, sig s, int pledge) {
7+ require(checkSig(s, pk));
8+
9+ int initial = int(initialBlock);
10+ require(tx.time >= initial);
11+
12+ // Pledge amount calculation is done in client, verified in contract
13+ // When OP_MUL is enabled this can be done in contract
14+ // Double require to account for integer division
15+ int passedBlocks = int(tx.locktime) - initial;
16+ require(pledge / passedBlocks == pledgePerBlock);
17+ require((pledge - 1) / passedBlocks != pledgePerBlock);
18+
19+ // Cut out old initialBlock (PUSH1 0x04 <inheritor>)
20+ // Insert new initialBlock (PUSH1 0x04 <newInheritor>)
21+ bytes newContract = 0x4c04 + tx.locktime + tx.bytecode.split(6)[1];
22+
23+ int minerFee = 1000; // hardcoded fee
24+ int intValue = int(bytes(tx.value));
25+
26+ if (intValue <= pledge + minerFee) {
27+ bytes8 amount1 = bytes8(intValue - minerFee);
28+ bytes34 out1 = new OutputP2PKH(amount1, recipient);
29+ require(hash256(out1) == tx.hashOutputs);
30+ } else {
31+ bytes8 amount1 = bytes8(pledge);
32+ bytes8 amount2 = bytes8(intValue - pledge - minerFee);
33+ bytes34 out1 = new OutputP2PKH(amount1, recipient);
34+ bytes32 out2 = new OutputP2SH(amount2, hash160(newContract));
35+ require(hash256(out1 + out2) == tx.hashOutputs);
36+ }
37+ }
38+
39+ function reclaim(pubkey pk, sig s) {
40+ require(hash160(pk) == funder);
41+ require(checkSig(s, pk));
42+ }
43+ }
0 commit comments