Skip to content

Commit

Permalink
Make offerbase an inline struct and move back original fields to Offe…
Browse files Browse the repository at this point in the history
…r. (#2300)
  • Loading branch information
abuiles authored Feb 20, 2020
1 parent 1a06a6f commit 1fe83eb
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ func (l Ledger) PagingToken() string {
return l.PT
}

// Action needed in release: horizon-v0.25.0: Move back to Offer, remove embedded struct
type offerBase struct {
// Offer is the display form of an offer to trade currency.
type Offer struct {
Links struct {
Self hal.Link `json:"self"`
OfferMaker hal.Link `json:"offer_maker"`
Expand All @@ -248,11 +248,7 @@ type offerBase struct {
Price string `json:"price"`
LastModifiedLedger int32 `json:"last_modified_ledger"`
LastModifiedTime *time.Time `json:"last_modified_time"`
}

// Offer is the display form of an offer to trade currency.
type Offer struct {
offerBase
// Action needed in release: horizon-v0.25.0: Make id a string
ID int64 `json:"id"`
}
Expand All @@ -269,7 +265,26 @@ func (o *Offer) UnmarshalJSON(data []byte) error {
ID json.Number `json:"id"`
}

if err := json.Unmarshal(data, &o.offerBase); err != nil {
// This is a temporary workaround so that we can parse ID as number or
// string and the rest of the fields with their original values
var offerBase struct {
Links struct {
Self hal.Link `json:"self"`
OfferMaker hal.Link `json:"offer_maker"`
} `json:"_links"`

PT string `json:"paging_token"`
Seller string `json:"seller"`
Selling Asset `json:"selling"`
Buying Asset `json:"buying"`
Amount string `json:"amount"`
PriceR Price `json:"price_r"`
Price string `json:"price"`
LastModifiedLedger int32 `json:"last_modified_ledger"`
LastModifiedTime *time.Time `json:"last_modified_time"`
}

if err := json.Unmarshal(data, &offerBase); err != nil {
return err
}

Expand All @@ -282,6 +297,17 @@ func (o *Offer) UnmarshalJSON(data []byte) error {
return err
}

o.Links = offerBase.Links
o.PT = offerBase.PT
o.Seller = offerBase.Seller
o.Selling = offerBase.Selling
o.Buying = offerBase.Buying
o.Amount = offerBase.Amount
o.PriceR = offerBase.PriceR
o.Price = offerBase.Price
o.LastModifiedLedger = offerBase.LastModifiedLedger
o.LastModifiedTime = offerBase.LastModifiedTime

o.ID = offerID

return nil
Expand Down

0 comments on commit 1fe83eb

Please sign in to comment.