// Populate fills out the details func (res *Transaction) Populate( ctx context.Context, row history.Transaction, ) (err error) { res.ID = row.TransactionHash res.PT = row.PagingToken() res.Hash = row.TransactionHash res.Ledger = row.LedgerSequence res.LedgerCloseTime = row.LedgerCloseTime res.Account = row.Account res.AccountSequence = row.AccountSequence res.FeePaid = row.FeePaid res.OperationCount = row.OperationCount res.EnvelopeXdr = row.TxEnvelope res.ResultXdr = row.TxResult res.ResultMetaXdr = row.TxMeta res.FeeMetaXdr = row.TxFeeMeta res.MemoType = row.MemoType res.Memo = row.Memo.String res.Signatures = strings.Split(row.SignatureString, ",") res.ValidBefore = res.timeString(row.ValidBefore) res.ValidAfter = res.timeString(row.ValidAfter) lb := hal.LinkBuilder{Base: httpx.BaseURL(ctx)} res.Links.Account = lb.Link("/accounts", res.Account) res.Links.Ledger = lb.Link("/ledgers", fmt.Sprintf("%d", res.Ledger)) res.Links.Operations = lb.PagedLink("/transactions", res.ID, "operations") res.Links.Effects = lb.PagedLink("/transactions", res.ID, "effects") res.Links.Self = lb.Link("/transactions", res.ID) res.Links.Succeeds = lb.Linkf("/transactions?order=desc&cursor=%s", res.PT) res.Links.Precedes = lb.Linkf("/transactions?order=asc&cursor=%s", res.PT) return }
// Populate fills out the resource's fields func (this *Account) Populate( ctx context.Context, ca core.Account, cd []core.AccountData, cs []core.Signer, ct []core.Trustline, ha history.Account, ) (err error) { this.ID = ca.Accountid this.PT = ha.PagingToken() this.AccountID = ca.Accountid this.Sequence = ca.Seqnum this.SubentryCount = ca.Numsubentries this.InflationDestination = ca.Inflationdest.String this.HomeDomain = ca.HomeDomain.String this.Flags.Populate(ca) this.Thresholds.Populate(ca) // populate balances this.Balances = make([]Balance, len(ct)+1) for i, tl := range ct { err = this.Balances[i].Populate(ctx, tl) if err != nil { return } } // add native balance err = this.Balances[len(this.Balances)-1].PopulateNative(ca.Balance) if err != nil { return } // populate data this.Data = make(map[string]string) for _, d := range cd { this.Data[d.Key] = d.Value } // populate signers this.Signers = make([]Signer, len(cs)+1) for i, s := range cs { this.Signers[i].Populate(ctx, s) } this.Signers[len(this.Signers)-1].PopulateMaster(ca) lb := hal.LinkBuilder{httpx.BaseURL(ctx)} self := fmt.Sprintf("/accounts/%s", ha.Address) 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") this.Links.Offers = lb.PagedLink(self, "offers") return }
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 }
// Populate fills in the details func (res *Root) Populate(ctx context.Context, row db.LedgerState, hVersion string, cVersion string) { res.HorizonSequence = row.HorizonSequence res.StellarCoreSequence = row.StellarCoreSequence res.HorizonVersion = hVersion res.StellarCoreVersion = cVersion lb := hal.LinkBuilder{httpx.BaseURL(ctx)} res.Links.Account = lb.Link("/accounts/{address}") res.Links.AccountTransactions = lb.PagedLink("/accounts/{address}/transactions") res.Links.Friendbot = lb.Link("/friendbot{?addr}") res.Links.Metrics = lb.Link("/metrics") res.Links.OrderBook = lb.Link("/order_book{?selling_asset_type,selling_asset_code,selling_issuer,buying_asset_type,buying_asset_code,buying_issuer}") res.Links.Self = lb.Link("/") res.Links.Transaction = lb.Link("/transactions/{hash}") res.Links.Transactions = lb.PagedLink("/transactions") }
func (this *Account) Populate(ctx context.Context, row db.AccountRecord) (err error) { this.ID = row.Accountid this.PT = row.PagingToken() this.Address = row.Accountid this.Sequence = row.Seqnum this.SubentryCount = row.Numsubentries this.InflationDestination = row.Inflationdest.String this.HomeDomain = row.HomeDomain.String this.Flags.Populate(ctx, row) this.Thresholds.Populate(ctx, row) // populate balances this.Balances = make([]Balance, len(row.Trustlines)+1) for i, tl := range row.Trustlines { err = this.Balances[i].Populate(ctx, tl) if err != nil { return } } // add native balance err = this.Balances[len(this.Balances)-1].PopulateNative(row.Balance) if err != nil { return } // populate signers this.Signers = make([]Signer, len(row.Signers)+1) for i, s := range row.Signers { this.Signers[i].Populate(ctx, s) } this.Signers[len(this.Signers)-1].PopulateMaster(row) lb := hal.LinkBuilder{httpx.BaseURL(ctx)} self := fmt.Sprintf("/accounts/%s", row.Address) 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") this.Links.Offers = lb.PagedLink(self, "Offers") return }
// Populate fills in the details func (res *Root) Populate(ctx context.Context, hSeq, cSeq int32, hVersion, cVersion string, passphrase string) { res.HorizonSequence = hSeq res.StellarCoreSequence = cSeq res.HorizonVersion = hVersion res.StellarCoreVersion = cVersion res.NetworkPassphrase = passphrase lb := hal.LinkBuilder{httpx.BaseURL(ctx)} res.Links.Account = lb.Link("/accounts/{account_id}") res.Links.AccountTransactions = lb.PagedLink("/accounts/{account_id}/transactions") res.Links.Friendbot = lb.Link("/friendbot{?addr}") res.Links.Metrics = lb.Link("/metrics") res.Links.OrderBook = lb.Link("/order_book{?selling_asset_type,selling_asset_code,selling_issuer,buying_asset_type,buying_asset_code,buying_issuer}") res.Links.Self = lb.Link("/") res.Links.Transaction = lb.Link("/transactions/{hash}") res.Links.Transactions = lb.PagedLink("/transactions") }