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

add tx decoder #2415

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions contrib/scripts/txdecoder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Takes the transaction hash as input
rawTx=$1

# Decode the transaction using cast dt and store the result in a variable
decodedTx=$(cast dt $rawTx)
Copy link
Contributor

Choose a reason for hiding this comment

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

To prevent globbing and word splitting, double-quote variables in command substitutions.

- decodedTx=$(cast dt $rawTx)
+ decodedTx=$(cast dt "$rawTx")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
decodedTx=$(cast dt $rawTx)
decodedTx=$(cast dt "$rawTx")


# Use jq to pretty print the decoded transaction
echo "$decodedTx" | jq '.'

# Use jq to extract the values from the decoded transaction
type=$(echo "$decodedTx" | jq -r '.type')
gas=$(echo "$decodedTx" | jq -r '.gas')
value=$(echo "$decodedTx" | jq -r '.value')
nonce=$(echo "$decodedTx" | jq -r '.nonce')
maxPriorityFeePerGas=$(echo "$decodedTx" | jq -r '.maxPriorityFeePerGas')
maxFeePerGas=$(echo "$decodedTx" | jq -r '.maxFeePerGas')

# Note: The actual conversion commands will depend on the capabilities of 'cast'
echo "Converted Values:"
echo "Type: $(cast --to-dec $type)" # This specific conversion might not make sense for 'type', as it's not a value field.
echo "Gas: $(cast --to-dec $gas)"
echo "Value: $(cast --to-unit $value ether)"
echo "Nonce: $(cast --to-dec $nonce)"
Comment on lines +25 to +27
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure variables are double-quoted in command substitutions to prevent globbing and word splitting.

- echo "Gas: $(cast --to-dec $gas)"
- echo "Value: $(cast --to-unit $value ether)"
- echo "Nonce: $(cast --to-dec $nonce)"
+ echo "Gas: $(cast --to-dec "$gas")"
+ echo "Value: $(cast --to-unit "$value" ether)"
+ echo "Nonce: $(cast --to-dec "$nonce")"

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
echo "Gas: $(cast --to-dec $gas)"
echo "Value: $(cast --to-unit $value ether)"
echo "Nonce: $(cast --to-dec $nonce)"
echo "Gas: $(cast --to-dec "$gas")"
echo "Value: $(cast --to-unit "$value" ether)"
echo "Nonce: $(cast --to-dec "$nonce")"

echo "MaxPriorityFeePerGas: $(cast --to-unit $maxPriorityFeePerGas gwei)"
echo "MaxFeePerGas: $(cast --to-unit $maxFeePerGas gwei)"
Copy link
Contributor

Choose a reason for hiding this comment

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

To ensure the script's stability and prevent potential issues with globbing and word splitting, it's advisable to double-quote variables in all command substitutions.

- echo "Type: $(cast --to-dec $type)"
- echo "Gas: $(cast --to-dec $gas)"
- echo "Value: $(cast --to-unit $value ether)"
- echo "Nonce: $(cast --to-dec $nonce)"
- echo "MaxPriorityFeePerGas: $(cast --to-unit $maxPriorityFeePerGas gwei)"
- echo "MaxFeePerGas: $(cast --to-unit $maxFeePerGas gwei)"
+ echo "Type: $(cast --to-dec "$type")"
+ echo "Gas: $(cast --to-dec "$gas")"
+ echo "Value: $(cast --to-unit "$value" ether)"
+ echo "Nonce: $(cast --to-dec "$nonce")"
+ echo "MaxPriorityFeePerGas: $(cast --to-unit "$maxPriorityFeePerGas" gwei)"
+ echo "MaxFeePerGas: $(cast --to-unit "$maxFeePerGas" gwei)"

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
echo "Type: $(cast --to-dec $type)" # This specific conversion might not make sense for 'type', as it's not a value field.
echo "Gas: $(cast --to-dec $gas)"
echo "Value: $(cast --to-unit $value ether)"
echo "Nonce: $(cast --to-dec $nonce)"
echo "MaxPriorityFeePerGas: $(cast --to-unit $maxPriorityFeePerGas gwei)"
echo "MaxFeePerGas: $(cast --to-unit $maxFeePerGas gwei)"
echo "Type: $(cast --to-dec "$type")" # This specific conversion might not make sense for 'type', as it's not a value field.
echo "Gas: $(cast --to-dec "$gas")"
echo "Value: $(cast --to-unit "$value" ether)"
echo "Nonce: $(cast --to-dec "$nonce")"
echo "MaxPriorityFeePerGas: $(cast --to-unit "$maxPriorityFeePerGas" gwei)"
echo "MaxFeePerGas: $(cast --to-unit "$maxFeePerGas" gwei)"

Loading