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

#396: streamlined Asset creation to be consistent for all asset types #398

Merged

Conversation

sreuland
Copy link
Contributor

@sreuland sreuland commented Jan 6, 2022

checked for Asset representation(native, alpha4, alpha12, pool share) consistency for any API operation/effect resource that may have possibility of holding an Asset resource which refers to liquidity pool shares via liquidity_pool_id and does not contain the usual non-native alpha4 or alpha12 attributes of asset_code and asset_issuer, these are the resources identified:

TrustlineCreatedEffectReponse TrustlineUpdatedEffectResponse TrustlineRemovedEffectResponse ChangeTrustOperationResponse

I refactored the Asset class to provide a bit more asset-type agnostic factory methods for generating Assets which derive the type(i.e. class model), so callers do not need to have same know-how.

closes #396

…r all asset types(native, alpha4, alpha12, pool share). Fixed TrustlineCreatedEffectReponse marshaling to work when asset is of pool share type.
@sreuland
Copy link
Contributor Author

sreuland commented Jan 6, 2022

@tamirms , this could wait, can go in after #397 is done

@sreuland sreuland requested a review from a team January 6, 2022 21:39
* @return Asset
*/
public static Asset create(String type, String code, String issuer, String liquidityPoolID) {
if (type == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the rationale for changing the behavior of type to allow null values?

previously: type the type of asset can be 'native', 'alpha4', 'alpha12' or 'liquidity_pool_shares'

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the alpha4, alpha12 type values were/are ignored, rather the asset code is introspected to determine the Asset class type, only type values of 'native' and 'liquidity_pool_shares' have effect on derived Asset class, otherwise, clients don't need to pass a specific 'alpha4, alpha12' type, for backwards compat, it's fine, if it's one of those values or null will result in the same introspection of asset code to determine Asset class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

trying to stay with existing static factory method pattern, but one other creational pattern to consider, but thought it might be too much breaking change, is to remove the create methods, and replace with builder pattern, such as:
Asset.newBuilder().withCode().withIssuer().withLiquidityPoolId().create()

if you don't include any withXyz() then by default the builder creates a native.

@sreuland sreuland merged commit 312092d into lightsail-network:master Jan 10, 2022
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.

Call getAsset from TrustlineCreatedEffectResponse class
2 participants