Skip to content

Commit d94fcde

Browse files
committed
backend/btc: remove unused sameAccount in getAddressCallback
bitbox02-api-go now automagically determines if the output belongs to the same account as the inputs or not, so we don't need this flag anymore.
1 parent d58dda7 commit d94fcde

File tree

9 files changed

+22
-25
lines changed

9 files changed

+22
-25
lines changed

backend/accounts.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,14 +1063,14 @@ func (backend *Backend) createAndAddAccount(coin coinpkg.Coin, persistedConfig *
10631063

10641064
// This function is passed as a callback to the BTC account constructor. It is called when the
10651065
// keystore needs to determine whether an address belongs to an account on its same keystore.
1066-
getAddressCallback := func(askingAccount *btc.Account, scriptHashHex blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error) {
1066+
getAddressCallback := func(askingAccount *btc.Account, scriptHashHex blockchain.ScriptHashHex) (*addresses.AccountAddress, error) {
10671067
accountsByKeystore, err := backend.AccountsByKeystore()
10681068
if err != nil {
1069-
return nil, false, err
1069+
return nil, err
10701070
}
10711071
rootFingerprint, err := backend.keystore.RootFingerprint()
10721072
if err != nil {
1073-
return nil, false, err
1073+
return nil, err
10741074
}
10751075
for _, account := range accountsByKeystore[hex.EncodeToString(rootFingerprint)] {
10761076
// This only makes sense for BTC accounts.
@@ -1083,10 +1083,10 @@ func (backend *Backend) createAndAddAccount(coin coinpkg.Coin, persistedConfig *
10831083
continue
10841084
}
10851085
if address := btcAccount.GetAddress(scriptHashHex); address != nil {
1086-
return address, askingAccount == btcAccount, nil
1086+
return address, nil
10871087
}
10881088
}
1089-
return nil, false, nil
1089+
return nil, nil
10901090
}
10911091

10921092
switch specificCoin := coin.(type) {

backend/accounts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ func TestKeystoresBalance(t *testing.T) {
14911491
b := newBackend(t, testnetDisabled, regtestDisabled)
14921492
defer b.Close()
14931493

1494-
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error), log *logrus.Entry) accounts.Interface {
1494+
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error), log *logrus.Entry) accounts.Interface {
14951495
accountMock := MockBtcAccount(t, config, coin, gapLimits, log)
14961496
accountMock.BalanceFunc = func() (*accounts.Balance, error) {
14971497
return accounts.NewBalance(coinpkg.NewAmountFromInt64(1e8), coinpkg.NewAmountFromInt64(0)), nil
@@ -1561,7 +1561,7 @@ func TestCoinsTotalBalance(t *testing.T) {
15611561
b := newBackend(t, testnetDisabled, regtestDisabled)
15621562
defer b.Close()
15631563

1564-
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error), log *logrus.Entry) accounts.Interface {
1564+
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error), log *logrus.Entry) accounts.Interface {
15651565
accountMock := MockBtcAccount(t, config, coin, gapLimits, log)
15661566
accountMock.BalanceFunc = func() (*accounts.Balance, error) {
15671567
return accounts.NewBalance(coinpkg.NewAmountFromInt64(1e8), coinpkg.NewAmountFromInt64(0)), nil
@@ -1622,7 +1622,7 @@ func TestAccountsFiatAndCoinBalance(t *testing.T) {
16221622
b := newBackend(t, testnetDisabled, regtestDisabled)
16231623
defer b.Close()
16241624

1625-
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error), log *logrus.Entry) accounts.Interface {
1625+
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error), log *logrus.Entry) accounts.Interface {
16261626
accountMock := MockBtcAccount(t, config, coin, gapLimits, log)
16271627
accountMock.BalanceFunc = func() (*accounts.Balance, error) {
16281628
return accounts.NewBalance(coinpkg.NewAmountFromInt64(1e8), coinpkg.NewAmountFromInt64(0)), nil

backend/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ type Backend struct {
229229

230230
// makeBtcAccount creates a BTC account. In production this is `btc.NewAccount`, but can be
231231
// overridden in unit tests for mocking.
232-
makeBtcAccount func(*accounts.AccountConfig, *btc.Coin, *types.GapLimits, func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error), *logrus.Entry) accounts.Interface
232+
makeBtcAccount func(*accounts.AccountConfig, *btc.Coin, *types.GapLimits, func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error), *logrus.Entry) accounts.Interface
233233
// makeEthAccount creates an ETH account. In production this is `eth.NewAccount`, but can be
234234
// overridden in unit tests for mocking.
235235
makeEthAccount func(*accounts.AccountConfig, *eth.Coin, *http.Client, *logrus.Entry) accounts.Interface
@@ -298,7 +298,7 @@ func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backe
298298
coins: map[coinpkg.Code]coinpkg.Coin{},
299299
accounts: []accounts.Interface{},
300300
aopp: AOPP{State: aoppStateInactive},
301-
makeBtcAccount: func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error), log *logrus.Entry) accounts.Interface {
301+
makeBtcAccount: func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error), log *logrus.Entry) accounts.Interface {
302302
return btc.NewAccount(config, coin, gapLimits, getAddress, log, hclient)
303303
},
304304
makeEthAccount: func(config *accounts.AccountConfig, coin *eth.Coin, httpClient *http.Client, log *logrus.Entry) accounts.Interface {

backend/backend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func newBackend(t *testing.T, testing, regtest bool) *Backend {
281281
}
282282
b.ratesUpdater.SetCoingeckoURL("unused") // avoid hitting real API
283283

284-
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error), log *logrus.Entry) accounts.Interface {
284+
b.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error), log *logrus.Entry) accounts.Interface {
285285
return MockBtcAccount(t, config, coin, gapLimits, log)
286286
}
287287
b.makeEthAccount = func(config *accounts.AccountConfig, coin *eth.Coin, httpClient *http.Client, log *logrus.Entry) accounts.Interface {

backend/coins/btc/account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ type Account struct {
122122
httpClient *http.Client
123123

124124
// getAddressFromSameKeystore is a function that retrieves an address from any account on the same keystore as this one.
125-
getAddressFromSameKeystore func(*Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error)
125+
getAddressFromSameKeystore func(*Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error)
126126
}
127127

128128
// NewAccount creates a new account.
@@ -133,7 +133,7 @@ func NewAccount(
133133
config *accounts.AccountConfig,
134134
coin *Coin,
135135
forceGapLimits *types.GapLimits,
136-
getAddressFromSameKeystore func(*Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error),
136+
getAddressFromSameKeystore func(*Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error),
137137
log *logrus.Entry,
138138
httpClient *http.Client,
139139
) *Account {

backend/coins/btc/sign.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ type ProposedTransaction struct {
4242
FormatUnit coin.BtcUnit
4343
// GetKeystoreAddress returns the address from the same keystore given the script hash,
4444
// or nil if not found.
45-
// It also returns a boolean indicating whether the address belongs to the account
46-
// that is asking for the address or not.
47-
GetKeystoreAddress func(*Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error)
45+
GetKeystoreAddress func(*Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error)
4846
SendingAccount *Account
4947
}
5048

@@ -111,13 +109,12 @@ func (p *ProposedTransaction) Update() error {
111109
for index, txOut := range txProposal.Psbt.UnsignedTx.TxOut {
112110
// outputAddress is the recipient address if it belongs to the same keystore. It is nil if
113111
// the address is external.
114-
outputAddress, sameAccount, err := p.GetKeystoreAddress(p.SendingAccount, blockchain.NewScriptHashHex(txOut.PkScript))
112+
outputAddress, err := p.GetKeystoreAddress(p.SendingAccount, blockchain.NewScriptHashHex(txOut.PkScript))
115113
if err != nil {
116114
return errp.Newf("failed to get address: %v", err)
117115
}
118116

119-
_ = sameAccount
120-
// Add key info to change output
117+
// Add key info to output belonging to our keystore.
121118
if outputAddress != nil {
122119
scriptType := outputAddress.AccountConfiguration.ScriptType()
123120
switch scriptType {

backend/devices/bitbox02/keystore_simulator_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,18 @@ func makeTx(t *testing.T, device *Device, recipient *maketx.OutputInfo) *btc.Pro
476476
GetPrevTx: func(chainhash.Hash) (*wire.MsgTx, error) {
477477
return prevTx, nil
478478
},
479-
GetKeystoreAddress: func(account *btc.Account, scriptHashHex blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error) {
479+
GetKeystoreAddress: func(account *btc.Account, scriptHashHex blockchain.ScriptHashHex) (*addresses.AccountAddress, error) {
480480
for _, address := range addrs {
481481
if address.PubkeyScriptHashHex() == scriptHashHex {
482-
return address, true, nil
482+
return address, nil
483483
}
484484
}
485485
for _, address := range addrsInDifferentAccount {
486486
if address.PubkeyScriptHashHex() == scriptHashHex {
487-
return address, false, nil
487+
return address, nil
488488
}
489489
}
490-
return nil, false, nil
490+
return nil, nil
491491
},
492492
Signatures: make([]*types.Signature, len(txProposal.Psbt.UnsignedTx.TxIn)),
493493
FormatUnit: coinpkg.BtcUnitDefault,

backend/keystore/software/software.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (keystore *Keystore) signBTCTransaction(btcProposedTx *btc.ProposedTransact
212212
keystore.log.Error("There needs to be exactly one output being spent per input.")
213213
return errp.New("There needs to be exactly one output being spent per input.")
214214
}
215-
address, _, err := btcProposedTx.GetKeystoreAddress(btcProposedTx.SendingAccount, spentOutput.Address.PubkeyScriptHashHex())
215+
address, err := btcProposedTx.GetKeystoreAddress(btcProposedTx.SendingAccount, spentOutput.Address.PubkeyScriptHashHex())
216216
if err != nil {
217217
return err
218218
}

backend/notes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (s *notesTestSuite) SetupTest() {
8181
}
8282
}
8383

84-
s.backend.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, bool, error), log *logrus.Entry) accounts.Interface {
84+
s.backend.makeBtcAccount = func(config *accounts.AccountConfig, coin *btc.Coin, gapLimits *types.GapLimits, getAddress func(*btc.Account, blockchain.ScriptHashHex) (*addresses.AccountAddress, error), log *logrus.Entry) accounts.Interface {
8585
accountMock := MockBtcAccount(s.T(), config, coin, gapLimits, log)
8686
accountMock.NotesFunc = notesFunc(config.Config.Code)
8787
accountMock.TransactionsFunc = transactionsFunc(config.Config.Code)

0 commit comments

Comments
 (0)