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

Unable to get a source asset from PathPaymentOperationResponse #125

Closed
parkhomenko opened this issue Aug 14, 2018 · 3 comments
Closed

Unable to get a source asset from PathPaymentOperationResponse #125

parkhomenko opened this issue Aug 14, 2018 · 3 comments

Comments

@parkhomenko
Copy link

It is not possible to retrieve a source asset in the PathPaymentOperationResponse class due to a bug in the code.
Below is the code snippet from that class:

    public Asset getAsset() {
        if (this.assetType.equals("native")) {
            return new AssetTypeNative();
        } else {
            KeyPair issuer = KeyPair.fromAccountId(this.assetIssuer);
            return Asset.createNonNativeAsset(this.assetCode, issuer);
        }
    }

    public Asset getSourceAsset() {
        if (this.sourceAssetCode.equals("native")) {
            return new AssetTypeNative();
        } else {
            KeyPair issuer = KeyPair.fromAccountId(this.sourceAssetIssuer);
            return Asset.createNonNativeAsset(this.sourceAssetCode, issuer);
        }
    }

There are two public methods getAsset() and getSourceAsset() in that class, which serve for getting an asset object. It is impossible to get the last one because of the incorrect if check in it:

if (this.sourceAssetCode.equals("native")) {

It checks for the asset code instead of the type for the source asset.
The code should probably be changed to (the same way as in the getAsset() method):

if (this.sourceAssetType.equals("native")) {
@bartekn
Copy link
Contributor

bartekn commented Aug 14, 2018

Are you sure? Asset.getSourceAsset doesn't check any asset fields.

@parkhomenko
Copy link
Author

Thank you for the reply Bartek, but I didn't get what you mean.

There is a function:

public Asset getSourceAsset() {
        if (this.sourceAssetCode.equals("native")) {
            return new AssetTypeNative();
        } else {
            KeyPair issuer = KeyPair.fromAccountId(this.sourceAssetIssuer);
            return Asset.createNonNativeAsset(this.sourceAssetCode, issuer);
        }
    }

The very first line in it checks wether sourceAssetCode is equals to native, but it should be sourceAssetType instead. Am I wrong?

@bartekn
Copy link
Contributor

bartekn commented Aug 14, 2018

OK, I see it now, thanks!

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