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

protocols/horizon: Display memo_bytes even when memo text is an empty string #2504

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,20 @@ type InnerTransaction struct {
func (t Transaction) MarshalJSON() ([]byte, error) {
type Alias Transaction
v := &struct {
Memo *string `json:"memo,omitempty"`
Memo *string `json:"memo,omitempty"`
MemoBytes *string `json:"memo_bytes,omitempty"`
*Alias
}{
Alias: (*Alias)(&t),
}
if t.MemoType != "none" {
v.Memo = &t.Memo
}

if t.MemoType == "text" {
v.MemoBytes = &t.MemoBytes
}

return json.Marshal(v)
}

Expand Down
9 changes: 6 additions & 3 deletions protocols/horizon/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ func TestTransactionJSONMarshal(t *testing.T) {

func TestTransactionEmptyMemoText(t *testing.T) {
transaction := Transaction{
MemoType: "text",
Memo: "",
MemoType: "text",
Memo: "",
MemoBytes: "",
}
marshaledTransaction, marshalErr := json.Marshal(transaction)
assert.Nil(t, marshalErr)
var result struct {
Memo *string
Memo *string
MemoBytes *string `json:"memo_bytes"`
}
json.Unmarshal(marshaledTransaction, &result)
assert.NotNil(t, result.Memo, "memo field is present even if input memo was empty string")
assert.NotNil(t, result.MemoBytes, "memo_bytes field is present even if input memo was empty string")
}

func TestTransactionMemoTypeNone(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
However, XDR strings are actually binary blobs with no enforced encoding.
It is possible to set the memo in a transaction envelope to a binary sequence which is not valid ASCII or unicode.
Previously, if you wanted to recover the original binary sequence for a transaction memo, you would have to decode the transaction's envelope.
In this release, we have added a `memo_bytes` field to the Horizon transaction response.
In this release, we have added a `memo_bytes` field to the Horizon transaction response for transactions with `memo_type` equal `text`.
`memo_bytes` stores the base 64 encoding of the memo bytes set in the transaction envelope.


Expand Down