Last active
October 30, 2020 06:51
-
-
Save thr0wn/2dfd29f72888c05bce2ccabf03c8c9e8 to your computer and use it in GitHub Desktop.
Revisions
-
thr0wn revised this gist
Oct 30, 2020 . 1 changed file with 26 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,32 @@ pragma cashscript ^0.4.0; contract Swap() { function claimToken(sig selfSig, pubkey selfPk, pubkey otherPk, datasig selfDatasig, datasig otherDatasig, bytes message) { // Check that the message was signed by both parts require(checkDataSig(selfDatasig, message, otherPk)); require(checkDataSig(otherDatasig, message, selfPk)); // check itself sig require(checkSig(selfSig, selfPk)); pubkey mSelfPk = int(message.split(?)[?]); bytes? mSelfToken = int(message.split(?)[?]); bytes? mSelfAmount = int(message.split(?)[?]); pubkey mOtherPk = int(message.split(?)[?]); bytes? mOtherToken = int(message.split(?)[?]); bytes? mOtherAmount = int(message.split(?)[?]); int minerFee = 1000; if (mSelfPk === selfPk) { bytes swap = new OutputNullData([mSelfToken, mSelfAmount]); int changeAmount = int(bytes(tx.value)) - minerFee; bytes32 change = new OutputP2SH(bytes8(changeAmount), hash160(selfPk)); require(tx.hashOutputs == hash256(swap + change)); } else { bytes swap = new OutputNullData([mOtherToken, mOtherAmount]); int changeAmount = int(bytes(tx.value)) - minerFee; bytes32 change = new OutputP2SH(bytes8(changeAmount), hash160(otherPk)); require(tx.hashOutputs == hash256(swap + change)); } } } -
thr0wn created this gist
Oct 28, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ pragma cashscript ^0.4.0; contract Swap(pubkey escrowPk) { function spendTokenA(sig address2Sig, pubkey address2Pk, datasig escrowSig, bytes escrowMessage) { // Check that the message was signed by the escrow require(checkDataSig(escrowSig, escrowMessage, escrowPk)); // Check that the transaction was signed by the contract owner require(checkSig(address2Sig, address2Pk)); // Check if recipient2Pk is address2Pk pubkey recipient2Pk = int(escrowMessage.split(4)[0]); require(recipient2Pk === address2Pk); } function spendTokenB(sig address1Sig, pubkey address1Pk, datasig escrowSig, bytes escrowMessage) { // Check that the message was signed by the escrow require(checkDataSig(escrowSig, escrowMessage, escrowPk)); // Check that the transaction was signed by the contract owner require(checkSig(address1Sig, address1Pk)); // Check if recipient1Pk is address1Pk pubkey recipient1Pk = int(escrowMessage.split(4)[1]); require(recipient1Pk === address1Pk); } }