From 66eccac7a4b3283a8ca3d6188b8007b3ec47844c Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Thu, 23 Apr 2020 17:04:59 +0200 Subject: [PATCH 1/2] protocols/horizon: Display memo_bytes even when memo text is empty --- protocols/horizon/main.go | 8 +++++++- services/horizon/CHANGELOG.md | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/protocols/horizon/main.go b/protocols/horizon/main.go index 1068b4870d..d93ca4d443 100644 --- a/protocols/horizon/main.go +++ b/protocols/horizon/main.go @@ -488,7 +488,8 @@ 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), @@ -496,6 +497,11 @@ func (t Transaction) MarshalJSON() ([]byte, error) { if t.MemoType != "none" { v.Memo = &t.Memo } + + if t.MemoType == "text" { + v.MemoBytes = &t.MemoBytes + } + return json.Marshal(v) } diff --git a/services/horizon/CHANGELOG.md b/services/horizon/CHANGELOG.md index 70d1ff6519..66aead66e5 100644 --- a/services/horizon/CHANGELOG.md +++ b/services/horizon/CHANGELOG.md @@ -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. From 8879fbec558e302bb9ffc2c9e79c42271da7654b Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Thu, 23 Apr 2020 17:09:20 +0200 Subject: [PATCH 2/2] Add test --- protocols/horizon/main_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/protocols/horizon/main_test.go b/protocols/horizon/main_test.go index e0d761dd98..035e723865 100644 --- a/protocols/horizon/main_test.go +++ b/protocols/horizon/main_test.go @@ -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) {