Created
August 25, 2019 06:35
-
-
Save cgcardona/5417b139fd244e2d782533a82a04014b to your computer and use it in GitHub Desktop.
Local CashScript Contract for local.bitcoin.com
This file contains 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 Local( | |
bytes20 sellerPHK, // Hash160 of seller's public key | |
bytes20 buyerPKH, // Hash160 of buyer's public key | |
bytes20 arbitratorPKH, // Hash160 of arbitrator's public key | |
bytes escrowKey // Nonce (just some unimportant random bytes unique per exchange) | |
) { | |
function spend( | |
sig spenderSig, | |
pubkey spenderPK, | |
datasig oracleSig, | |
pubkey oraclePK, | |
int actionByte | |
) { | |
bytes20 verifySpenderPKH = bytes20(0); | |
bytes20 verifyOraclePKH = bytes20(0); | |
if (actionByte == 1) { | |
// OP_1 is the code for "releaseBySeller" | |
verifySpenderPKH = buyerPKH; | |
verifyOraclePKH = sellerPHK; | |
} else if (actionByte == 2) { | |
// OP_2 is the code for "releaseByArbitrator" | |
verifySpenderPKH = buyerPKH; | |
verifyOraclePKH = arbitratorPKH; | |
} else if (actionByte == 3) { | |
// OP_3 is the code for "returnByBuyer" | |
verifySpenderPKH = sellerPHK; | |
verifyOraclePKH = buyerPKH; | |
} else if (actionByte == 4) { | |
// OP_4 is the code for "returnByArbitrator" | |
verifySpenderPKH = sellerPHK; | |
verifyOraclePKH = arbitratorPKH; | |
} else { | |
// Action byte is unknown; fail. | |
require(false); | |
} | |
require(hash160(oraclePK) == verifyOraclePKH); | |
require(hash160(spenderPK) == verifySpenderPKH); | |
// Construct message | |
bytes oracleMessage = escrowKey + bytes(actionByte); | |
// Verify oracle's signature | |
require(checkDataSig(oracleSig, oracleMessage, oraclePK)); | |
// Verify spender's tx signature | |
require(checkSig(spenderSig, spenderPK)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment