Mecenas CashScript Contract for recurring payments. More info: https://www.reddit.com/r/btc/comments/cuzi1o/mecenas_recurring_payment_smart_contract_since_we/. More info about CashScript: https://developer.bitcoin.com/cashscript/docs/language
contract Mecenas(bytes20 pkh, bytes20 pkh2, int pledge) { | |
function protege(pubkey pk, sig s, bytes ver, bytes hPhSo, bytes scriptCode, bytes value, bytes nSequence, bytes hashOutput, bytes tail ) { | |
require(ver.length == 4); | |
require(hPhSo.length == 100); | |
require(value.length == 8); | |
require(nSequence.length == 4); | |
require(nSequence.length == 32); | |
require(tail.length == 8); | |
require(checkSig(s, pk)); | |
bytes preimage = ver + hPhSo + scriptCode + value + nSequence + hashOutput + tail; | |
require(checkDataSig(datasig(s), sha256(preimage), pk)); | |
int fee = 1000; | |
// num2bin? | |
bytes amount2 = bytes(pledge); | |
bytes amount1 = bytes(int(value) - pledge - fee); | |
bytes opDup = 0x76; | |
bytes opEqual = 0x87; | |
bytes opHash160 = 0xa9; | |
bytes pushHash = 0x14; | |
bytes newVarInt1 = 0x17; | |
bytes newVarInt2 = 0x19; | |
bytes opEqualverify = 0x88; | |
bytes opChecksig = 0xac; | |
// original spedn | |
// bin [_, rawscr] = scriptCode @ 3; | |
// is this split correctly? | |
bytes rawscr = scriptCode.split(3)[0]; | |
// how to check for 30 days? | |
require(tx.time >= 30); | |
require(int(ver) >= 2); | |
bytes out1 = amount1 + newVarInt1 + opHash160 + pushHash + hash160(rawscr) + opEqual; | |
bytes out2 = amount2 + newVarInt2 + opDup + opHash160 + pushHash + pkh + opEqualverify + opChecksig; | |
require(hash256(out1 + out2) == sha256(hashOutput)); | |
} | |
function mecenas(pubkey pk, sig s) { | |
require(hash160(pk) == pkh2); | |
require(checkSig(s, pk)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
thanks for the code, handy example! Spotted a little mistake
should be hashOutput.length== 32