btcsuite / btcutil

Provides bitcoin-specific convenience functions and types
475 stars 408 forks source link

DecodeAddress: don't panic on nil defaultNet #187

Closed matthewleon closed 3 years ago

matthewleon commented 3 years ago

Commit 3ac1210 breaks DecodeAddress's handling of nil defaultNet: it will panic. The documentation suggests that DecodeAddress shouldn't require a defaultNet, and indeed in the case of most Bitcoin addresses, with some small adjustments, it can work without one.

matthewleon commented 3 years ago

Where does the documentation state that it's ok to pass a nil default net?

It doesn't. At least not explicitly. My reading of it suggested that defaultNet would only be used in the case of addresses that don't encode the network:

// The bitcoin network the address is associated with is extracted if possible. // When the address does not encode the network, such as in the case of a raw // public key, the address will be associated with the passed defaultNet.

But that's pretty subjective, and possible lazy, reading on my part.