Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add btc wallet name to connection config #25

Merged
merged 7 commits into from
Aug 19, 2024
18 changes: 11 additions & 7 deletions itest/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func keyToAddr(key *btcec.PrivateKey, net *chaincfg.Params) (btcutil.Address, er
return pubKeyAddr.AddressPubKeyHash(), nil
}

func defaultStakerConfig(t *testing.T, passphrase string) (*stakercfg.Config, *rpcclient.Client) {
func defaultStakerConfig(t *testing.T, walletName, passphrase string) (*stakercfg.Config, *rpcclient.Client) {
defaultConfig := stakercfg.DefaultConfig()

// both wallet and node are bicoind
Expand All @@ -98,6 +98,7 @@ func defaultStakerConfig(t *testing.T, passphrase string) (*stakercfg.Config, *r
defaultConfig.WalletRpcConfig.Pass = bitcoindPass
defaultConfig.WalletRpcConfig.DisableTls = true
defaultConfig.WalletConfig.WalletPass = passphrase
defaultConfig.WalletConfig.WalletName = walletName

// node configuration
defaultConfig.BtcNodeBackendConfig.Bitcoind.RPCHost = bitcoindHost
Expand Down Expand Up @@ -223,7 +224,8 @@ func StartManager(
h := NewBitcoindHandler(t)
h.Start()
passphrase := "pass"
_ = h.CreateWallet("test-wallet", passphrase)
walletName := "test-wallet"
_ = h.CreateWallet(walletName, passphrase)
// only outputs which are 100 deep are mature
br := h.GenerateBlocks(int(numMatureOutputsInWallet) + 100)

Expand Down Expand Up @@ -258,7 +260,7 @@ func StartManager(
err = bh.Start()
require.NoError(t, err)

cfg, c := defaultStakerConfig(t, passphrase)
cfg, c := defaultStakerConfig(t, walletName, passphrase)

logger := logrus.New()
logger.SetLevel(logrus.DebugLevel)
Expand Down Expand Up @@ -1507,7 +1509,8 @@ func TestBitcoindWalletRpcApi(t *testing.T) {
h.Start()
passphrase := "pass"
numMatureOutputs := 1
_ = h.CreateWallet("test-wallet", passphrase)
walletName := "test-wallet"
_ = h.CreateWallet(walletName, passphrase)
// only outputs which are 100 deep are mature
_ = h.GenerateBlocks(numMatureOutputs + 100)

Expand All @@ -1518,6 +1521,7 @@ func TestBitcoindWalletRpcApi(t *testing.T) {
scfg.WalletRpcConfig.Pass = "pass"
scfg.ActiveNetParams.Name = "regtest"
scfg.WalletConfig.WalletPass = passphrase
scfg.WalletConfig.WalletName = walletName
scfg.BtcNodeBackendConfig.ActiveWalletBackend = types.BitcoindWalletBackend
scfg.ActiveNetParams = chaincfg.RegressionNetParams

Expand Down Expand Up @@ -1577,9 +1581,9 @@ func TestBitcoindWalletBip322Signing(t *testing.T) {
h := NewBitcoindHandler(t)
h.Start()
passphrase := "pass"

_ = h.CreateWallet("test-wallet", passphrase)
cfg, c := defaultStakerConfig(t, passphrase)
walletName := "test-wallet"
_ = h.CreateWallet(walletName, passphrase)
cfg, c := defaultStakerConfig(t, walletName, passphrase)

segwitAddress, err := c.GetNewAddress("")
require.NoError(t, err)
Expand Down
11 changes: 10 additions & 1 deletion walletcontroller/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewRpcWalletController(scfg *stakercfg.Config) (*RpcWalletController, error
scfg.WalletRpcConfig.User,
scfg.WalletRpcConfig.Pass,
scfg.ActiveNetParams.Name,
scfg.WalletConfig.WalletName,
scfg.WalletConfig.WalletPass,
scfg.BtcNodeBackendConfig.ActiveWalletBackend,
&scfg.ActiveNetParams,
Expand All @@ -58,6 +59,7 @@ func NewRpcWalletControllerFromArgs(
user string,
pass string,
network string,
walletName string,
walletPassphrase string,
nodeBackend types.SupportedWalletBackend,
params *chaincfg.Params,
Expand All @@ -66,7 +68,7 @@ func NewRpcWalletControllerFromArgs(
) (*RpcWalletController, error) {

connCfg := &rpcclient.ConnConfig{
Host: host,
Host: rpcHostURL(host, walletName),
User: user,
Pass: pass,
DisableTLS: disableTls,
Expand Down Expand Up @@ -98,6 +100,13 @@ func NewRpcWalletControllerFromArgs(
}, nil
}

func rpcHostURL(host, walletName string) string {
if len(walletName) > 0 {
return host + "/wallet/" + walletName
}
return host
}

func (w *RpcWalletController) UnlockWallet(timoutSec int64) error {
return w.WalletPassphrase(w.walletPassphrase, timoutSec)
}
Expand Down
Loading