Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Create decode_tx_input.rs #1054

Merged
merged 3 commits into from
Mar 17, 2022
Merged

Create decode_tx_input.rs #1054

merged 3 commits into from
Mar 17, 2022

Conversation

elyase
Copy link
Contributor

@elyase elyase commented Mar 17, 2022

Motivation

The question comes up often in the Telegram chat

Solution

Provided an example

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

Copy link
Collaborator

@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.

mind trying my suggestion, pretty sure this works

examples/decode_tx_input.rs Outdated Show resolved Hide resolved
let tx_input = "0x38ed173900000000000000000000000000000000000000000001a717cc0a3e4f84c00000000000000000000000000000000000000000000000000000000000000283568400000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000201f129111c60401630932d9f9811bd5b5fff34e000000000000000000000000000000000000000000000000000000006227723d000000000000000000000000000000000000000000000000000000000000000200000000000000000000000095ad61b0a150d79219dcf64e1e6cc01f0b64c4ce000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7";
let calldata = tx_input.strip_prefix("0x").unwrap_or(tx_input);
let calldata = Bytes::from(hex::decode(calldata).unwrap());
let decoded = SwapExactTokensForTokensCall::decode(&calldata)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this makes me think wether we should add a decode_hex function?

cc @gakonst

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah decode_hex(data: &str) which does the conversion internally, is blanked impl'ed on the trait and forwards to decode seems right

@gakonst gakonst merged commit 59e2a30 into gakonst:master Mar 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants