-
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
Changes from 2 commits
e7a7e15
4c75bbd
9739b4b
8935a89
26d3977
bc0c06e
4525412
4b57b71
0362c70
39fddb1
ca37d2a
43456de
7547fd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,33 @@ | |
import org.stellar.sdk.xdr.MemoType; | ||
|
||
import java.nio.charset.Charset; | ||
import java.util.Arrays; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Represents MEMO_TEXT. | ||
*/ | ||
public class MemoText extends Memo { | ||
private String text; | ||
private byte[] text; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
|
||
public MemoText(String text) { | ||
this.text = checkNotNull(text, "text cannot be null"); | ||
this(checkNotNull(text, "text cannot be null").getBytes((Charset.forName("UTF-8")))); | ||
} | ||
|
||
int length = text.getBytes((Charset.forName("UTF-8"))).length; | ||
if (length > 28) { | ||
throw new MemoTooLongException("text must be <= 28 bytes. length=" + String.valueOf(length)); | ||
public MemoText(byte[] text) { | ||
this.text = checkNotNull(text, "text cannot be null"); | ||
if (this.text.length > 28) { | ||
throw new MemoTooLongException("text must be <= 28 bytes. length=" + String.valueOf(this.text.length)); | ||
} | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
return new String(text, Charset.forName("UTF-8")); | ||
tamirms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public byte[] getBytes() { | ||
return this.text; | ||
} | ||
|
||
@Override | ||
|
@@ -36,19 +43,19 @@ org.stellar.sdk.xdr.Memo toXdr() { | |
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(this.text); | ||
return Arrays.hashCode(this.text); | ||
} | ||
|
||
@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 Arrays.equals(this.text, memoText.text); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return text == null ? "" : text; | ||
return text == null ? "" : this.getText(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,7 +335,7 @@ union Memo switch (MemoType type) | |
case MEMO_NONE: | ||
void; | ||
case MEMO_TEXT: | ||
string text<28>; | ||
opaque text<28>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do we keep the source of truth for our .x files? Does this get updated there also so that all other SDKs also get updated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they are kept here https://github.com/stellar/stellar-core/tree/master/src/xdr I'm waiting for confirmation in stellar/go#2022 that we're going to change the type of the memo text field. Once we have confirmation we'll need to update the .x files in stellar core and in the go monorepo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Files in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is merged after the changes are in stellar-core master then 👍. |
||
case MEMO_ID: | ||
uint64 id; | ||
case MEMO_HASH: | ||
|
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.
Let's link to the issue (#257) from the changelog