forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offer.go
41 lines (38 loc) · 1.27 KB
/
offer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package resourceadapter
import (
"context"
"github.com/andskur/go/amount"
. "github.com/andskur/go/protocols/horizon"
"github.com/andskur/go/services/horizon/internal/assets"
"github.com/andskur/go/services/horizon/internal/db2/core"
"github.com/andskur/go/services/horizon/internal/db2/history"
"github.com/andskur/go/services/horizon/internal/httpx"
"github.com/andskur/go/support/render/hal"
)
func PopulateOffer(ctx context.Context, dest *Offer, row core.Offer, ledger *history.Ledger) {
dest.ID = row.OfferID
dest.PT = row.PagingToken()
dest.Seller = row.SellerID
dest.Amount = amount.String(row.Amount)
dest.PriceR.N = row.Pricen
dest.PriceR.D = row.Priced
dest.Price = row.PriceAsString()
dest.Buying = Asset{
Type: assets.MustString(row.BuyingAssetType),
Code: row.BuyingAssetCode.String,
Issuer: row.BuyingIssuer.String,
}
dest.Selling = Asset{
Type: assets.MustString(row.SellingAssetType),
Code: row.SellingAssetCode.String,
Issuer: row.SellingIssuer.String,
}
dest.LastModifiedLedger = row.Lastmodified
if ledger != nil {
dest.LastModifiedTime = &ledger.ClosedAt
}
lb := hal.LinkBuilder{httpx.BaseURL(ctx)}
dest.Links.Self = lb.Linkf("/offers/%d", row.OfferID)
dest.Links.OfferMaker = lb.Linkf("/accounts/%s", row.SellerID)
return
}