Skip to content

Commit

Permalink
dex/networks/btc: ExtractScriptAddrs never errors
Browse files Browse the repository at this point in the history
The updated txscript.ExtractPkScriptAddrs always returns a nil error.
Keep the error return on ExtractScriptAddrs for now since it was not
removed from ExtractPkScriptAddrs and it could have meaning again.
  • Loading branch information
chappjc committed Apr 6, 2022
1 parent c62e0bd commit 0db0fdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions client/asset/btc/btc.go
Expand Up @@ -3355,6 +3355,9 @@ func convertUnspent(confs uint32, unspents []*ListUnspentResult, chainParams *ch
if err != nil {
return nil, nil, 0, fmt.Errorf("error reading asset info: %w", err)
}
if nfo.NonStandardScript {
continue // "spendable" or not, don't use these for funding
}

utxo := &compositeUTXO{
utxo: &utxo{
Expand Down
2 changes: 1 addition & 1 deletion dex/networks/btc/script.go
Expand Up @@ -417,7 +417,7 @@ func ExtractScriptAddrs(script []byte, chainParams *chaincfg.Params) (*BtcScript
// For P2SH and non-P2SH multi-sig, pull the addresses from the pubkey script.
class, addrs, numRequired, err := txscript.ExtractPkScriptAddrs(script, chainParams)
nonStandard := class == txscript.NonStandardTy
if err != nil {
if err != nil { // txscript.ExtractPkScriptAddrs always returns a nil error now, so this should not happen
return nil, nonStandard, fmt.Errorf("ExtractScriptAddrs: %w", err)
}
if nonStandard {
Expand Down
14 changes: 7 additions & 7 deletions dex/networks/btc/script_test.go
Expand Up @@ -251,10 +251,7 @@ func TestIsDust(t *testing.T) {

func TestExtractScriptAddrs(t *testing.T) {
// Invalid script
_, nonStd, err := ExtractScriptAddrs(invalidScript, tParams)
if err == nil {
t.Fatalf("no error for bad script")
}
_, nonStd, _ := ExtractScriptAddrs(invalidScript, tParams)
if !nonStd {
t.Errorf("expected non-standard script")
}
Expand Down Expand Up @@ -415,9 +412,12 @@ func TestInputInfo(t *testing.T) {
t.Fatalf("no error for missing redeem script")
}
// Redeem script must be parseable.
_, err = InputInfo(script, invalidScript, tParams)
if err == nil {
t.Fatalf("no error for unparseable redeem script")
spendInfo, err = InputInfo(script, invalidScript, tParams)
if err != nil {
t.Fatalf("failed to parse non-standard script")
}
if !spendInfo.NonStandardScript {
t.Errorf("non-standard script was not detected as such")
}
}

Expand Down

0 comments on commit 0db0fdd

Please sign in to comment.