From 779ca92a7db010899c5e9e30e182f850246beefc Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Thu, 1 Feb 2024 15:06:19 +0900 Subject: [PATCH] main: add listbdkutxos support to rpc --- rpcserver.go | 21 +++++++++++++++++++++ rpcserverhelp.go | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index 09a2f144..343b865f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -179,6 +179,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{ "invalidateblock": handleInvalidateBlock, "help": handleHelp, "listbdktransactions": handleListBDKTransactions, + "listbdkutxos": handleListBDKUTXOs, "node": handleNode, "peekaddress": handlePeekAddress, "ping": handlePing, @@ -3118,6 +3119,26 @@ func handleListBDKTransactions(s *rpcServer, cmd interface{}, closeChan <-chan s return res, nil } +// handleListBDKUTXOs handles handlelistbdkutxos commands. +func handleListBDKUTXOs(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { + utxos := s.cfg.BDKWallet.Wallet.UTXOs() + + res := make([]btcjson.ListBDKUTXOsResult, len(utxos)) + for i := range res { + res[i] = btcjson.ListBDKUTXOsResult{ + Txid: utxos[i].Txid.String(), + Vout: utxos[i].Vout, + Amount: int64(utxos[i].Amount), + ScriptPubKey: hex.EncodeToString(utxos[i].ScriptPubKey), + IsChange: utxos[i].IsChange, + DerivationIndex: utxos[i].DerivationIndex, + Confirmations: utxos[i].Confirmations, + } + } + + return res, nil +} + // handlePeekAddress implements the peekaddress command. func handlePeekAddress(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { c := cmd.(*btcjson.PeekAddressCmd) diff --git a/rpcserverhelp.go b/rpcserverhelp.go index 80d46cf6..8333e6f7 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -644,6 +644,18 @@ var helpDescsEnUS = map[string]string{ "listbdktransactionsresult-received": "The sum of satoshis that was received in this tx.", "listbdktransactionsresult-confirmations": "The amount of blockchain confirmations for this tx.", + // ListBDKUTXOsCmd help. + "listbdkutxos--synopsis": "Returns a list of all the relevant utxos the bdk wallet is holding onto", + + // ListBDKUTXOsResult help. + "listbdkutxosresult-txid": "The txid of the relevant utxo.", + "listbdkutxosresult-vout": "The output index of the relevant utxo.", + "listbdkutxosresult-amount": "The amount in satoshis this utxo is worth.", + "listbdkutxosresult-scriptpubkey": "The script pubkey of the utxo.", + "listbdkutxosresult-ischange": "Whether or not this utxo is a change output.", + "listbdkutxosresult-derivationindex": "The derivation index of the wallet this utxo is located at.", + "listbdkutxosresult-confirmations": "The total amount of blockchain confirmations this utxo has.", + // PeekAddressCmd help. "peekaddress--synopsis": "Returns an address of the desired derivation index", "peekaddress-index": "The desired derivation index you want to fetch the address at", @@ -917,6 +929,7 @@ var rpcResultTypes = map[string][]interface{}{ "help": {(*string)(nil), (*string)(nil)}, "invalidateblock": nil, "listbdktransactions": {(*[]btcjson.ListBDKTransactionsResult)(nil)}, + "listbdkutxos": {(*[]btcjson.ListBDKUTXOsResult)(nil)}, "peekaddress": {(*btcjson.BDKAddressResult)(nil)}, "ping": nil, "proveutxochaintipinclusion": {(*btcjson.ProveUtxoChainTipInclusionVerboseResult)(nil)},