@@ -2489,6 +2489,180 @@ describe('Bitcoin Service', function() {
24892489 done ( ) ;
24902490 } ) ;
24912491 } ) ;
2492+ it ( 'three confirmed utxos -> one utxo after mempool' , function ( done ) {
2493+ var deltas = [
2494+ {
2495+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2496+ satoshis : - 7679241 ,
2497+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2498+ index : 0 ,
2499+ timestamp : 1461342707725 ,
2500+ prevtxid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2501+ prevout : 0
2502+ } ,
2503+ {
2504+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2505+ satoshis : - 7679241 ,
2506+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2507+ index : 0 ,
2508+ timestamp : 1461342707725 ,
2509+ prevtxid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2510+ prevout : 1
2511+ } ,
2512+ {
2513+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2514+ satoshis : - 7679241 ,
2515+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2516+ index : 1 ,
2517+ timestamp : 1461342707725 ,
2518+ prevtxid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2519+ prevout : 2
2520+ } ,
2521+ {
2522+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2523+ satoshis : 100000 ,
2524+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2525+ index : 1 ,
2526+ script : '76a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac' ,
2527+ timestamp : 1461342833133
2528+ }
2529+ ] ;
2530+ var bitcoind = new BitcoinService ( baseConfig ) ;
2531+ var confirmedUtxos = [
2532+ {
2533+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2534+ txid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2535+ outputIndex : 0 ,
2536+ script : '76a914f399b4b8894f1153b96fce29f05e6e116eb4c21788ac' ,
2537+ satoshis : 7679241 ,
2538+ height : 207111
2539+ } ,
2540+ {
2541+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2542+ txid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2543+ outputIndex : 1 ,
2544+ script : '76a914f399b4b8894f1153b96fce29f05e6e116eb4c21788ac' ,
2545+ satoshis : 7679241 ,
2546+ height : 207111
2547+ } ,
2548+ {
2549+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2550+ txid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2551+ outputIndex : 2 ,
2552+ script : '76a914f399b4b8894f1153b96fce29f05e6e116eb4c21788ac' ,
2553+ satoshis : 7679241 ,
2554+ height : 207111
2555+ }
2556+ ] ;
2557+ bitcoind . nodes . push ( {
2558+ client : {
2559+ getAddressUtxos : sinon . stub ( ) . callsArgWith ( 1 , null , {
2560+ result : confirmedUtxos
2561+ } ) ,
2562+ getAddressMempool : sinon . stub ( ) . callsArgWith ( 1 , null , {
2563+ result : deltas
2564+ } )
2565+ }
2566+ } ) ;
2567+ var options = {
2568+ queryMempool : true
2569+ } ;
2570+ var address = '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ;
2571+ bitcoind . getAddressUnspentOutputs ( address , options , function ( err , utxos ) {
2572+ if ( err ) {
2573+ return done ( err ) ;
2574+ }
2575+ utxos . length . should . equal ( 1 ) ;
2576+ done ( ) ;
2577+ } ) ;
2578+ } ) ;
2579+ it ( 'spending utxos in the mempool' , function ( done ) {
2580+ var deltas = [
2581+ {
2582+ txid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2583+ satoshis : 7679241 ,
2584+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2585+ index : 0 ,
2586+ timestamp : 1461342707724
2587+ } ,
2588+ {
2589+ txid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2590+ satoshis : 7679241 ,
2591+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2592+ index : 1 ,
2593+ timestamp : 1461342707724
2594+ } ,
2595+ {
2596+ txid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2597+ satoshis : 7679241 ,
2598+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2599+ timestamp : 1461342707724 ,
2600+ index : 2 ,
2601+ } ,
2602+ {
2603+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2604+ satoshis : - 7679241 ,
2605+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2606+ index : 0 ,
2607+ timestamp : 1461342707725 ,
2608+ prevtxid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2609+ prevout : 0
2610+ } ,
2611+ {
2612+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2613+ satoshis : - 7679241 ,
2614+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2615+ index : 0 ,
2616+ timestamp : 1461342707725 ,
2617+ prevtxid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2618+ prevout : 1
2619+ } ,
2620+ {
2621+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2622+ satoshis : - 7679241 ,
2623+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2624+ index : 1 ,
2625+ timestamp : 1461342707725 ,
2626+ prevtxid : '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0' ,
2627+ prevout : 2
2628+ } ,
2629+ {
2630+ txid : 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ,
2631+ satoshis : 100000 ,
2632+ address : '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ,
2633+ index : 1 ,
2634+ timestamp : 1461342833133
2635+ }
2636+ ] ;
2637+ var bitcoind = new BitcoinService ( baseConfig ) ;
2638+ var confirmedUtxos = [ ] ;
2639+ bitcoind . nodes . push ( {
2640+ client : {
2641+ getAddressUtxos : sinon . stub ( ) . callsArgWith ( 1 , null , {
2642+ result : confirmedUtxos
2643+ } ) ,
2644+ getAddressMempool : sinon . stub ( ) . callsArgWith ( 1 , null , {
2645+ result : deltas
2646+ } )
2647+ }
2648+ } ) ;
2649+ var options = {
2650+ queryMempool : true
2651+ } ;
2652+ var address = '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo' ;
2653+ bitcoind . getAddressUnspentOutputs ( address , options , function ( err , utxos ) {
2654+ if ( err ) {
2655+ return done ( err ) ;
2656+ }
2657+ utxos . length . should . equal ( 1 ) ;
2658+ utxos [ 0 ] . address . should . equal ( address ) ;
2659+ utxos [ 0 ] . txid . should . equal ( 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce' ) ;
2660+ utxos [ 0 ] . outputIndex . should . equal ( 1 ) ;
2661+ utxos [ 0 ] . script . should . equal ( '76a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac' ) ;
2662+ utxos [ 0 ] . timestamp . should . equal ( 1461342833133 ) ;
2663+ done ( ) ;
2664+ } ) ;
2665+ } ) ;
24922666 it ( 'will update with mempool results spending zero value output (likely never to happen)' , function ( done ) {
24932667 var deltas = [
24942668 {
0 commit comments