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

Swap and Ics 20 Withdrawal effect hash #9

Merged
merged 7 commits into from
Dec 2, 2024
Merged

Conversation

abenso
Copy link
Collaborator

@abenso abenso commented Nov 29, 2024

Parser and computation of effect hash of Swap and Ics 20 Withdrawal actions

@abenso abenso force-pushed the feat/swap-ics-20-hash branch from de7c1eb to 53b6b39 Compare November 29, 2024 19:39

pub fn to_proto_swap(&self) -> [u8; Self::PROTO_LEN] {
let mut proto = [0u8; Self::PROTO_LEN];
proto[0..4].copy_from_slice(&[0x22, 0x22, 0x0a, 0x20]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

From where that array values come from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These bytes are for protobuf headers. If the .proto file is modified, these bytes may change. We can discuss if there is another way to make this more flexible


pub fn to_proto_swap(&self) -> [u8; Self::PROTO_LEN] {
let mut proto = [0u8; Self::PROTO_LEN];
proto[0..4].copy_from_slice(&[0x0a, 0x22, 0x0a, 0x20]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also define that array as a constant, similarly to Self::PROTO_LEN


pub fn to_bytes(&self) -> Result<[u8; 64], ParserError> {
let mut bytes = [0u8; 64];
let asset_1_bytes = self.asset_1.to_bytes().expect("asset_1 conversion failed");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not use expect or unwraps, however if the code execution path would never fail, unwrap is preferable because it does not have the overhead of a static string in the final binary, also a safety comment explaining a bit why it won't panic

@abenso abenso merged commit 29b468e into dev Dec 2, 2024
44 checks passed
@abenso abenso deleted the feat/swap-ics-20-hash branch December 2, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants