Fix the PSBT JSON serialization, using serde-derive#508
Fix the PSBT JSON serialization, using serde-derive#508sgeisler merged 9 commits intorust-bitcoin:masterfrom
Conversation
e51969b to
b427ed7
Compare
dr-orlovsky
left a comment
There was a problem hiding this comment.
This looks good since gets rid of a lot of serde impl macros! utACK
src/util/psbt/mod.rs
Outdated
There was a problem hiding this comment.
This line also doesn't compile for me
cargo +stable test '--features=rand use-serde base64' # 2020-12-21T16:02:46 / cargo 1.48.0 (65cbdd2dc 2020-10-14)
Command failed: cargo +stable test --features=rand use-serde base64
Compiling serde_json v1.0.44
Compiling serde_test v1.0.118
Compiling bitcoin v0.25.2 (/tmp/tmpwjnlqhmp)
error[E0433]: failed to resolve: use of undeclared crate or module `bip32`
--> src/util/psbt/mod.rs:356:31
|
356 | let xpub: bip32::ExtendedPubKey =
| ^^^^^ use of undeclared crate or module `bip32`
error: aborting due to previous error
Instead, implement Debug in impl_bytes_newtype.
b427ed7 to
27654a5
Compare
README.md
Outdated
There was a problem hiding this comment.
I don't think there's any reason to downgrade serde. I am testing on 1.29 fine without it.
There was a problem hiding this comment.
If I drop that line, I get this:
error: no matching version `= 1.0.118` found for package `serde_derive`
location searched: registry `https://github.com/rust-lang/crates.io-index`
versions found: 1.0.98
required by package `serde v1.0.118`
... which is depended on by `bitcoin v0.25.2 (file:///home/steven/code/rust/bitcoin)`
Because a higher serde will require a higher serde_derive. Somehow Cargo is not very smart about all that and it can't realize that it has a pin on _derive and then look for a matching serde.
There was a problem hiding this comment.
The script I use is
set -e
MSRV="1.29.0"
CMD="rustup run ${MSRV}"
rm -f Cargo.lock
$CMD cargo generate-lockfile
$CMD cargo update --package "cc" --precise "1.0.41"
$CMD cargo update --package "serde" --precise "1.0.98"
$CMD cargo update --package "serde_derive" --precise "1.0.98"
$CMD cargo test --features "use-serde rand base64"
Perhaps we should commit that.
There was a problem hiding this comment.
None of my scripts pin serde and everything works fine for me.
There was a problem hiding this comment.
Oh, I'm lying, it's just that my scripts never made any progress on this PR because of the other compilation issue.
There was a problem hiding this comment.
I just tried and this worked:
rm -rf target/ && rm Cargo.lock && cargo +1.29.0 test
There was a problem hiding this comment.
@elichai you have to add --features=use-serde to see the failure
ca41df6 to
e5f285f
Compare
src/serde_utils.rs
Outdated
There was a problem hiding this comment.
One slightly annoying consequence of directly serializing the tuple instead of a wrapper is that the value is serialized as array of u8s instead of hex like everything else.
There was a problem hiding this comment.
I think this is more than slightly annoying but it's also really unclear how to fix it.
There was a problem hiding this comment.
It might be worthwhile to duplicate this entire module, changing U to Vec<u8> and doing hex-serialization.
There was a problem hiding this comment.
Could we get away with having a Preferred(De)Serialize trait which is identical to the (De)Serialize traits and has a default impl just passing through to the serde version? But for certain types we can implement default (de)serialization methods.
e5f285f to
f54dcbb
Compare
|
Pushed a few more changes:
|
So that we can later distinguish other modules over maps.
Non-human-readable serialization (binary) doesn't need hexification.
816d98e to
3fd94ef
Compare
| }], | ||
| }; | ||
| let encoded = ::serde_json::to_string(&psbt).unwrap(); | ||
| println!("encoded PSBT: {}", encoded); |
There was a problem hiding this comment.
Is that a problem? It's in a unit test, so it will only be printed when used with --nocapture. I can remove it if it's a problem. When changing any of the PSBT fields, this helps looking at how the JSON actually looks.
There was a problem hiding this comment.
(F.e. the Transactioin.witness field still is Vec<Vec<u8>> which doesn't print as hex. I tried fixing that too, but I got tired of fighting serde for a while, might do that in another PR.)
There was a problem hiding this comment.
Yeah, that's fair, you can leave it in.
This re-introduces serde-derive, but adds version pinning instructions to the README.
I hope that's fine. I failed to add hex support for the values of maps (like
partial_sigs: BTreeMap<PublicKey, Vec<u8>>). For that I fear we'd need some helper crate likeserde_with. Even though, I'm sure in theory it's possible to do manually, but I couldn't figure it out.