-
Notifications
You must be signed in to change notification settings - Fork 159
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
Conversation
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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()); | ||
} | ||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably added by accident.
@bartekn could you take another look? I've pushed a commit which fixes the issues you've raised. |
fixes #230
I took this branch #139 , rebased it on top of master and fixed the conflicts