Skip to content

Conversation

tclemos
Copy link

@tclemos tclemos commented Feb 20, 2025

Motivation

Below is a call to cast cdd to decode this particular transaction:
https://etherscan.io/tx/0x59b8625421982e22ec159ad4f5c32c2352b9185e3e4d0f8771e25c77719e2391

cast cdd --json 'sequenceBatchesValidium((bytes32,bytes32,uint64,bytes32)[],uint64,uint64,address,bytes)' 0xdb5b0ed700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000006772bf190000000000000000000000000000000000000000000000000000000000020716000000000000000000000000af9d27ffe4d51ed54ac8eec78f2785d7e11e5ab100000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000404366a6dc4b2f348a85e0066e46f0cc206fca6512e0ed7f17ca7afb88e9a4c27000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093922dee6e380c28a50c008ab167b7800bb24c2026cd1b22f1c6fb884ceed7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060f85e59ecad6c1a6be343a945abedb7d5b5bfad7817c4d8cc668da7d391faf700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093dfbf04395fbec1f1aed4ad0f9d3ba880ff58a60485df5d33f8f5e0fb73188600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000aa334a426ea9e21d5f84eb2d4723ca56b92382b9260ab2b6769b7c23d437b6b512322a25cecc954127e60cf91ef056ac1da25f90b73be81c3ff1872fa48d10c7ef1ccb4087bbeedb54b1417a24abbb76f6cd57010a65bb03c7b6602b1eaf0e32c67c54168232d4edc0bfa1b815b2af2a2d0a5c109d675a4f2de684e51df9abb324ab1b19a81bac80f9ce3a45095f3df3a7cf69ef18fc08e94ac3cbc1c7effeacca68e3bfe5d81e26a659b500000000000000000000000000000000000000000000

Ideally, the first argument here, which is a tuple, would be JSON encoded as an array rather than a string:
Image

My workaround for now has been use something like jq -r '.[0]' | tr "()" "[]" | sed -e 's/\(0x[0-9a-f]*\)/"\1"/gi' | jq '.' to parse the first argument.

Image

Solution

Changed ./crates/cast/main.rs print_token(tokens) to parse fields into JSON objects instead of strings

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@tclemos tclemos marked this pull request as ready for review February 21, 2025 13:47
@tclemos
Copy link
Author

tclemos commented Feb 26, 2025

@mattsse @zerosnacks would you mind checking this PR?
does it make sense from your perspective?
anything else I could help with?

@zerosnacks
Copy link
Member

Hi @tclemos thanks for your PR!

Whilst I understand the need to parse this as suggested I don't think the proposed solution is the one we are looking for as it effectively reverts the formatting applied in https://github.com/foundry-rs/foundry/blob/5c6b9ae8143bce995e52e927297429257d354ffd/crates/common/fmt/src/dynamic.rs. If we wanted to make a change to the formatting that would be place to make the change.

Personally I think the current formatting for tuples using ( .. ) is correct and consistent.

@jenpaff jenpaff moved this to Ready For Review in Foundry Apr 15, 2025
@tclemos
Copy link
Author

tclemos commented Apr 20, 2025

Hey @jenpaff I saw you moved this PR to Ready For Review, let me know if you need any help with it.

@jenpaff jenpaff moved this from Ready For Review to In Progress in Foundry Apr 22, 2025

for i in data {
let i =
re.replace_all(&i, |caps: &regex::Captures<'_>| format!(r#""{}""#, &caps[0]));
Copy link
Member

@DaniPopes DaniPopes Apr 29, 2025

Choose a reason for hiding this comment

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

This is not the right fix, instead we should have a separate function in crates/common/fmt/src/dynamic.rs that prints as JSON recursively instead of just the top layer, or perhaps even converting DynSolValue to serde_json::Value and print that instead.

I understand this is a more complex change, if you don't have capacity / will to do this we should open an issue for it and close this PR.

@zerosnacks
Copy link
Member

Closing in favor of #11212

Thanks for your PR

@zerosnacks zerosnacks closed this Aug 19, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Foundry Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants