You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #272: Update to hex-conservative 1.1; drop hex module
44a6974 rename hex_conservative to hex, re-export it, delete old hex module (Andrew Poelstra)
f30b28a re-export 'hex_conservative' as hex (Andrew Poelstra)
1c37bb1 serde_utils: remove old hex module (Andrew Poelstra)
de8927c serde: remove old hex module from 'hex_bytes' module (Andrew Poelstra)
0e28e22 serde_utils: change deserialization bound on hex_bytes from FromHex to From<Vec<u8>> (Andrew Poelstra)
c307d35 replace ToHex with hex-conservative 1.1 functions (Andrew Poelstra)
3a1a2a1 script: replace from_hex and from_str with from_hex_no_prefix (Andrew Poelstra)
0b6ef57 confidential: replace FromHex with FromStr for abf and vbf (Andrew Poelstra)
b4ab7c3 replace Vec::<u8>::from_hex with hex-conservative functions (Andrew Poelstra)
a152b04 bump hex-conservative dependency to 1.1.0 (Andrew Poelstra)
Pull request description:
We have a `hex` module which is loosely based on the `hashes::hex` module from `bitcoin_hashes` 0.11 or so. rust-bitcoin has updated to the `hex-conservative` crate, "hex with a conservative MSRV policy", which is maintained by the rust-bitcoin community.
We recently have released version 1.1, which is finally feature-complete, after years of haggling over API questions.
This has a couple philosophical changes from the old `hex` module:
* There is no `FromHex` trait; the assumption is that if something is naturally hex-encoded then it should use `FromStr` to parse from hex, and there is little value in a trait describing "an object which can be parsed from hex" beyond this. For things like `Script` which have a hex-encoding but aren't "naturally" hex-encoded, they should have inherent methods
* Relatedly, rather than requiring extension traits to decode hex to arrays or vectors, we provide standalone methods `decode_to_vec` and `decode_to_array`
* The `ToHex` trait, which previously was oriented around producing hex-encoded `String`s, has been replaced with `DisplayHex`, a trait which produces a (typically) no-alloc wrapper around an object that can be hex-formatted. It is a trait rather than standalone function(s) so it can be cleanly implemented for both `[u8]` and `[u8]`-like things, but we don't expect users to implement this; they should use `Display` or inherent methods instead
In addition, there are a pile of mechanical changes; `to_hex` becomes `as_hex` in most cases, `Vec::from_hex` becomes `decode_to_vec` or `hex!`, etc. So this PR has a large diff but it's mostly mechanical, and the changes serve both to clean up the code and to eliminate a bunch of allocations.
A later PR will replace our encoding traits with the new `bitcoin-consensus-encoding` trait, which will further eliminate allocations when deserializing objects from hex.
ACKs for top commit:
apoelstra:
ACK 44a6974; successfully ran local tests
delta1:
ACK 44a6974; tested locally
Tree-SHA512: b4ed7ccd0c66b0b59baf2ab11c80af502d3590373992c73270f49ae112ca1ab3296138f08375dbe41cc8e8dac65216562eb13195bb77ee2aa7947ad778b06930
let inp0_sig = Vec::<u8>::from_hex("3044022040d1802d6e10da4c27f05eff807550e614b3d2fa20c663dbf1ebf162d3952689022001f477c953b7c543bce877e3297fccb00ef5dba21d427e79c8bfb8522713309801").unwrap();
283
+
let inp0_sig = hex::hex!("3044022040d1802d6e10da4c27f05eff807550e614b3d2fa20c663dbf1ebf162d3952689022001f477c953b7c543bce877e3297fccb00ef5dba21d427e79c8bfb8522713309801").to_vec();
let inp1_sig = Vec::<u8>::from_hex("3044022017c696503f5e1539fe5cb8dd05f793bd3b6e39f193028a7299a80c94c817a02d022007889009088f46cd9d9f4d137815704170410f53d503b68c1e020292a85b93fa01").unwrap();
289
+
let inp1_sig = hex::hex!("3044022017c696503f5e1539fe5cb8dd05f793bd3b6e39f193028a7299a80c94c817a02d022007889009088f46cd9d9f4d137815704170410f53d503b68c1e020292a85b93fa01").to_vec();
0 commit comments