Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Fix Issue decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
donovanhide committed Mar 24, 2024
1 parent 68f92ff commit 6816ca3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
5 changes: 2 additions & 3 deletions data/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,9 @@ func readObject(r Reader, v *reflect.Value) error {
s := reflect.ValueOf(&slot)
err := readObject(r, &s)
v.Elem().FieldByName("AuctionSlot").Set(s)
if err == errorEndOfObject {
return nil
if err != errorEndOfObject {
return err
}
return err
case "AuthAccount":
var authAccount AuthAccountItem
aa := reflect.ValueOf(&authAccount)
Expand Down
15 changes: 15 additions & 0 deletions data/issue..go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package data

import "fmt"

type Issue struct {
Currency Currency `json:"currency"`
Issuer Account `json:"issuer,omitempty"`
}

func (i Issue) String() string {
if i.Currency.IsNative() {
return i.Currency.String()
}
return fmt.Sprintf("%s/%s", i.Currency, i.Issuer)
}
4 changes: 2 additions & 2 deletions data/ledgerentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ type AMM struct {
VoteSlots []VoteEntry `json:",omitempty"`
AuctionSlot *AuctionSlot `json:",omitempty"`
LPTokenBalance *Amount `json:",omitempty"`
Asset *Asset `json:",omitempty"`
Asset2 *Asset `json:",omitempty"`
Asset *Issue `json:",omitempty"`
Asset2 *Issue `json:",omitempty"`
OwnerNode *NodeIndex `json:",omitempty"`
}

Expand Down
20 changes: 20 additions & 0 deletions data/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ import (
"math"
)

func (i *Issue) Marshal(w io.Writer) error {
if err := i.Currency.Marshal(w); err != nil {
return err
}
if i.Currency.IsNative() {
return nil
}
return i.Issuer.Marshal(w)
}

func (i *Issue) Unmarshal(r Reader) error {
if err := unmarshalSlice(i.Currency[:], r, "Currency"); err != nil {
return err
}
if i.Currency.IsNative() {
return nil
}
return unmarshalSlice(i.Issuer[:], r, "Issuer")
}

func (v *Value) Unmarshal(r Reader) error {
var u uint64
if err := binary.Read(r, binary.BigEndian, &u); err != nil {
Expand Down

0 comments on commit 6816ca3

Please sign in to comment.