paypro: extract addresses from server outputs and craft txs in this manner.

This commit is contained in:
Christopher Jeffrey 2014-08-05 17:01:17 -07:00 committed by Manuel Araoz
commit 093fd68c78
2 changed files with 126 additions and 1 deletions

View file

@ -234,6 +234,39 @@ describe('PayPro (in Wallet) model', function() {
}
};
var outs = [];
outputs.forEach(function(output) {
var amount = output.get('amount');
var script = {
offset: output.get('script').offset,
limit: output.get('script').limit,
buffer: output.get('script').buffer
};
var v = new Buffer(8);
v[0] = (amount.high >> 24) & 0xff;
v[1] = (amount.high >> 16) & 0xff;
v[2] = (amount.high >> 8) & 0xff;
v[3] = (amount.high >> 0) & 0xff;
v[4] = (amount.low >> 24) & 0xff;
v[5] = (amount.low >> 16) & 0xff;
v[6] = (amount.low >> 8) & 0xff;
v[7] = (amount.low >> 0) & 0xff;
var s = script.buffer.slice(script.offset, script.limit);
var network = network === 'main' ? 'livenet' : 'testnet';
var addr = bitcore.Address.fromScriptPubKey(new bitcore.Script(s), network);
outs.push({
address: addr[0].toString(),
amountSatStr: bitcore.Bignum.fromBuffer(v, {
endian: 'little',
size: 1
}).toString(10)
});
});
/*
var outs = [];
outputs.forEach(function(output) {
outs.push({
@ -241,11 +274,13 @@ describe('PayPro (in Wallet) model', function() {
amountSatStr: '0'
});
});
*/
var b = new bitcore.TransactionBuilder(opts)
.setUnspent(unspentTest)
.setOutputs(outs);
/*
outputs.forEach(function(output, i) {
var amount = output.get('amount');
var script = {
@ -269,6 +304,7 @@ describe('PayPro (in Wallet) model', function() {
b.tx.outs[i].v = v;
b.tx.outs[i].s = s;
});
*/
var selectedUtxos = b.getSelectedUnspent();
var inputChainPaths = selectedUtxos.map(function(utxo) {
@ -460,6 +496,39 @@ describe('PayPro (in Wallet) model', function() {
}
};
var outs = [];
outputs.forEach(function(output) {
var amount = output.get('amount');
var script = {
offset: output.get('script').offset,
limit: output.get('script').limit,
buffer: output.get('script').buffer
};
var v = new Buffer(8);
v[0] = (amount.high >> 24) & 0xff;
v[1] = (amount.high >> 16) & 0xff;
v[2] = (amount.high >> 8) & 0xff;
v[3] = (amount.high >> 0) & 0xff;
v[4] = (amount.low >> 24) & 0xff;
v[5] = (amount.low >> 16) & 0xff;
v[6] = (amount.low >> 8) & 0xff;
v[7] = (amount.low >> 0) & 0xff;
var s = script.buffer.slice(script.offset, script.limit);
var network = network === 'main' ? 'livenet' : 'testnet';
var addr = bitcore.Address.fromScriptPubKey(new bitcore.Script(s), network);
outs.push({
address: addr[0].toString(),
amountSatStr: bitcore.Bignum.fromBuffer(v, {
endian: 'little',
size: 1
}).toString(10)
});
});
/*
var outs = [];
outputs.forEach(function(output) {
outs.push({
@ -467,11 +536,13 @@ describe('PayPro (in Wallet) model', function() {
amountSatStr: '0'
});
});
*/
var b = new bitcore.TransactionBuilder(opts)
.setUnspent(unspentTest)
.setOutputs(outs);
/*
outputs.forEach(function(output, i) {
var amount = output.get('amount');
var script = {
@ -495,6 +566,7 @@ describe('PayPro (in Wallet) model', function() {
b.tx.outs[i].v = v;
b.tx.outs[i].s = s;
});
*/
var selectedUtxos = b.getSelectedUnspent();
var inputChainPaths = selectedUtxos.map(function(utxo) {