Skip to content

Instantly share code, notes, and snippets.

@cgcardona cgcardona/Mecenas.cash
Last active Nov 24, 2019

Embed
What would you like to do?
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));
}
}
@mr-zwets

This comment has been minimized.

Copy link

mr-zwets commented Nov 16, 2019

thanks for the code, handy example! Spotted a little mistake

require(nSequence.length == 32);

should be hashOutput.length== 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.