@@ -539,7 +539,8 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
539
539
" [\n "
540
540
" \" address\" (string) The base58check encoded address\n "
541
541
" ,...\n "
542
- " ]\n "
542
+ " ],\n "
543
+ " \" chainInfo\" (boolean) Include chain info with results\n "
543
544
" }\n "
544
545
" \n Result\n "
545
546
" [\n "
@@ -555,7 +556,15 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
555
556
" \n Examples:\n "
556
557
+ HelpExampleCli (" getaddressutxos" , " '{\" addresses\" : [\" 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\" ]}'" )
557
558
+ HelpExampleRpc (" getaddressutxos" , " {\" addresses\" : [\" 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\" ]}" )
558
- );
559
+ );
560
+
561
+ bool includeChainInfo = false ;
562
+ if (params[0 ].isObject ()) {
563
+ UniValue chainInfo = find_value (params[0 ].get_obj (), " chainInfo" );
564
+ if (chainInfo.isBool ()) {
565
+ includeChainInfo = chainInfo.get_bool ();
566
+ }
567
+ }
559
568
560
569
std::vector<std::pair<uint160, int > > addresses;
561
570
@@ -573,7 +582,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
573
582
574
583
std::sort (unspentOutputs.begin (), unspentOutputs.end (), heightSort);
575
584
576
- UniValue result (UniValue::VARR);
585
+ UniValue utxos (UniValue::VARR);
577
586
578
587
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin (); it!=unspentOutputs.end (); it++) {
579
588
UniValue output (UniValue::VOBJ);
@@ -588,10 +597,20 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp)
588
597
output.push_back (Pair (" script" , HexStr (it->second .script .begin (), it->second .script .end ())));
589
598
output.push_back (Pair (" satoshis" , it->second .satoshis ));
590
599
output.push_back (Pair (" height" , it->second .blockHeight ));
591
- result .push_back (output);
600
+ utxos .push_back (output);
592
601
}
593
602
594
- return result;
603
+ if (includeChainInfo) {
604
+ UniValue result (UniValue::VOBJ);
605
+ result.push_back (Pair (" utxos" , utxos));
606
+
607
+ LOCK (cs_main);
608
+ result.push_back (Pair (" hash" , chainActive.Tip ()->GetBlockHash ().GetHex ()));
609
+ result.push_back (Pair (" height" , (int )chainActive.Height ()));
610
+ return result;
611
+ } else {
612
+ return utxos;
613
+ }
595
614
}
596
615
597
616
UniValue getaddressdeltas (const UniValue& params, bool fHelp )
@@ -609,6 +628,7 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
609
628
" ]\n "
610
629
" \" start\" (number) The start block height\n "
611
630
" \" end\" (number) The end block height\n "
631
+ " \" chainInfo\" (boolean) Include chain info in results, only applies if start and end specified\n "
612
632
" }\n "
613
633
" \n Result:\n "
614
634
" [\n "
@@ -629,12 +649,21 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
629
649
UniValue startValue = find_value (params[0 ].get_obj (), " start" );
630
650
UniValue endValue = find_value (params[0 ].get_obj (), " end" );
631
651
652
+ UniValue chainInfo = find_value (params[0 ].get_obj (), " chainInfo" );
653
+ bool includeChainInfo = false ;
654
+ if (chainInfo.isBool ()) {
655
+ includeChainInfo = chainInfo.get_bool ();
656
+ }
657
+
632
658
int start = 0 ;
633
659
int end = 0 ;
634
660
635
661
if (startValue.isNum () && endValue.isNum ()) {
636
662
start = startValue.get_int ();
637
663
end = endValue.get_int ();
664
+ if (start <= 0 || end <= 0 ) {
665
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Start and end is expected to be greater than zero" );
666
+ }
638
667
if (end < start) {
639
668
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " End value is expected to be greater than start" );
640
669
}
@@ -660,7 +689,7 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
660
689
}
661
690
}
662
691
663
- UniValue result (UniValue::VARR);
692
+ UniValue deltas (UniValue::VARR);
664
693
665
694
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin (); it!=addressIndex.end (); it++) {
666
695
std::string address;
@@ -675,10 +704,38 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
675
704
delta.push_back (Pair (" blockindex" , (int )it->first .txindex ));
676
705
delta.push_back (Pair (" height" , it->first .blockHeight ));
677
706
delta.push_back (Pair (" address" , address));
678
- result .push_back (delta);
707
+ deltas .push_back (delta);
679
708
}
680
709
681
- return result;
710
+ UniValue result (UniValue::VOBJ);
711
+
712
+ if (includeChainInfo && start > 0 && end > 0 ) {
713
+ LOCK (cs_main);
714
+
715
+ if (start > chainActive.Height () || end > chainActive.Height ()) {
716
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Start or end is outside chain range" );
717
+ }
718
+
719
+ CBlockIndex* startIndex = chainActive[start];
720
+ CBlockIndex* endIndex = chainActive[end];
721
+
722
+ UniValue startInfo (UniValue::VOBJ);
723
+ UniValue endInfo (UniValue::VOBJ);
724
+
725
+ startInfo.push_back (Pair (" hash" , startIndex->GetBlockHash ().GetHex ()));
726
+ startInfo.push_back (Pair (" height" , start));
727
+
728
+ endInfo.push_back (Pair (" hash" , endIndex->GetBlockHash ().GetHex ()));
729
+ endInfo.push_back (Pair (" height" , end));
730
+
731
+ result.push_back (Pair (" deltas" , deltas));
732
+ result.push_back (Pair (" start" , startInfo));
733
+ result.push_back (Pair (" end" , endInfo));
734
+
735
+ return result;
736
+ } else {
737
+ return deltas;
738
+ }
682
739
}
683
740
684
741
UniValue getaddressbalance (const UniValue& params, bool fHelp )
0 commit comments