Skip to content

Instantly share code, notes, and snippets.

@cgcardona
Last active December 16, 2019 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgcardona/a5d7481fd9b07a6cafa9909ac95b8751 to your computer and use it in GitHub Desktop.
Save cgcardona/a5d7481fd9b07a6cafa9909ac95b8751 to your computer and use it in GitHub Desktop.
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
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