From 8ea43ba508fa72a206bfa0b965bb3df49f2590e8 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Mon, 22 Aug 2022 16:03:25 -0700 Subject: [PATCH] multi-scope: update sendfrom --- rpc/legacyrpc/methods.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/rpc/legacyrpc/methods.go b/rpc/legacyrpc/methods.go index 2a437b9dbe..ad2439d7ec 100644 --- a/rpc/legacyrpc/methods.go +++ b/rpc/legacyrpc/methods.go @@ -1603,7 +1603,9 @@ func isNilOrEmpty(s *string) bool { // address. Leftover inputs not sent to the payment address or a fee for // the miner are sent back to a new address in the wallet. Upon success, // the TxID for the created transaction is returned. -func sendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) { +func sendFrom(icmd interface{}, w *wallet.Wallet, + chainClient *chain.RPCClient) (interface{}, error) { + cmd := icmd.(*btcjson.SendFromCmd) // Transaction comments are not yet supported. Error instead of @@ -1615,9 +1617,7 @@ func sendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) } } - account, err := w.AccountNumber( - waddrmgr.KeyScopeBIP0044, cmd.FromAccount, - ) + account, err := w.AccountNumber(cmd.FromAccount) if err != nil { return nil, err } @@ -1630,6 +1630,7 @@ func sendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) if minConf < 0 { return nil, ErrNeedPositiveMinconf } + // Create map of address and amount pairs. amt, err := btcutil.NewAmount(cmd.Amount) if err != nil { @@ -1639,7 +1640,13 @@ func sendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) cmd.ToAddress: amt, } - return sendPairs(w, pairs, waddrmgr.KeyScopeBIP0044, account, minConf, + // Use specified scope, if provided. + scope, err := lookupKeyScope(cmd.AddressType) + if err != nil { + return nil, err + } + + return sendPairs(w, pairs, scope, account, minConf, txrules.DefaultRelayFeePerKb) }