Skip to content

Commit

Permalink
Merge pull request #132 from kcalvinalvin/2024-02-04-bdkwallet-changes
Browse files Browse the repository at this point in the history
main: bdk wallet changes
  • Loading branch information
kcalvinalvin authored Feb 4, 2024
2 parents 9a6d381 + f48dcaf commit 426098b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
64 changes: 64 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ func handleAddNode(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (in

// handleBalance handles the balance command.
func handleBalance(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

balance := s.cfg.BDKWallet.Wallet.Balance()
return btcjson.BalanceResult{
Immature: int64(balance.Immature),
Expand Down Expand Up @@ -997,6 +1005,14 @@ func handleEstimateFee(s *rpcServer, cmd interface{}, closeChan <-chan struct{})

// handleFreshAddress implements the freshaddress command.
func handleFreshAddress(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

index, address, err := s.cfg.BDKWallet.Wallet.FreshAddress()
if err != nil {
return nil, &btcjson.RPCError{
Expand Down Expand Up @@ -2542,6 +2558,14 @@ func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{

// handleGetMnemonicWords implements the getmnemonicwords command.
func handleGetMnemonicWords(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

words := s.cfg.BDKWallet.Wallet.MnemonicWords()
return words, nil
}
Expand Down Expand Up @@ -3088,6 +3112,14 @@ func handleHelp(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (inter

// handleListBDKTransactions handles listbdktransactions commands.
func handleListBDKTransactions(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

txs, err := s.cfg.BDKWallet.Wallet.Transactions()
if err != nil {
return nil, &btcjson.RPCError{
Expand Down Expand Up @@ -3121,6 +3153,14 @@ func handleListBDKTransactions(s *rpcServer, cmd interface{}, closeChan <-chan s

// handleListBDKUTXOs handles handlelistbdkutxos commands.
func handleListBDKUTXOs(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

utxos := s.cfg.BDKWallet.Wallet.UTXOs()

res := make([]btcjson.ListBDKUTXOsResult, len(utxos))
Expand All @@ -3141,6 +3181,14 @@ func handleListBDKUTXOs(s *rpcServer, cmd interface{}, closeChan <-chan struct{}

// handlePeekAddress implements the peekaddress command.
func handlePeekAddress(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

c := cmd.(*btcjson.PeekAddressCmd)

index, address, err := s.cfg.BDKWallet.Wallet.PeekAddress(c.Index)
Expand Down Expand Up @@ -3831,6 +3879,14 @@ func sendTxToMempoolSpace(rawTx string, chainParams *chaincfg.Params) (string, e

// handleRebroadcastUnconfirmedBDKTxs implements the rebroadcastunconfirmedbdktxs command.
func handleRebroadcastUnconfirmedBDKTxs(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

allTxs, err := s.cfg.BDKWallet.Wallet.Transactions()
if err != nil {
return nil, &btcjson.RPCError{
Expand Down Expand Up @@ -4426,6 +4482,14 @@ func handleSubmitBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{})

// handleUnusedAddress implements the unusedaddress command.
func handleUnusedAddress(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
// Before doing anything, check that the bdk wallet is active.
if s.cfg.BDKWallet == nil {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCMisc,
Message: "BDK wallet must be enabled. (--bdkwallet)",
}
}

index, address, err := s.cfg.BDKWallet.Wallet.UnusedAddress()
if err != nil {
return nil, &btcjson.RPCError{
Expand Down
9 changes: 8 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3556,7 +3556,14 @@ func newServer(listenAddrs, agentBlacklist, agentWhitelist []string,
DataDir: cfg.DataDir,
})
if err != nil {
return nil, err
if err == bdkwallet.ErrNoBDK {
s.bdkWallet = nil
cfg.NoBdkWallet = true
btcdLog.Infof("Unable to enable bkdwallet as utreexod wasn't built with bdkwallet. " +
"Starting node without bdkwallet.")
} else {
return nil, err
}
}
}

Expand Down

0 comments on commit 426098b

Please sign in to comment.