+ source: 'pragma cashscript >=0.10.0;\n\n/* This is an unofficial CashScript port of Licho\'s Mecenas contract. It is\n * not compatible with Licho\'s EC plugin, but rather meant as a demonstration\n * of covenants in CashScript.\n * The time checking has been removed so it can be tested without time requirements.\n */\ncontract Mecenas(bytes20 recipient, bytes20 funder, int pledge/*, int period */) {\n function receive() {\n // require(tx.age >= period);\n\n // Check that the first output sends to the recipient\n require(tx.outputs[0].lockingBytecode == new LockingBytecodeP2PKH(recipient));\n\n int minerFee = 1000;\n int currentValue = tx.inputs[this.activeInputIndex].value;\n int changeValue = currentValue - pledge - minerFee;\n\n // If there is not enough left for *another* pledge after this one, we send the remainder to the recipient\n // Otherwise we send the remainder to the recipient and the change back to the contract\n if (changeValue <= pledge + minerFee) {\n require(tx.outputs[0].value == currentValue - minerFee);\n } else {\n require(tx.outputs[0].value == pledge);\n require(tx.outputs[1].lockingBytecode == tx.inputs[this.activeInputIndex].lockingBytecode);\n require(tx.outputs[1].value == changeValue);\n }\n }\n\n function reclaim(pubkey pk, sig s) {\n require(hash160(pk) == funder);\n require(checkSig(s, pk));\n }\n}\n',
0 commit comments