Пример #1
0
func (this *Ledger) Populate(ctx context.Context, row db.LedgerRecord) {
	this.ID = row.LedgerHash
	this.PT = row.PagingToken()
	this.Hash = row.LedgerHash
	this.PrevHash = row.PreviousLedgerHash.String
	this.Sequence = row.Sequence
	this.TransactionCount = row.TransactionCount
	this.OperationCount = row.OperationCount
	this.ClosedAt = row.ClosedAt
	this.TotalCoins = amount.String(xdr.Int64(row.TotalCoins))
	this.FeePool = amount.String(xdr.Int64(row.FeePool))
	this.BaseFee = row.BaseFee
	this.BaseReserve = amount.String(xdr.Int64(row.BaseReserve))
	this.MaxTxSetSize = row.MaxTxSetSize

	self := fmt.Sprintf("/ledgers/%d", row.Sequence)
	lb := hal.LinkBuilder{httpx.BaseURL(ctx)}
	this.Links.Self = lb.Link(self)
	this.Links.Transactions = lb.PagedLink(self, "transactions")
	this.Links.Operations = lb.PagedLink(self, "operations")
	this.Links.Payments = lb.PagedLink(self, "payments")
	this.Links.Effects = lb.PagedLink(self, "effects")

	return
}
Пример #2
0
// NewLedgerResource creates a new resource from a db.LedgerRecord
func NewLedgerResource(in db.LedgerRecord) LedgerResource {
	self := fmt.Sprintf("/ledgers/%d", in.Sequence)
	return LedgerResource{
		Links: halgo.Links{}.
			Self(self).
			Link("transactions", "%s/transactions%s", self, hal.StandardPagingOptions).
			Link("operations", "%s/operations%s", self, hal.StandardPagingOptions).
			Link("effects", "%s/effects%s", self, hal.StandardPagingOptions),
		ID:               in.LedgerHash,
		PagingToken:      in.PagingToken(),
		Hash:             in.LedgerHash,
		PrevHash:         in.PreviousLedgerHash.String,
		Sequence:         in.Sequence,
		TransactionCount: in.TransactionCount,
		OperationCount:   in.OperationCount,
		ClosedAt:         in.ClosedAt,
	}
}