Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit f5cda55

Browse files
committed
bus: return error on startup if wallet is disabled
Typically the case when disablewallet=1 is specified in bitcoin.conf, or if bitcoind is compiled without wallet features. This is useful with Raspiblitz, where wallet is disabled by default. Closes #11.
1 parent 3b181fb commit f5cda55

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

bus/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ var (
77
// was not successful. Use this error during sanity checks.
88
ErrBitcoindUnreachable = errors.New("bitcoind unreachable")
99

10+
// ErrWalletDisabled indicates that wallet features have been disabled on
11+
// the connected Bitcoin node. SatStack relies on wallet RPCs to function.
12+
ErrWalletDisabled = errors.New("bitcoind wallet is disabled")
13+
1014
// ErrUnsupportedBitcoindVersion indicates that the connected bitcoind node
1115
// has a version that is not supported by SatStack.
1216
ErrUnsupportedBitcoindVersion = errors.New("unsupported bitcoind version")

bus/infrastructure.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import (
66
"sync"
77
"time"
88

9-
"github.com/btcsuite/btcutil"
10-
9+
"github.com/btcsuite/btcd/btcjson"
1110
"github.com/btcsuite/btcd/chaincfg/chainhash"
12-
11+
"github.com/btcsuite/btcd/rpcclient"
12+
"github.com/btcsuite/btcutil"
1313
"github.com/ledgerhq/satstack/config"
1414
"github.com/ledgerhq/satstack/utils"
15-
1615
"github.com/patrickmn/go-cache"
17-
18-
"github.com/btcsuite/btcd/rpcclient"
1916
log "github.com/sirupsen/logrus"
2017
)
2118

@@ -93,6 +90,10 @@ func New(host string, user string, pass string, noTLS bool) (*Bus, error) {
9390
client := <-pool
9491
defer func() { pool <- client }()
9592

93+
if walletDisabled(client) {
94+
return nil, ErrWalletDisabled
95+
}
96+
9697
info, err := client.GetBlockChainInfo()
9798
if err != nil {
9899
return nil, fmt.Errorf("%s: %w", ErrBitcoindUnreachable, err)
@@ -181,6 +182,20 @@ func CurrencyFromChain(chain string) (Currency, error) {
181182
}
182183
}
183184

185+
// walletDisabled detects if wallet features have been disabled in the Bitcoin
186+
// node, and returns a boolean value accordingly.
187+
//
188+
// This maps to the option disablewallet=1 in bitcoin.conf.
189+
func walletDisabled(client *rpcclient.Client) bool {
190+
if _, err := client.GetWalletInfo(); err != nil {
191+
if err.(*btcjson.RPCError).Code == btcjson.ErrRPCMethodNotFound.Code {
192+
return true
193+
}
194+
}
195+
196+
return false
197+
}
198+
184199
// txIndexEnabled can be used to detect if the bitcoind server being connected
185200
// has a transaction index (enabled by option txindex=1).
186201
//

0 commit comments

Comments
 (0)