Commit Graph

5 Commits

Author SHA1 Message Date
Jamil Lambert, PhD 282434d4bd
Use variable directly in format! string
There is a new lint error on nightly-2025-04-25 "variables can be used
directly in the `format!` string".

Use the variables in the `format!` string for all cases in
`bitcoin/examples/`.
2025-05-06 09:49:03 +01:00
Tobin C. Harding 5d5a19793a
Run the formatter 2025-04-28 13:44:24 +10:00
Tobin C. Harding 2b72f1f30b
Make Lower/Upper hex print scripts with len prefix
Add the length prefix when formatting hex strings by way of `LowerHex`
and `UpperHex`.

This looses formatting options because I can't remember right now how
not to - again.
2025-04-28 13:43:07 +10:00
Tobin C. Harding c27b95fb0d
Make script to/from hex use consensus encoding
I'm not sure why we do not use consensus encoding currently for encoding
and decoding scripts to/from hex strings. Many tests include hard coded
hex which do not include the length prefix.

- Add a pair of encoding functions to encode/decode to/from hex without
the length prefix.
- Make `to_hex` and `from_hex` expect the length prefix i.e., use
consensus encoding.

This makes the API easier to use because the various encoding APIs can
be use together now eg `consensus::encode_hex` and `ScriptBuf::from_hex`.
2025-04-28 13:39:44 +10:00
Tobin C. Harding f4bc58dc48
bitcoin: Add a script encoding example
Our encoding/decoding support for scripts is currently a bit convoluted.
Add an example that shows how all the APIs go together.

Note this highlights a potential problem. `to_hex_string` is in
`bitcoin` and therefore has access to consensus encoding but does not
include the length prefix. This means that the output string from
`to_hex_string` cannot be parsed with
`consensus::encode::deserialize_hex` - which is surprising and has lead
to difficulty by at least one user trying to debug.
2025-04-28 13:38:12 +10:00