diff --git a/data/decoder.go b/data/decoder.go index 5c933c9..f6bd941 100644 --- a/data/decoder.go +++ b/data/decoder.go @@ -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) diff --git a/data/issue..go b/data/issue..go new file mode 100644 index 0000000..aa3cfec --- /dev/null +++ b/data/issue..go @@ -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) +} diff --git a/data/ledgerentry.go b/data/ledgerentry.go index 3c0d1cd..774ba11 100644 --- a/data/ledgerentry.go +++ b/data/ledgerentry.go @@ -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"` } diff --git a/data/wire.go b/data/wire.go index b1df792..ea9eed0 100644 --- a/data/wire.go +++ b/data/wire.go @@ -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 {