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

Remove KeyPair dependency from requests and responses #231

Merged
merged 2 commits into from
Jul 16, 2019

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented Jul 15, 2019

fixes #230

I took this branch #139 , rebased it on top of master and fixed the conflicts

@tamirms tamirms requested a review from bartekn July 15, 2019 11:59
Copy link
Contributor

@bartekn bartekn left a comment

Choose a reason for hiding this comment

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

Looks good but there are some issues. It seems that we need to lazy initialize EdDSAPublicKeySpec object in KeyPair. This will solve issues connected to Asset* classes that may have invalid issuer.

@@ -42,11 +42,11 @@ public static Asset fromXdr(org.stellar.sdk.xdr.Asset xdr) {
String assetCode4 = Util.paddedByteArrayToString(xdr.getAlphaNum4().getAssetCode().getAssetCode4());
KeyPair issuer4 = KeyPair.fromXdrPublicKey(
xdr.getAlphaNum4().getIssuer().getAccountID());
return new AssetTypeCreditAlphaNum4(assetCode4, issuer4);
return new AssetTypeCreditAlphaNum4(assetCode4, issuer4.getAccountId());
Copy link
Contributor

Choose a reason for hiding this comment

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

The problem here is that xdr.getAlphaNum4().getIssuer().getAccountID() can be invalid pubket and KeyPair.fromXdrPublicKey will try to create EdDSAPublicKeySpec instance throwing an exception.

case ASSET_TYPE_CREDIT_ALPHANUM12:
String assetCode12 = Util.paddedByteArrayToString(xdr.getAlphaNum12().getAssetCode().getAssetCode12());
KeyPair issuer12 = KeyPair.fromXdrPublicKey(xdr.getAlphaNum12().getIssuer().getAccountID());
return new AssetTypeCreditAlphaNum12(assetCode12, issuer12);
return new AssetTypeCreditAlphaNum12(assetCode12, issuer12.getAccountId());
Copy link
Contributor

Choose a reason for hiding this comment

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

The same issue as above.

@@ -36,7 +36,7 @@ public String getType() {
assetCode12.setAssetCode12(Util.paddedByteArray(mCode, 12));
credit.setAssetCode(assetCode12);
AccountID accountID = new AccountID();
accountID.setAccountID(mIssuer.getXdrPublicKey());
accountID.setAccountID(KeyPair.fromAccountId(mIssuer).getXdrPublicKey());
Copy link
Contributor

Choose a reason for hiding this comment

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

This will instantiate EdDSAPublicKeySpec object and throw an exception.

@@ -36,7 +36,7 @@ public String getType() {
assetCode4.setAssetCode4(Util.paddedByteArray(mCode, 4));
credit.setAssetCode(assetCode4);
AccountID accountID = new AccountID();
accountID.setAccountID(mIssuer.getXdrPublicKey());
accountID.setAccountID(KeyPair.fromAccountId(mIssuer).getXdrPublicKey());
Copy link
Contributor

Choose a reason for hiding this comment

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

This will instantiate EdDSAPublicKeySpec object and throw an exception.

public Page<AccountResponse> execute() throws IOException, TooManyRequestsException {
return this.execute(this.httpClient, this.buildUri());
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

@@ -1,7 +1,6 @@
package org.stellar.sdk.responses.operations;

import com.google.gson.annotations.SerializedName;

import org.stellar.sdk.KeyPair;
Copy link
Contributor

@bartekn bartekn Jul 15, 2019

Choose a reason for hiding this comment

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

Maybe we can remove deprecated getSigner and remove this from imports? EDIT. probably not in a scope of this PR.

@@ -3,6 +3,7 @@
import org.junit.Assert;
import org.junit.Test;

import java.security.Key;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably added by accident.

@tamirms
Copy link
Contributor Author

tamirms commented Jul 15, 2019

@bartekn could you take another look? I've pushed a commit which fixes the issues you've raised.

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.

server.payments().execute() throws java.lang.IllegalArgumentException: not a valid GroupElement
2 participants