// NewOfferResource converts a CoreOfferRecord into an OfferResource func NewOfferResource(op db.CoreOfferRecord) OfferResource { self := fmt.Sprintf("/offers/%d", op.OfferID) buying := NewOfferAssetResource(op.BuyingAssetType, op.BuyingAssetCode, op.BuyingIssuer) selling := NewOfferAssetResource(op.SellingAssetType, op.SellingAssetCode, op.SellingIssuer) return OfferResource{ Links: halgo.Links{}. Self(self). Link("offer_maker", "/accounts/%s", op.SellerID), ID: op.OfferID, PagingToken: op.PagingToken(), Seller: op.SellerID, Buying: buying, Selling: selling, Amount: AmountToString(op.Amount), PriceR: PriceResource{ N: op.Pricen, D: op.Priced, }, Price: op.PriceAsString(), } }
func (this *Offer) Populate(ctx context.Context, row db.CoreOfferRecord) { this.ID = row.OfferID this.PT = row.PagingToken() this.Seller = row.SellerID this.Amount = amount.String(row.Amount) this.PriceR.N = row.Pricen this.PriceR.D = row.Priced this.Price = row.PriceAsString() this.Buying = Asset{ Type: assets.MustString(row.BuyingAssetType), Code: row.BuyingAssetCode.String, Issuer: row.BuyingIssuer.String, } this.Selling = Asset{ Type: assets.MustString(row.SellingAssetType), Code: row.SellingAssetCode.String, Issuer: row.SellingIssuer.String, } lb := hal.LinkBuilder{httpx.BaseURL(ctx)} this.Links.Self = lb.Linkf("/offers/%d", row.OfferID) this.Links.OfferMaker = lb.Linkf("/accounts/%s", row.SellerID) return }