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

[Feature Request][Go SDK]Create struct tag from string #76

Closed
dkatzan opened this issue Jul 24, 2024 · 1 comment · Fixed by #137
Closed

[Feature Request][Go SDK]Create struct tag from string #76

dkatzan opened this issue Jul 24, 2024 · 1 comment · Fixed by #137
Labels
enhancement New feature or request

Comments

@dkatzan
Copy link

dkatzan commented Jul 24, 2024

🚀 Feature Request Description

Add support for creating a struct tag from a string

Motivation

There are a few helper functions to create a few basic struct tag, such as
NewStringTag, NewOptionTag, and NewObjectTag

I would like to have a new function, that can parse a string: NewStructTagFromString
that can parse (recursively) and build a struct tag

the motivation is to be able to easily build transfer transactions from the name of a coin

e.g. here is a snippet, of how I implemented a basic function to do so:

	coinTypeStrParts := strings.Split(coinTypeStr, "::")
	accountAddress := aptosSdk.AccountAddress{}
	err := accountAddress.ParseStringRelaxed(coinTypeStrParts[0])
	if err != nil {
		return aptosSdk.TypeTag{}, err
	}
	typedArgument := aptosSdk.TypeTag{
		Value: &aptosSdk.StructTag{
			Address: accountAddress,
			Module:  coinTypeStrParts[1],
			Name:    coinTypeStrParts[2],
		},
	}
	return typedArgument, nil

but this function will fail to build a proper struct tag in a recursive case, e.g. for LP coins like:
0x31a6675cbe84365bf2b0cbce617ece6c47023ef70826533bde5203d32171dc3c::swap::LPToken<0x1::aptos_coin::AptosCoin, 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC>

This function, does exist in the python SDK: https://github.com/aptos-labs/aptos-python-sdk/blob/e5e1ecb0a6bea419a24098f17582798cdfc7be56/aptos_sdk/type_tag.py#L311

and it is parsing the string and building the struct recursively from the string

@dkatzan dkatzan added the enhancement New feature or request label Jul 24, 2024
@dkatzan dkatzan changed the title [Feature Request] <Feature Title> Create struct tag from string Jul 25, 2024
@gregnazario
Copy link
Contributor

Yep, it exists in TypeScript and Python, needs to be migrated over

@gregnazario gregnazario changed the title Create struct tag from string [Feature Request][Go SDK]Create struct tag from string Aug 26, 2024
@gregnazario gregnazario moved this from 🎉 New to 🦆 Todo in Developer Experience Jan 7, 2025
gregnazario added a commit that referenced this issue Mar 13, 2025
Similar to the TypeScript SDK, this ports over the logic
that handles all of the different types into structured types.

Resolves #76
gregnazario added a commit that referenced this issue Mar 13, 2025
Similar to the TypeScript SDK, this ports over the logic
that handles all of the different types into structured types.

Resolves #76
gregnazario added a commit that referenced this issue Mar 17, 2025
Similar to the TypeScript SDK, this ports over the logic
that handles all of the different types into structured types.

Resolves #76
@github-project-automation github-project-automation bot moved this from 🦆 Todo to ✅ Done in Developer Experience Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Status: Backlog
Development

Successfully merging a pull request may close this issue.

2 participants