// Populate fills out the details
func (res *TransactionSuccess) Populate(ctx context.Context, result txsub.Result) {
	res.Hash = result.Hash
	res.Ledger = result.LedgerSequence
	res.Env = result.EnvelopeXDR
	res.Result = result.ResultXDR
	res.Meta = result.ResultMetaXDR

	lb := hal.LinkBuilder{httpx.BaseURL(ctx)}
	res.Links.Transaction = lb.Link("/transactions", result.Hash)
	return
}
Beispiel #2
0
func (this *Base) Populate(ctx context.Context, row db.EffectRecord) {
	this.ID = row.ID()
	this.PT = row.PagingToken()
	this.Account = row.Account
	this.populateType(row)

	lb := hal.LinkBuilder{httpx.BaseURL(ctx)}
	this.Links.Operation = lb.Linkf("/operations/%d", row.HistoryOperationID)
	this.Links.Succeeds = lb.Linkf("/effects?order=desc&cursor=%s", this.PT)
	this.Links.Precedes = lb.Linkf("/effects?order=asc&cursor=%s", this.PT)
}
Beispiel #3
0
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
}
Beispiel #4
0
// Populate fills out the details
func (res *Trade) Populate(ctx context.Context, row history.Effect) (err error) {
	if row.Type != history.EffectTrade {
		err = errors.New("invalid effect; not a trade")
		return
	}
	row.UnmarshalDetails(res)
	res.ID = row.PagingToken()
	res.PT = row.PagingToken()
	res.Buyer = row.Account

	lb := hal.LinkBuilder{httpx.BaseURL(ctx)}
	res.Links.Self = lb.Link("/accounts", res.Seller)
	res.Links.Seller = lb.Link("/accounts", res.Seller)
	res.Links.Buyer = lb.Link("/accounts", res.Buyer)
	return
}
Beispiel #5
0
// 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")
}
Beispiel #6
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
}
Beispiel #7
0
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
}
Beispiel #8
0
// 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
}
Beispiel #9
0
func (this *Base) Populate(ctx context.Context, row history.Operation) {
	this.ID = fmt.Sprintf("%d", row.ID)
	this.PT = row.PagingToken()
	this.SourceAccount = row.SourceAccount
	this.populateType(row)

	lb := hal.LinkBuilder{httpx.BaseURL(ctx)}
	self := fmt.Sprintf("/operations/%d", row.ID)
	this.Links.Self = lb.Link(self)
	this.Links.Succeeds = lb.Linkf("/effects?order=desc&cursor=%s", this.PT)
	this.Links.Precedes = lb.Linkf("/effects?order=asc&cursor=%s", this.PT)
	this.Links.Transaction = lb.Linkf("/transactions/%s", row.TransactionHash)
	this.Links.Effects = lb.Link(self, "effects")
}
Beispiel #10
0
// 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")
}
Beispiel #11
0
// 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
}