Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Witness human-readable serde #899

Closed
wants to merge 3 commits into from
Closed

Witness human-readable serde #899

wants to merge 3 commits into from

Conversation

dr-orlovsky
Copy link
Collaborator

Previous implementations of Witness (and Vec<Vec>) serde serialization didn't support human-readable representations. This resulted in long unreadable JSON/YAML byte arrays, which were especially ugly when pretty-printed (a line per each byte).

an example of that ugliness
unsigned_tx:
  version: 2
  lock_time: 0
  input:
    - previous_output: "c96ec66b95ab23bbc287d698c5e63f141dcd75b7728d00f5a89e1f2d93a9424f:1"
      script_sig: ""
      sequence: 4294967295
      witness: []
  output:
    - value: 10000
      script_pubkey: 5120137b87fb9b00c8e09f1b91a9379c98eef1774a568f8ad8514079aaa3941666f3
    - value: 9666
      script_pubkey: 5120566b18c07d063d114a572735c4705f4aa007486b016463d4ffae278d225c3a91
version: 0
xpub:
  tpubDCLfi9JceW8Er2qcaK7gBudjXPrS31VCf7wiiPFLV2s9ptKLkaGxnQutTtdsJoqgbRxWhBDMHJEZ6XsGfC26QhMZEoRYfdCFS3qhaXskUeD:
    - 877c9433
    - "m/86'/1/0'"
  tpubDCLfi9JceW8FJEw6RpfrCtByfaKCHsS9VHdrvB97ZkfS2wKbxtygMxW4MraMuPV5avsDkvae5t36MMwtRuJ5btAfQh7NxKGpmNxzwSm15ZF:
    - 877c9433
    - "m/86'/1/10'"
proprietary: []
unknown: []
inputs:
  - non_witness_utxo:
      version: 2
      lock_time: 2190833
      input:
        - previous_output: "8c7d5031f9e1e9ef691aacedd20a5a8e6dd79882b569581c331a38c0ba17491c:0"
          script_sig: ""
          sequence: 4294967294
          witness:
            - - 48
              - 68
              - 2
              - 32
              - 108
              - 145
              - 6
              - 133
              - 173
              - 227
              - 190
              - 147
              - 176
              - 196
              - 50
              - 84
              - 118
              - 66
              - 59
              - 149
              - 52
              - 171
              - 92
              - 92
              - 9
              - 76
              - 28
              - 247
              - 9
              - 241
              - 241
              - 151
              - 142
              - 82
              - 171
              - 112
              - 2
              - 32
              - 109
              - 30
              - 127
              - 238
              - 0
              - 53
              - 58
              - 4
              - 75
              - 100
              - 184
              - 121
              - 132
              - 139
              - 142
              - 49
              - 132
              - 219
              - 3
              - 224
              - 54
              - 155
              - 171
              - 63
              - 248
              - 150
              - 106
              - 132
              - 147
              - 176
              - 236
              - 123
              - 1
            - - 2
              - 134
              - 28
              - 194
              - 153
              - 223
              - 0
              - 94
              - 181
              - 115
              - 213
              - 57
              - 15
              - 109
              - 206
              - 82
              - 84
              - 140
              - 99
              - 210
              - 142
              - 67
              - 15
              - 178
              - 230
              - 53
              - 245
              - 83
              - 45
              - 141
              - 28
              - 13
              - 230
      output:
        - value: 464333
          script_pubkey: 0014862b51f53fa54235a0c5c5e1fb256d73dc90fffc
        - value: 20000
          script_pubkey: 5120f23d25a56919ba6c873a727a2699c8764fffaa2f5fb70df2f5febbec86b9fe8f
    witness_utxo: ~
    partial_sigs: {}
    sighash_type:
      inner: 1
    redeem_script: ~
    witness_script: ~
    bip32_derivation: []
    final_script_sig: ~
    final_script_witness: ~
    ripemd160_preimages: {}
    sha256_preimages: {}
    hash160_preimages: {}
    hash256_preimages: {}
    tap_key_sig:
      sig: 987a59ed7b7a57efa602b1ed86551f4bf4759f5198adc006b0043b045091813d870a253a45a0253c55acb77f71f3d3b90b05ea02a5989fdf7bb74535a8d0afb3
      hash_ty: All
    tap_script_sigs:
      - - - 6332fd4c53a053bccc53a1d82fa2e1e2276ce609c0200d3ced4cd74a22653388
          - 27686a1d5598f23ac8884676a4ffd6b742a9936abcc10fae26aecd09776af574
        - sig: 7e5e4521edccbe61bec1370b61fbd3d39ae8be4229af6f8c428faf7a02f1a4432b520ffefa6431482aa51b76e6dda8518a2aefa4ca90464b91f8ee1800ddff4d
          hash_ty: All
      - - - 6332fd4c53a053bccc53a1d82fa2e1e2276ce609c0200d3ced4cd74a22653388
          - 3b17906c53e5308858f3e5a78f1ca33ef014cb84096f608b35983822bc5867da
        - sig: 90f9f9651a0d6780a6ee2786868dbf546b99fef527fa0b1c3e92e7c36dc05f4006f22944bd0544724d55c0b43c091745d67a759cc015c4ec8b43ab2b8aea0d6f
          hash_ty: All
      - - - 6332fd4c53a053bccc53a1d82fa2e1e2276ce609c0200d3ced4cd74a22653388
          - d7cc5bca95baca4b690daa28d0efe18ae82fe4cc1ce44814ee2be098b7f1510b
        - sig: 7ad2b4fa33e8c9fe02e1e7db89068ca5171f1173bc876451d1d71f7519a1fbe8aedd4c5b93e202b2dafa8eb3ae17def57f4f9b0ec9c9a5c93caf4ab541d94b55
          hash_ty: All
    tap_scripts:
      - - leaf_version: 192
          output_key_parity: 1
          internal_key: d99571989a8fcd762e3bd5b3e864ee81727fbff82660c4a57b5de501b4ba8ed4
          merkle_branch:
            - 27686a1d5598f23ac8884676a4ffd6b742a9936abcc10fae26aecd09776af574
            - 3b17906c53e5308858f3e5a78f1ca33ef014cb84096f608b35983822bc5867da
        - - 206332fd4c53a053bccc53a1d82fa2e1e2276ce609c0200d3ced4cd74a22653388ac20cff309356e57796533f8c22ec6b9625e0b465498f123a8169b2a9d8e2c278255ba20dec28c52648655a6d711525503bbfebaa8c12a332e3c9ffd82064ff166af698cba529d5ab1
          - 192
      - - leaf_version: 192
          output_key_parity: 1
          internal_key: d99571989a8fcd762e3bd5b3e864ee81727fbff82660c4a57b5de501b4ba8ed4
          merkle_branch:
            - 9732abae6c1729c3bb135a2f52977265f290c8d8fba6377c7a0e0cc5eece5567
        - - 206332fd4c53a053bccc53a1d82fa2e1e2276ce609c0200d3ced4cd74a22653388ac20cff309356e57796533f8c22ec6b9625e0b465498f123a8169b2a9d8e2c278255ba20dec28c52648655a6d711525503bbfebaa8c12a332e3c9ffd82064ff166af698cba539c
          - 192
      - - leaf_version: 192
          output_key_parity: 1
          internal_key: d99571989a8fcd762e3bd5b3e864ee81727fbff82660c4a57b5de501b4ba8ed4
          merkle_branch:
            - d7cc5bca95baca4b690daa28d0efe18ae82fe4cc1ce44814ee2be098b7f1510b
            - 3b17906c53e5308858f3e5a78f1ca33ef014cb84096f608b35983822bc5867da
        - - 206332fd4c53a053bccc53a1d82fa2e1e2276ce609c0200d3ced4cd74a22653388ac20cff309356e57796533f8c22ec6b9625e0b465498f123a8169b2a9d8e2c278255ba20dec28c52648655a6d711525503bbfebaa8c12a332e3c9ffd82064ff166af698cba519d0164b1
          - 192
    tap_key_origins:
      - - 6332fd4c53a053bccc53a1d82fa2e1e2276ce609c0200d3ced4cd74a22653388
        - - - 27686a1d5598f23ac8884676a4ffd6b742a9936abcc10fae26aecd09776af574
            - 3b17906c53e5308858f3e5a78f1ca33ef014cb84096f608b35983822bc5867da
            - d7cc5bca95baca4b690daa28d0efe18ae82fe4cc1ce44814ee2be098b7f1510b
          - - fcedac08
            - m/0/0
      - - d99571989a8fcd762e3bd5b3e864ee81727fbff82660c4a57b5de501b4ba8ed4
        - - []
          - - 4d94875d
            - m/0/0
    tap_internal_key: d99571989a8fcd762e3bd5b3e864ee81727fbff82660c4a57b5de501b4ba8ed4
    tap_merkle_root: 94b1f8ca0e387b63d25fce87354e841f18d2a97c1027aaee7e3072fa40233b1e
    proprietary: []
    unknown: []
outputs:
  - redeem_script: ~
    witness_script: ~
    bip32_derivation: []
    tap_internal_key: ~
    tap_tree: ~
    tap_key_origins: []
    proprietary: []
    unknown: []
  - redeem_script: ~
    witness_script: ~
    bip32_derivation: []
    tap_internal_key: 9342cfe214556af10e9b34549458af0d937603c68dd6e8b95f005095b26df7da
    tap_tree:
      branch:
        - hash: 2b15aae72ed4ac365785d21c56cf435a43633ba2af84e4ed3c0b4d26897bbcf2
          leaves:
            - script: 2071beef4035dca001a9ab71983b860d273b1a2c8173d00656b8bbaf497e6e444dac207339326d461857494b87bbe2cc9b3e31ccff1d7844a2bdfcb6c5c2e9727098aeba20ad21352f1ca6eef7db5fa23f6e573eb5c823da6c7755c61c652a45d3349d059aba519d0164b1
              ver: 192
              merkle_branch:
                - 2409b7478a75b0350b4710b5eca54056fde8c22ba035eb209e9a1e4e659783f1
                - 9653be7568281a9657d57478560cb2638acf80c98124f0318adaedb16d63b02c
            - script: 2071beef4035dca001a9ab71983b860d273b1a2c8173d00656b8bbaf497e6e444dac207339326d461857494b87bbe2cc9b3e31ccff1d7844a2bdfcb6c5c2e9727098aeba20ad21352f1ca6eef7db5fa23f6e573eb5c823da6c7755c61c652a45d3349d059aba529d5ab1
              ver: 192
              merkle_branch:
                - 304ad4baaba8c42012939da18cd35fded9d15fb24e8af33e364cf02fb340a5ce
                - 9653be7568281a9657d57478560cb2638acf80c98124f0318adaedb16d63b02c
            - script: 2071beef4035dca001a9ab71983b860d273b1a2c8173d00656b8bbaf497e6e444dac207339326d461857494b87bbe2cc9b3e31ccff1d7844a2bdfcb6c5c2e9727098aeba20ad21352f1ca6eef7db5fa23f6e573eb5c823da6c7755c61c652a45d3349d059aba539c
              ver: 192
              merkle_branch:
                - ac035f11d4fdce47af56e62818ad3f11c7b6a2c5bcefc435787148f2c08318bf
    tap_key_origins: []
    proprietary: []
    unknown: []

This breaks backward compatibility for human-readable types, but I assume that previous representation was actually "non-human readable" and it was a bug, not a feature. Waiting for confirmation from @JeremyRubin who I know uses JSON serialization a lot.

This also removes tests for JSON backward-compatible encoding. Human-readable 
encoding will be changed in the next commit and this will break backward 
compatibility, thus that part of the test is removed.
@dr-orlovsky dr-orlovsky added the API break This PR requires a version bump for the next release label Mar 22, 2022
@dr-orlovsky dr-orlovsky added this to the 0.28.0 milestone Mar 22, 2022
@dr-orlovsky dr-orlovsky added this to In progress in PSBT via automation Mar 22, 2022
@dr-orlovsky
Copy link
Collaborator Author

Vary strange that CI reports blockdata::transaction::tests::test_segwit_tx_decode failing, I can't reproduce that locally. Also that test must not be affected by the code from the current PR. Will try to force-push and re-run Ci

@tcharding
Copy link
Member

tcharding commented Mar 23, 2022

You might of forgotten --features=use-serde to get it to fail locally.

The test failure seems to be because with this PR applied Witness no longer serde roundtrips when using to/from_value. I don't know why. The added test uses to_string/from_str.

serde roundtrip fails for Transaction (which has TxIn which has Witness)

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two unit tests could be split up. They each contain a serde regression test and a serde roundtrip test.

@tcharding
Copy link
Member

Warning project management discussion: I'm confused, what does it mean that this PR got added to 0.28 milestone but does not use the RC-fix label, do we have two things now that each describe the same thing? Perhaps I should never have added the RC-fix label?

@dr-orlovsky
Copy link
Collaborator Author

Warning project management discussion

My understanding that labels are useful for classification (priority, module, type) and not workflow (milestone, number of reviews required, stage of review) purposes. For the later, github provides milestones and project boards. So my proposal is to use appropriate tools and not to overload labels with all these responsibilities :)

@dr-orlovsky
Copy link
Collaborator Author

dr-orlovsky commented Mar 23, 2022

@tcharding thank you for the help with clarifying the source of the error. In fact I found out that error is not happening during Display/FromStr roundtrip, but instead during serde_json::to_value/from_value roundtrip, which does not perform string serialization (using objected JSON representation instead). Investigating how this can fail while JSON string roundripts in other tests for the same Witness structure do not fail.

PS: the actual error is not related to JSON serialization, but somehow to serde_json typing:
invalid type: string \"0000000000000000000000000000000000000000000000000000000000000000\", expected a borrowed string

@dr-orlovsky
Copy link
Collaborator Author

dr-orlovsky commented Mar 23, 2022

It really seems we have a serde_json bug here, which, for visit_seq implements visit_str but does not implement visit_string method. This problem can be avoided if we will switch in test_macros::serde_round_trip! on using serde_json::from_str/to_string instead of serde_json::from_value/to_value. Pushing commit showcasing that 3af0f42.

The reason of the bug is the fact that serde_json calls https://github.com/serde-rs/serde/blob/7e19ae8c9486a3bbbe51f1befb05edee94c454f9/serde/src/de/mod.rs#L1476-L1492 due to the fact that serde_json visitor does not provide visit_str implementation for a visitor used by serde_json::from_value.

@dr-orlovsky
Copy link
Collaborator Author

Ok, completed my investigation and fixed the issue.

While it is indeed a serde_json bug, which I already filed (serde-rs/json#871), it was also triggered by the fact that I did not specify the String type in data deserialization explicitly here:

while let Option::Some(elem) = a.next_element()? {

Pushed the fixed version which made an explicit type:

while let Option::Some(elem) = a.next_element::<String>()? {

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just two superficial suggestions :) Out of interest did you happen to audit all the serde impls we have to see if any others do not use is_human_readable? (Just asking because I'll add it to my todo list if not.)

src/blockdata/witness.rs Show resolved Hide resolved
src/blockdata/witness.rs Outdated Show resolved Hide resolved
@dr-orlovsky
Copy link
Collaborator Author

I looked into other places using is_human_readable - and there were few; but I did not audit are all possible locations use it

Previous implementations of Witness (and Vec<Vec<u8>>) serde serialization
didn't support human-readable representations. This resulted in long unreadable 
JSON/YAML byte arrays, which were especially ugly when pretty-printed (a line 
per each byte).
@apoelstra
Copy link
Member

Is this needed for 0.28.0?

@JeremyRubin
Copy link
Contributor

i'd be a mild NACK here -- the best thing to do IMO is to have code on the other end that can parse a witness and represent it.

i personally wouldn't use this in Sapio since i think for PSBTs i try to serialize them to encoded strings first almost universally (maybe i don't do this when it's just a internal-to-internal thing, but almost certainly i do it for internal/external since matching rust's choice of json for psbt is undesirable)

@sanket1729
Copy link
Member

@dr-orlovsky, I think this is also a feature request and not a bug introduced in 0.28.0. We never had human-readable serde for Witness, and I don't think we should be discussing this near rc.2

@dr-orlovsky
Copy link
Collaborator Author

@apoelstra it is desirable for 0.28.0 since we introduced breaking change with new Witness type and changing serde impl will be another breaking change. Unlike PsbtSigHashType, Witness is used in Transaction serialization and serde change there will be breaking according to our recent discussion.

@JeremyRubin
Copy link
Contributor

One option is to expose the new serialization in a minor release in 0.28 under a feature flag (improved-human-json) and then fully break in 0.29.

@JeremyRubin
Copy link
Contributor

or another -- just do an 0.29 in a month with the breaking changes if feature flag is bad. we shouldn't slow down releases just because we don't like 'ngu' on release version, semver is supposed to be used to help people pick, not moralize 0.28 as worse than 0.29.

@sanket1729 sanket1729 mentioned this pull request Mar 28, 2022
@sanket1729
Copy link
Member

The code looks correct to me, I would not mind having this. But I would like this to get more reviews from people using serde. There seems to be some controversy around it, and I don't think it is a super-critical feature that should be release-blocking unlike #901 or #898.

@dr-orlovsky
Copy link
Collaborator Author

dr-orlovsky commented Mar 28, 2022

I personally see no harm of adding this functionality here as we did for all other types. Yes, it is possible to create wrappes upstream and manually do all the serde serializaiton, but since this is the only issue preventing from normal PSBT human readable serde, I do not see why we just can have it here and save a lot of work upstream.

@JeremyRubin
Copy link
Contributor

the harm is that it's a late phase substantial breaking change which would take more time to actually review.

"human readable" is a attribute, not a purpose. Display is for "human readable" but not machine parsable. serde serializations are machine parsable. This breaks, in a non-trivial way, the representations of PSBTs late in the phase of a software release. after a rc.1, i don't think we should do breaking changes beyond something being newly broken, less os a feature change.

e.g., if we had to change a method name, i wouldn't think that a huge deal as the fix is trivial. but changing the "AJI" of our serializations has ramifications for people building up the stack.

this is not an argument against the change in general, but just that if you wanted it done a week before a release is not the time for it.

@dr-orlovsky
Copy link
Collaborator Author

Interestingly enough the argument is reversed compared to recent case of PSBT serde. Here we also have a consensus encoding for transaction data which is preferable to use - as was proposed by you in #898 (comment)

Are you aware of people relying in their projects on serde human_readable serialization format for bitcoin Transaction-related data to whom this change will introduce harm, taking into account the amount of breaking changes we have in this release anyway?

@shesek @romanz @RCasatta @Kixunil will this break anything in your projects?

@JeremyRubin
Copy link
Contributor

the difference is that change is for unreleased stuff, chiefly the newly introduced PsbtSigHashType variants. This would only affect, afaiu, people using PSBTs with taproot support.

In contrast, the change to the PSBT type as a whole affects users from prior releases.

@dr-orlovsky
Copy link
Collaborator Author

In contrast, the change to the PSBT type as a whole affects users from prior releases.

Yes, the whole 0.28.0 release provides a largest set of breaking API and serialization changes ever, so this is the perfect time to have this change bundled.

@tcharding
Copy link
Member

Seems like fair points from both of you, perhaps we have to accept that this 0.28 release is super unusual, is not going to be perfect, and should not set precedence on how we do releases? I'm starting to think that we should just use the Benevolent Dictator method for selection of PRs to merge for this release.

Also I think we should spend a little time going over all the Taproot stuff once we release and do some consecutive major releases before rushing headlong into the next shiny new thing (MSRV/2018 bump).

@Kixunil
Copy link
Collaborator

Kixunil commented Mar 29, 2022

It doesn't break anything for me and I don't understand the opposition. The type was added in 0.28, so there can not be any break (Besides type being added but that's already a break in a different part.)

@JeremyRubin
Copy link
Contributor

The type wasn't added in 0.28, the Vec<Vec<>> would have the same json/yaml repr as Witness since Witness is a newtype wrapper.

@JeremyRubin
Copy link
Contributor

  • pedantically, it's not a newtype wrapper, but the serde manual impl is the same as a transparent newtype.

@Kixunil
Copy link
Collaborator

Kixunil commented Apr 5, 2022

Yes, still I think hex represenation would be better/it's a bug not to. People concerned with perfect compatibility should probably use consensus encoding anyway - that one is guaranteed to be compatible and is also more compact. :)

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO incorrect size hint is quite annoying as it could cause memory blow up so I'd like to see it fixed. The rest looks correct.

}
seq.end()
} else {
let vec: Vec<_> = self.to_vec();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note #942 applies, not urgent.

if serializer.is_human_readable() {
let mut seq = serializer.serialize_seq(Some(self.serialized_len()))?;
for elem in self.iter() {
seq.serialize_element(&elem.to_hex())?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocation should be avoidable, not urgent but we could create an issue if this gets merged.

use hashes::hex::ToHex;
use serde::ser::SerializeSeq;
if serializer.is_human_readable() {
let mut seq = serializer.serialize_seq(Some(self.serialized_len()))?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serialized_len looks wrong - it's number of bytes, not number of items.

{
use hashes::hex::FromHex;
let mut ret = Vec::new();
while let Some(elem) = a.next_element::<String>()? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-critical performance stuff: reserve(), serde_str_helpers::DeserBorrowStr instead of String, try appending hex bytes to existing Witness instead of allocating a new Vec for each element.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to get @apoelstra approval for another external dependency :) But I can confirm that that crate was created by @Kixunil and managed by him and me only with the most strict requirements

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also NIH it, it's fairly simple. I mainly brin-dumped all opts I could see.

let mut ret = Vec::new();
while let Some(elem) = a.next_element::<String>()? {
let vec = Vec::<u8>::from_hex(&elem).map_err(|_| {
serde::de::Error::invalid_value(serde::de::Unexpected::Str(&elem), &"hex byte representation")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too important: I think this could be even more detailed - unexpected len and unexpected char.

@@ -282,8 +292,35 @@ impl<'de> serde::Deserialize<'de> for Witness {
where
D: serde::Deserializer<'de>,
{
let vec: Vec<Vec<u8>> = serde::Deserialize::deserialize(deserializer)?;
Ok(Witness::from_vec(vec))
struct Visitor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: suggest calling it HRVisitor

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it help in hiring? :D

Copy link
Member

@tcharding tcharding Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely do not want HR visitors around here :)

@tcharding tcharding removed this from the 0.28.0 milestone Apr 21, 2022
@tcharding
Copy link
Member

I cleared the 0.28.0 milestone from this PR (as well as closing the milestone) because 0.28 is released. Flagging it so you can add a milestone back to this PR if you wish to.

@dr-orlovsky
Copy link
Collaborator Author

@tcharding I can't edit milestones anymore

@Kixunil Kixunil added this to the 0.29.0 milestone Apr 21, 2022
@Kixunil
Copy link
Collaborator

Kixunil commented Apr 21, 2022

Damn, this probably should've been RC fix :(

@tcharding
Copy link
Member

What is the status of this PR please? Are you working on it @dr-orlovsky, should I pick it up, or should we close it? Thanks.

@dr-orlovsky
Copy link
Collaborator Author

Feel free to pick it up

@tcharding
Copy link
Member

Closing in favour of #1068

@tcharding tcharding closed this Jun 28, 2022
PSBT automation moved this from In progress to Done Jun 28, 2022
apoelstra added a commit that referenced this pull request Jul 18, 2022
a1df62a Witness human-readable serde test (Dr Maxim Orlovsky)
68577df Witness human-readable serde (Dr Maxim Orlovsky)
93b66c5 Witness serde: test binary encoding to be backward-compatible (Dr Maxim Orlovsky)
b409ae7 witness: Refactor import statements (Tobin C. Harding)
e23d3a8 Remove unnecessary whitespace (Tobin C. Harding)
ac55b10 Add whitespace between functions (Tobin C. Harding)

Pull request description:

  This is dr-orlovsky's [PR](#899) picked up at his permission in the discussion thread.

  I went through the review comments and implemented everything except the perf optimisations. Also includes a patch at the front of the PR that adds a unit test that can be run to see the "before and after", not sure if we want it in, perhaps it should be removed before merge.

  This PR implicitly fixes 942.

  To test this PR works as advertised run `cargo test display_transaction --features=serde -- --nocapture` after creating a unit test as follows:
  ```rust

      // Used to verify that parts of a transaction pretty print.
      // `cargo test display_transaction --features=serde -- --nocapture`
      #[cfg(feature = "serde")]
      #[test]
      fn serde_display_transaction() {
          let tx_bytes = Vec::from_hex(
              "02000000000101595895ea20179de87052b4046dfe6fd515860505d6511a9004cf12a1f93cac7c01000000\
              00ffffffff01deb807000000000017a9140f3444e271620c736808aa7b33e370bd87cb5a078702483045022\
              100fb60dad8df4af2841adc0346638c16d0b8035f5e3f3753b88db122e70c79f9370220756e6633b17fd271\
              0e626347d28d60b0a2d6cbb41de51740644b9fb3ba7751040121028fa937ca8cba2197a37c007176ed89410\
              55d3bcb8627d085e94553e62f057dcc00000000"
          ).unwrap();
          let tx: Transaction = deserialize(&tx_bytes).unwrap();
          let ser = serde_json::to_string_pretty(&tx).unwrap();
          println!("{}", ser);
      }
  ```

  Fixes: #942

ACKs for top commit:
  apoelstra:
    ACK a1df62a
  Kixunil:
    ACK a1df62a

Tree-SHA512: d0ef5b8cbf1cf8456eaaea490a793f1ac7dfb18067c4019a2c3a1bdd9627a231a4dd0a0151a4df9af2b32b909d4b384a5bec1dd3e38d44dc6a23f9c40aa4f1f9
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
…for `Witness`

a1df62a Witness human-readable serde test (Dr Maxim Orlovsky)
68577df Witness human-readable serde (Dr Maxim Orlovsky)
93b66c5 Witness serde: test binary encoding to be backward-compatible (Dr Maxim Orlovsky)
b409ae7 witness: Refactor import statements (Tobin C. Harding)
e23d3a8 Remove unnecessary whitespace (Tobin C. Harding)
ac55b10 Add whitespace between functions (Tobin C. Harding)

Pull request description:

  This is dr-orlovsky's [PR](rust-bitcoin/rust-bitcoin#899) picked up at his permission in the discussion thread.

  I went through the review comments and implemented everything except the perf optimisations. Also includes a patch at the front of the PR that adds a unit test that can be run to see the "before and after", not sure if we want it in, perhaps it should be removed before merge.

  This PR implicitly fixes 942.

  To test this PR works as advertised run `cargo test display_transaction --features=serde -- --nocapture` after creating a unit test as follows:
  ```rust

      // Used to verify that parts of a transaction pretty print.
      // `cargo test display_transaction --features=serde -- --nocapture`
      #[cfg(feature = "serde")]
      #[test]
      fn serde_display_transaction() {
          let tx_bytes = Vec::from_hex(
              "02000000000101595895ea20179de87052b4046dfe6fd515860505d6511a9004cf12a1f93cac7c01000000\
              00ffffffff01deb807000000000017a9140f3444e271620c736808aa7b33e370bd87cb5a078702483045022\
              100fb60dad8df4af2841adc0346638c16d0b8035f5e3f3753b88db122e70c79f9370220756e6633b17fd271\
              0e626347d28d60b0a2d6cbb41de51740644b9fb3ba7751040121028fa937ca8cba2197a37c007176ed89410\
              55d3bcb8627d085e94553e62f057dcc00000000"
          ).unwrap();
          let tx: Transaction = deserialize(&tx_bytes).unwrap();
          let ser = serde_json::to_string_pretty(&tx).unwrap();
          println!("{}", ser);
      }
  ```

  Fixes: #942

ACKs for top commit:
  apoelstra:
    ACK a1df62a
  Kixunil:
    ACK a1df62a

Tree-SHA512: d0ef5b8cbf1cf8456eaaea490a793f1ac7dfb18067c4019a2c3a1bdd9627a231a4dd0a0151a4df9af2b32b909d4b384a5bec1dd3e38d44dc6a23f9c40aa4f1f9
@Kixunil Kixunil removed this from the 0.29.0 milestone Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API break This PR requires a version bump for the next release
Projects
PSBT
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants