Skip to content

Commit

Permalink
main: add listbdkutxos support to rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
kcalvinalvin committed Feb 1, 2024
1 parent 23ec5ad commit 779ca92
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
"invalidateblock": handleInvalidateBlock,
"help": handleHelp,
"listbdktransactions": handleListBDKTransactions,
"listbdkutxos": handleListBDKUTXOs,
"node": handleNode,
"peekaddress": handlePeekAddress,
"ping": handlePing,
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)},
Expand Down

0 comments on commit 779ca92

Please sign in to comment.