rust-bitcoin / rust-bitcoin

Rust Bitcoin library
Creative Commons Zero v1.0 Universal
2.13k stars 696 forks source link

Make address encoding more modular / flexible #642

Closed benma closed 2 years ago

benma commented 3 years ago

Would be possible to put the bech32 hrp, base58 version, etc. into the Network directly?

E.g. pub struct Network { pub bech32_hrp: &'static str, ... }.

Then the data would not be scattered around like here, aiding readability.

The predefined networks (Bitcoin, Testnet, etc). could then be constants to choose from.

It would look something like this: https://github.com/digitalbitbox/bitbox02-firmware/blob/5003a78801faca996cc4d027ef36818e9f711bf7/src/rust/bitbox02-rust/src/hww/api/bitcoin/params.rs#L22

This would make it easy for clients use network parameters for other chains without needing to make PRs by simply defining their own network instances.

Imho this would be much better than adding all network params that users requests to this repo. Adding to the Network enum would be a breaking change every time.

Context: I am looking into using this crate in the BitBox02 firmware. It seems promising that we could start using this crate, but is missing e.g. Litecoin params.

Let me know if this would be good change, then I could attempt a PR.

benma commented 3 years ago

This change looks quite invasive. A better solution might to add the p2pkh, p2sh, p2wpkh, p2shwpkh etc. functions also to Payload, making it usable without tying it to a network like the Address does. It would be some additional functions and no breaking change.

benma commented 3 years ago

Please check this PR as a proposal, following my 2nd comment to introduce this function in a backwards compatible way:

https://github.com/rust-bitcoin/rust-bitcoin/pull/643

dr-orlovsky commented 2 years ago

Seems to be closed by #643. @benma please feel free to re-open this issue if I missed something