Created
September 19, 2019 07:04
-
-
Save rkalis/5532beb24d180f51639a6c9e638bc421 to your computer and use it in GitHub Desktop.
CashScript port of Licho's Last Will contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract LastWill( | |
bytes20 pkh, | |
bytes20 pkh2, | |
bytes20 pkh3 | |
) { | |
function refresh( | |
pubkey pk, | |
sig s, | |
bytes ver, | |
bytes hPhSo, | |
bytes scriptCode, | |
bytes value, | |
bytes nSequence, | |
bytes hashOutput, | |
bytes tail | |
) { | |
require(ripemd160(sha256(pk)) == pkh); | |
require(checkSig(s, pk)); | |
bytes preimage = ver + hPhSo + scriptCode + value + nSequence + hashOutput + tail; | |
require(checkDataSig(datasig(s), sha256(preimage), pk)); | |
int fee = 1000; | |
// proper sized bytes<->int conversion still needs to be added | |
// Right now it always converts integer to bytes8 (which is ok in this case) | |
// bytes amount = bytes8(int(value) - fee); | |
bytes amount = bytes(int(value) - fee); | |
// proper sized bytes still need to be added (bytes1) | |
bytes opEqual = 0x87; | |
bytes opHash160 = 0xa9; | |
bytes pushHash = 0x14; | |
bytes newVarInt = 0x17; | |
bytes rawscr = scriptCode.split(1)[1]; | |
require(tx.age >= 7 days); | |
require(int(ver) >= 2); | |
require(hash256(amount + newVarInt + opHash160 + pushHash + hash160(rawscr) + opEqual) == bytes32(hashOutput)); | |
} | |
function cold(pubkey pk, sig s) { | |
require(hash160(pk) == pkh2); | |
require(checkSig(s, pk)); | |
} | |
function inherit(pubkey pk, sig s) { | |
require(tx.age >= 180 days); | |
require(hash160(pk) == pkh3); | |
require(checkSig(s, pk)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment