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

Fully parsed tx types #288

Closed
lrettig opened this issue Dec 7, 2023 · 3 comments
Closed

Fully parsed tx types #288

lrettig opened this issue Dec 7, 2023 · 3 comments

Comments

@lrettig
Copy link
Member

lrettig commented Dec 7, 2023

Right now the API only returns parsed "raw" transactions that include the principal, template, and method selector but not the method payload nor the parsed payload (which for a 'Send' tx would include recipient and amount):

// An immutable Spacemesh transaction.
// do not include mutable data such as tx state or result.
message Transaction {
bytes id = 1;
AccountId principal = 2;
AccountId template = 3;
uint32 method = 4; // this is actually limited by uint8, but no type for that.
Nonce nonce = 5;
LayerLimits limits = 6;
uint64 max_gas = 7;
uint64 gas_price = 8;
uint64 max_spend = 9;
bytes raw = 10;
}

This makes reading tx data unnecessarily difficult for clients. Add one or more fully-parsed tx types (for spawn, send, etc.).

@Avionic23
Copy link

Hi, @lrettig. I've been trying to decode the raw transaction with 'go-scale' library into different data structures like Spend, SpendBody, SpendPayload, SpendArguments. Unfortunately , none of those has worked. I'm kindly asking if it's possible to decode address of the receiver from raw transaction. Also, I'd like to know what fields are included in the raw transaction and in which order because I've found several sources with different data structures and I'm not sure which one is correct. Thanks

@lrettig
Copy link
Member Author

lrettig commented Apr 10, 2024

This is being handled in APIv2 now in #319; see the work in progress here: https://github.com/spacemeshos/api/pull/319/files#diff-8ebf744ee0115b17bf0e41111f7f3d9ea7c8b4205532e81f9a3e287e5c3154b9.

@Avionic23 please see https://github.com/spacemeshos/wiki/wiki/Integration-guide#transactions. The authoritative code you're looking for lives in https://github.com/spacemeshos/go-spacemesh/blob/develop/genvm/vm.go. It's definitely possible to parse a raw tx into a tx type and to parse the arguments as you describe; go-spacemesh does exactly this. We don't yet have a clean SDK that makes doing this easy but hopefully we will soon. Let me know if you still have questions.

@lrettig lrettig closed this as completed Apr 10, 2024
@Avionic23
Copy link

Avionic23 commented Apr 12, 2024

Hey, @lrettig. Thank you for your help. I reviewed https://github.com/spacemeshos/go-spacemesh/blob/develop/genvm/vm.go and noticed that the addresses are actually 24 bytes long, but in go-scale they are still 20 bytes long. I assume that's the reason because after replacing [20]byte address to types.Address (which is underlying [24]byte data type) the receiver and amount arguments were successfully parsed.

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

No branches or pull requests

2 participants