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

chore(Cast): improve ether_core cli printing #1193 #1253

Merged
merged 1 commit into from
Apr 12, 2022

Conversation

Bind
Copy link
Contributor

@Bind Bind commented Apr 10, 2022

Motivation

cast cli output isn't quite consistent with seth as outlined in issue 1193.

Solution

I've added a simple trait UIfmt which has a function pretty. pretty returns the string that represents the underlying value formatted based on its type. Sounds overly complex, I format the string in the trait impl.

Most of the code can be found in print_utils

In order to handle similar field usage eg.

$ seth block latest timestamp
1649086807

I added get_pretty_<>_attr, which just maps from strings to struct properties. Doesn't seem like there is any easy way to dynamically access struct properties without manually managing a map, but happy to take another stab at it if there is an implementation I can use as a reference.

Didn't want to add a dep, but let me know if there is something you'd like me to pull in to better manage the template strings.

Examples

before:

$ cast block latest timestamp
0x62525184

now:

$ cast block latest timestamp
1649562074

before:

$ cast tx 0x554ae2c124516c2603cde951579a77955d60ce990c5bedccd585ed5c2a17894c
blockHash            "0x7ceb64be78bd9969c214d0ba6f60977023680f6fa0912899af5a6dc23570ecac"
blockNumber          "0xde19d8"
from                 "0x33ddd548fe3a082d753e5fe721a26e1ab43e3598"
gas                  "0x186a0"
gasPrice             "0x96230cda7"
hash                 "0x554ae2c124516c2603cde951579a77955d60ce990c5bedccd585ed5c2a17894c"
input                "0x"
nonce                "0x9fb6"
r                    "0x20dc43240012df060af340b8d56acf9acb95a77d6dbb2180041e345dddc914db"
s                    "0x4b13c3977e699573671f4aff8df60e01b8d6efbc747b80233a0d08eccaf85c48"
to                   "0x769b82d9696a48e79187c3274d0094740e2ddde4"
transactionIndex     "0xa9"
type                 "0x0"
v                    "0x25"
value                "0x15bc2f1a33a2000"

now:

$ cast tx 0x554ae2c124516c2603cde951579a77955d60ce990c5bedccd585ed5c2a17894c
blockHash               0x7ceb64be78bd9969c214d0ba6f60977023680f6fa0912899af5a6dc23570ecac
blockNumber             14555608
from                    0x33ddd548fe3a082d753e5fe721a26e1ab43e3598
gas                     100000
gasPrice                40302071207
hash                    0x554ae2c124516c2603cde951579a77955d60ce990c5bedccd585ed5c2a17894c
input                   0x
nonce                   40886
r                       14863180896486847121274413185188941251302656207390413281479383915883959751899
s                       33958383662778122732978284702091958654673751198163883813615612614842588355656
to                      0x769b82d9696a48e79187c3274d0094740e2ddde4
transactionIndex        169
v                       37
value                   97886160000000000

$ cast block latest
before | now

@Bind Bind force-pushed the bind/issue-1193 branch 2 times, most recently from 5a0241c to c3bfd50 Compare April 10, 2022 04:01
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

thanks,

couple nits :)

cast/src/lib.rs Outdated
Comment on lines 323 to 324
if field_value.is_some() {
field_value.unwrap()
Copy link
Member

Choose a reason for hiding this comment

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

use if let Some() = .. {} here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated!

Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

Nits as well, looks great otherwise! Thank you.

@Bind Bind force-pushed the bind/issue-1193 branch from c3bfd50 to 61fac87 Compare April 10, 2022 22:53
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

thanks for this
lgtm

@mattsse
Copy link
Member

mattsse commented Apr 11, 2022

@Bind can you please run cargo +nightly fmt to fix the lint issue?

@Bind
Copy link
Contributor Author

Bind commented Apr 11, 2022

On it

@tynes
Copy link
Contributor

tynes commented Apr 11, 2022

I think that r and s should stay as bytes32 instead of uint256, seth does it that way. But great work, this is really useful!

@Bind Bind force-pushed the bind/issue-1193 branch from 61fac87 to 3b4b4dd Compare April 11, 2022 15:21
@onbjerg onbjerg added the T-feature Type: feature label Apr 11, 2022
@Bind
Copy link
Contributor Author

Bind commented Apr 11, 2022

r and s should stay as bytes32 instead of uint256

I should be able to handle that.

@gakonst
Copy link
Member

gakonst commented Apr 11, 2022

Thank you @Bind! This is looking great. Only change needed is the r/s change, otherwise we can go for it

@Bind Bind force-pushed the bind/issue-1193 branch 4 times, most recently from 8158b5c to f0447fc Compare April 12, 2022 03:17
@Bind
Copy link
Contributor Author

Bind commented Apr 12, 2022

Alrighty, r & s change should be addressed! lmk if I should tack on anything else. 🥳

@Bind Bind force-pushed the bind/issue-1193 branch from f0447fc to 7342f61 Compare April 12, 2022 16:40
@Bind Bind force-pushed the bind/issue-1193 branch from 7342f61 to 685c9c8 Compare April 12, 2022 16:50
@Bind
Copy link
Contributor Author

Bind commented Apr 12, 2022

Think my vscode formatOnSave was borking the cargo +nightly fmt output. Will fiddle more if needed but should get through the lint action now.

@gakonst gakonst merged commit 8c4ab48 into foundry-rs:master Apr 12, 2022
@Bind Bind deleted the bind/issue-1193 branch April 13, 2022 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants