Created
July 17, 2019 21:01
-
-
Save vinarmani/65c6be07fba8d9f36b663470c5c4be6f to your computer and use it in GitHub Desktop.
Contract Creation for Padres vs Marlins (Steven vs. Vin) July 17, 2019
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
const jeton = require('jeton-lib') | |
const PrivateKey = jeton.PrivateKey | |
const PublicKey = jeton.PublicKey | |
const Signature = jeton.Signature | |
const OutputScript = jeton.escrow.OutputScript | |
const Transaction = jeton.Transaction | |
// Create the output script | |
var refpk = new PublicKey("029ba4d2d14a5c24e4b7b6aa953ecf24b599e2f5e944412a9d60e5878f0f6a06cd") | |
var stevenpk = new PublicKey("03e34df7c516e3a122ef72f9db4cbcd2302ac7c9ec5b1f52cd5f77740654958f31") | |
var vinpk = new PublicKey("03ef3b289d0c08ab016153975cc028871982a621f35ab548e348ce275bb2b21eca") | |
var outputScriptData = { | |
refereePubKey: refpk, | |
parties: [ | |
{message: 'padreswin', pubKey: stevenpk}, | |
{message: 'marlinswin', pubKey: vinpk} | |
] | |
} | |
outScript = new OutputScript(outputScriptData) | |
console.log(outScript.toAddress()) |
The winner will do the following, inputing the referee's broadcasted signature string and chosen address to send the winnings to:
EDIT
Just realized this will need to be done as two separate transactions for now. so run the code for each of the utxos
// UTXOS to be spent by winner
var utxo1 = new Transaction.UnspentOutput({
txid:
'ab9596efa523e50f2bee749f6ae4cc40cf5bfe6fbf1556e75a4cb994e5700ebd',
vout: 0,
satoshis: 6700000,
scriptPubKey: 'a9144a21989c05afedbedffc20e89f0ac5c13071cb2987'
})
var utxo2 = new Transaction.UnspentOutput({
txid:
'e2dcb47a6cf978ae04758041dc0fefb10e82433bc8c2935f9c9a4a9a32a358ca',
vout: 0,
satoshis: 6700000,
scriptPubKey: 'a9144a21989c05afedbedffc20e89f0ac5c13071cb2987'
})
// Make Transaction from escrow UTXO
sighash = (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID)
// Satoshi's to spend minus 750 for miner fee (just to be safe)
var amountToSpend = utxo1.satoshis - 750
var spendTx = new Transaction()
.from(utxo1) // then another transaction for utxo2
.to(WINNERS_PREFERRED_ADDRESS, amountToSpend)
var refereeSig = Signature.fromString(REFEREE_SIGNATURE_STRING)
var winnerPriv = new PrivateKey("PRIVATE_KEY_IN_WIF_FORMAT")
spendTx.signEscrow(0, winnerPriv , WINNING_MESSAGE, refereeSig, outScript.toScript(), sighash)
console.log(spendTx.toString())
Then broadcast the resulting transaction to claim the winnings
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At the end of the game, the referee runs this code where "message" is either "padreswin" or "marlinswin" depending on the outcome:
Referee then broadcasts that message