Created
July 24, 2019 14:35
-
-
Save owenkellogg/f5c30568eb9ac51ed4a8a3e409506825 to your computer and use it in GitHub Desktop.
baseball_bet_padres_marlins_bch
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
import * as jeton from 'jeton-lib'; | |
const PrivateKey = jeton.PrivateKey | |
const PublicKey = jeton.PublicKey | |
const Signature = jeton.Signature | |
const OutputScript = jeton.escrow.OutputScript | |
const Transaction = jeton.Transaction | |
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' | |
}) | |
var refpk = new PublicKey("029ba4d2d14a5c24e4b7b6aa953ecf24b599e2f5e944412a9d60e5878f0f6a06cd") | |
var stevenpk = new PublicKey("03e34df7c516e3a122ef72f9db4cbcd2302ac7c9ec5b1f52cd5f77740654958f31") | |
var vinpk = new PublicKey("03ef3b289d0c08ab016153975cc028871982a621f35ab548e348ce275bb2b21eca") | |
// Make Transaction from escrow UTXO | |
let sighash = (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID); | |
console.log('SIGHASH', sighash); | |
// Satoshi's to spend minus 750 for miner fee (just to be safe) | |
var amountToSpend = utxo2.satoshis - 750 | |
var spendTx = new Transaction() | |
.from(utxo2) // then another transaction for utxo2 | |
.to(stevenpk.toAddress(), amountToSpend) | |
let signature = '3043021f5c2bc2402a7e39b350b37f88e43429a07a031d5ef9e7b42a81cb38f6e5e8e502202c2dc70f64c11101bb010636d50a5f6796f087366ae2378617faa6e0ed4323a0' | |
console.log('signature', signature); | |
var refereeSig = Signature.fromString(signature) | |
var winnerPriv = new PrivateKey(process.env.player_padres_privatekey) | |
const WINNING_MESSAGE = 'padreswin'; | |
// Create the output script | |
var outputScriptData = { | |
refereePubKey: refpk, | |
parties: [ | |
{message: 'padreswin', pubKey: stevenpk}, | |
{message: 'marlinswin', pubKey: vinpk} | |
] | |
} | |
let outScript = new OutputScript(outputScriptData) | |
console.log(outScript.toAddress()) | |
spendTx.signEscrow(0, winnerPriv , WINNING_MESSAGE, refereeSig, outScript.toScript(), sighash) | |
console.log(spendTx.toString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment