diff --git a/api/test/data/addresses.js b/api/test/data/addresses.js index bed32ae6..9a6c1a09 100644 --- a/api/test/data/addresses.js +++ b/api/test/data/addresses.js @@ -1,6 +1,67 @@ 'use strict'; var mockAddresses = { + '13fas9TWPMRBakZ822mvddS6PM92udNB2g': { + summary: { + address: '13fas9TWPMRBakZ822mvddS6PM92udNB2g', + transactions: [ + '4469092947a437f9b4276e0a7e3c899a2b74b2fe325e49202c3005911adaab85', + 'afa55c2ce0e1038d87921d4de7b13a456edfa5ca6f44cddaf4cda9f1db441481' + ], + confirmed: { + balance: 0, + sent: 675000000, + received: 675000000 + }, + unconfirmed: { + balance: 0, + sent: 675000000, + received: 675000000 + } + }, + utxos: [] + }, + '17afxUJouat3fkaaQ9tZrDThxdkXGL4WrM': { + summary: { + address: '17afxUJouat3fkaaQ9tZrDThxdkXGL4WrM', + transactions: [ + '2ccc3f59d28c709770a8bc478b112e10feda4bf55197c2e48deaa0eb6bca0311', + '92f55c2c0b8317eafad83c73487fbeceb8279d0eb57e398763298e6cc983b356' + ], + confirmed: { + balance: 0, + sent: 100000000000, + received: 100000000000 + }, + unconfirmed: { + balance: 0, + sent: 100000000000, + received: 100000000000 + } + }, + utxos: [] + }, + '17DC6Fxidja2DN7oHTVgfx3uQ4KGArYEwg': { + summary: { + 'address': '17DC6Fxidja2DN7oHTVgfx3uQ4KGArYEwg', + 'transactions': [ + '33d1ad0d24e2cb466054e47060c8ae527af7a3c46445335bebf9d24a6f5b1e9e', + '6884733345b952b244a44cf770be62afbcf41549d8a89d2a4bea9f479e09dd47', + '2847ae66175042438532c2eccc5b39935fd1216453e62e2c3cb9c8e5020cc771' + ], + 'confirmed': { + 'balance': 0, + 'sent': 65000000000, + 'received': 65000000000 + }, + 'unconfirmed': { + 'balance': 0, + 'sent': 65000000000, + 'received': 65000000000 + } + }, + utxos: [] + }, '1CT9huFgxMFveRvzZ7zPPJNoaMm2Fo64VH': { summary: { address: '1CT9huFgxMFveRvzZ7zPPJNoaMm2Fo64VH', diff --git a/api/test/v1/addresses.js b/api/test/v1/addresses.js index 6eaf5376..51438776 100644 --- a/api/test/v1/addresses.js +++ b/api/test/v1/addresses.js @@ -51,7 +51,7 @@ describe.only('BitcoreHTTP v1 addresses routes', function() { nodeMock = new EventEmitter(); nodeMock.addressService = {}; nodeMock.addressService.getSummary = function(address) { - return Promise.resolve(mockAddresses[address.toString()]); + return Promise.resolve(mockAddresses[address.toString()].summary); }; nodeMock.listTransactions = function(opts) { return Promise.resolve(txs_for_addr(opts.address)); @@ -77,7 +77,7 @@ describe.only('BitcoreHTTP v1 addresses routes', function() { it('works with valid address ' + addr, function(cb) { agent.get('/v1/addresses/' + addr) .expect(200) - .expect(JSON.stringify(info), cb); + .expect(JSON.stringify(info.summary), cb); }); }); }); diff --git a/api/test/v1/node.js b/api/test/v1/node.js index cf0e59f8..63d12a90 100644 --- a/api/test/v1/node.js +++ b/api/test/v1/node.js @@ -18,7 +18,7 @@ describe('BitcoreHTTP v1 node routes', function() { peerCount: 8, version: 'test', network: 'regtest', - height: 1234, + height: 60000, }; nodeMock.getStatus = function() { return Promise.resolve(nodeMock.status); diff --git a/lib/services/transaction.js b/lib/services/transaction.js index 01cf5730..7f581db4 100644 --- a/lib/services/transaction.js +++ b/lib/services/transaction.js @@ -120,32 +120,28 @@ TransactionService.prototype._confirmOutput = function(ops, block, transaction) key: Index.getOutput(txid, index), value: output.toJSON() }); - var address; - if (output.script.isPublicKeyHashOut() || output.script.isScriptHashOut()) { - address = output.script.toAddress(); - } - if (address) { - var out4addr = output.toObject(); - out4addr.heightConfirmed = block.height; - ops.push({ - type: 'put', - key: Index.getOutputsForAddress(address, txid, index), - value: JSON.stringify(out4addr) - }); + var script = output.script; + if (!script.isPublicKeyHashOut() && !script.isScriptHashOut()) { + return; } + var address = output.script.toAddress(); + //console.log('o', address.type, address.toString()); + var obj = output.toObject(); + obj.heightConfirmed = block.height; + ops.push({ + type: 'put', + key: Index.getOutputsForAddress(address, txid, index), + value: JSON.stringify(obj) + }); }; }; TransactionService.prototype._confirmInput = function(ops, block, transaction) { - var self = this; var txid = transaction.id; return function(input, index) { if (input.isNull()) { return Promise.resolve(); } - if (input.script.isPublicKeyHashIn()) { - console.log(input.toObject()); - } ops.push({ type: 'put', key: Index.getOutput(txid, index), @@ -155,24 +151,22 @@ TransactionService.prototype._confirmInput = function(ops, block, transaction) { }); var script = input.script; if (!(script.isPublicKeyHashIn() || script.isScriptHashIn())) { - return; + return Promise.resolve(); } return Promise.try(function() { var address = input.script.toAddress(); - console.log('input address!', address.toString()); - if (address) { - ops.push({ - type: 'put', - key: Index.getSpentOutputsForAddress(address, txid, index), - value: JSON.stringify({ - heightSpent: block.height, - spentTx: txid, - spentTxInputIndex: index, - spendInput: input.toObject() - }) - }); - } + //console.log('i', address.type, address.toString()); + ops.push({ + type: 'put', + key: Index.getSpentOutputsForAddress(address, txid, index), + value: JSON.stringify({ + heightSpent: block.height, + spentTx: txid, + spentTxInputIndex: index, + spendInput: input.toObject() + }) + }); }); }; };