Skip to content

Instantly share code, notes, and snippets.

@curtislacy
Last active August 29, 2015 14:05
Show Gist options
  • Save curtislacy/62d20318a5cad36df2e9 to your computer and use it in GitHub Desktop.
Save curtislacy/62d20318a5cad36df2e9 to your computer and use it in GitHub Desktop.
Parsing a counterparty transaction.
// Send some BTC to cover distribution fees.
var feeAmount = Math.ceil( ( quantity * 0.0003 + 0.0001 ) * satoshisPerBTC )
var feeParams = {
source: sourceAddr.publicAddress,
destination: destPub,
quantity: feeAmount,
asset: 'BTC',
pubkey: pubKey,
allow_unconfirmed_inputs: true,
encoding: "multisig"
};
console.log( 'Sending fees: ' );
console.log( feeParams );
counterparty.create_send(feeParams, function(err, res) {
if(err) {
alertService.add("danger", err.message || err);
return d.reject(err);
}
var unsignedTxHex = res.result;
var raw = new bitcore.buffertools.Buffer(unsignedTxHex, 'hex');
var unsignedTx = new bitcore.Transaction();
unsignedTx.parse(raw);
console.log( unsignedTx );
console.log( 'Unsigned Transaction outputs: ' );
var changeOutputs = [];
for( var i = 0; i<unsignedTx.outs.length; i++ )
{
var sum = 0;
for( var j=0; j<unsignedTx.outs[i].v.length; j++ )
sum += unsignedTx.outs[i].v.readUInt8( j ) << ( 8*j )
if( sum != feeAmount )
{
changeOutputs.push(
{
'index': i,
'satoshis': sum
}
);
}
}
console.log( 'Change outputs: ' );
console.log( changeOutputs );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment