Skip to content

Commit

Permalink
fix: canonical NameUpdateTx RLP serialization seems to want NamePoint…
Browse files Browse the repository at this point in the history
…ers in the reverse order than specified in the JSON.
  • Loading branch information
randomshinichi committed Apr 30, 2019
1 parent 4729a9e commit f2bc093
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion aeternity/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ func (t *NameUpdateTx) RLP() (rlpRawMsg []byte, err error) {
return
}

// reverse the NamePointer order as compared to the JSON serialization, because the node seems to want it that way
i := 0
j := len(t.Pointers) - 1
reversedPointers := make([]*NamePointer, len(t.Pointers))
for i <= len(t.Pointers)-1 {
reversedPointers[i] = t.Pointers[j]
i++
j--
}

// create the transaction
rlpRawMsg, err = buildRLPMessage(
ObjectTagNameServiceUpdateTransaction,
Expand All @@ -320,7 +330,7 @@ func (t *NameUpdateTx) RLP() (rlpRawMsg []byte, err error) {
t.Nonce,
nID,
t.NameTTL,
t.Pointers,
reversedPointers,
t.ClientTTL,
t.Fee.Int,
t.TTL)
Expand Down
1 change: 1 addition & 0 deletions aeternity/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func TestNameUpdateTx_RLP(t *testing.T) {
fmt.Println(txJSON)

gotTx, err := BaseEncodeTx(&tx)

if (err != nil) != tt.wantErr {
t.Errorf("NameUpdateTx.RLP() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit f2bc093

Please sign in to comment.