Exemplo n.º 1
0
func NewOfferResource(op db.CoreOfferRecord) OfferResource {
	self := fmt.Sprintf("/offers/%d", op.Offerid)

	takerPays := NewOfferCurrencyResource(op.Paysalphanumcurrency, op.Paysissuer)
	takerGets := NewOfferCurrencyResource(op.Getsalphanumcurrency, op.Getsissuer)

	return OfferResource{
		Links: halgo.Links{}.
			Self(self).
			Link("offer_maker", "/accounts/%s", op.Accountid),
		ID:          op.Offerid,
		PagingToken: op.PagingToken(),
		Account:     op.Accountid,
		TakerPays:   takerPays,
		TakerGets:   takerGets,
		Amount:      op.Amount,
		Price: PriceResource{
			N: op.Pricen,
			D: op.Priced,
		},
		PriceF: op.PriceAsFloat(),
	}
}
Exemplo n.º 2
0
// 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:      op.Amount,
		Price: PriceResource{
			N: op.Pricen,
			D: op.Priced,
		},
		PriceF: op.PriceAsFloat(),
	}
}