-
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
Use bytes to represent memo text #259
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e7a7e15
Use bytes to represent memo text
tamirms 4c75bbd
Update changelog and bump version.
tamirms 9739b4b
Update src/main/java/org/stellar/sdk/MemoText.java
tamirms 8935a89
include link to github issue
tamirms 26d3977
Remove comment
tamirms bc0c06e
Regenerate code using xdrgen with fix
tamirms 4525412
Use updated version of xdrgen
tamirms 4b57b71
Use XdrString class
tamirms 0362c70
Use XdrString in MemoText
tamirms 39fddb1
Use newest xdrgen
tamirms ca37d2a
Check string lengths in ManageDataOperation and SetOptionsOperation
tamirms 43456de
Update changelog
tamirms 7547fd8
fix null pointer exception
tamirms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,63 @@ | ||
package org.stellar.sdk; | ||
|
||
import com.google.common.base.Objects; | ||
import org.stellar.sdk.xdr.MemoType; | ||
|
||
import java.nio.charset.Charset; | ||
import org.stellar.sdk.xdr.XdrString; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Represents MEMO_TEXT. | ||
*/ | ||
public class MemoText extends Memo { | ||
private String text; | ||
private XdrString text; | ||
|
||
public MemoText(String text) { | ||
this.text = checkNotNull(text, "text cannot be null"); | ||
this(new XdrString(checkNotNull(text, "text cannot be null"))); | ||
} | ||
|
||
public MemoText(byte[] text) { | ||
this(new XdrString(checkNotNull(text, "text cannot be null"))); | ||
} | ||
|
||
int length = text.getBytes((Charset.forName("UTF-8"))).length; | ||
public MemoText(XdrString text) { | ||
this.text = checkNotNull(text, "text cannot be null"); | ||
int length = this.text.getBytes().length; | ||
if (length > 28) { | ||
throw new MemoTooLongException("text must be <= 28 bytes. length=" + String.valueOf(length)); | ||
} | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
return this.text.toString(); | ||
} | ||
|
||
public byte[] getBytes() { | ||
return this.text.getBytes(); | ||
} | ||
|
||
@Override | ||
org.stellar.sdk.xdr.Memo toXdr() { | ||
org.stellar.sdk.xdr.Memo memo = new org.stellar.sdk.xdr.Memo(); | ||
memo.setDiscriminant(MemoType.MEMO_TEXT); | ||
memo.setText(text); | ||
memo.setText(this.text); | ||
return memo; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(this.text); | ||
return this.text.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MemoText memoText = (MemoText) o; | ||
return Objects.equal(this.text, memoText.text); | ||
return this.text.equals(memoText.text); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return text == null ? "" : text; | ||
return text == null ? "" : this.getText(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 change seems to be unrelated to the rest of this change. The rest of this change is specifically about memo text, but this change is to do with manage data operations. It seems out of scope and like it belongs in a separate PR.
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.
if I separated this change in a new PR it would depend on this branch because it requires
XdrString
. Lets keep both changes in the same PR for now. It shouldn't be too burdensome to review the extra changes