本文整理汇总了Golang中github.com/stellar/go-stellar-base/xdr.Asset类的典型用法代码示例。如果您正苦于以下问题:Golang Asset类的具体用法?Golang Asset怎么用?Golang Asset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Asset类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetOrderBookSummary
// GetOrderBookSummary loads a summary of an order book identified by a
// selling/buying pair. It is designed to drive an order book summary client
// interface (bid/ask spread, prices and volume, etc).
func (q *Q) GetOrderBookSummary(dest interface{}, selling xdr.Asset, buying xdr.Asset) error {
var sql bytes.Buffer
var oq orderbookQueryBuilder
err := selling.Extract(&oq.SellingType, &oq.SellingCode, &oq.SellingIssuer)
if err != nil {
return err
}
err = buying.Extract(&oq.BuyingType, &oq.BuyingCode, &oq.BuyingIssuer)
if err != nil {
return err
}
oq.pushArg(20)
err = orderbookQueryTemplate.Execute(&sql, &oq)
if err != nil {
return errors.Wrap(err, 1)
}
err = q.SelectRaw(dest, sql.String(), oq.args...)
if err != nil {
return errors.Wrap(err, 1)
}
return nil
}
开发者ID:irisli,项目名称:horizon,代码行数:29,代码来源:order_book_summary.go
示例2: ConnectedAssets
// ConnectedAssets loads xdr.Asset records for the purposes of path
// finding. Given the input asset type, a list of xdr.Assets is returned that
// each have some available trades for the input asset.
func (q *Q) ConnectedAssets(dest interface{}, selling xdr.Asset) error {
assets, ok := dest.(*[]xdr.Asset)
if !ok {
return errors.New("dest is not *[]xdr.Asset")
}
var (
t xdr.AssetType
c string
i string
)
err := selling.Extract(&t, &c, &i)
if err != nil {
return err
}
sql := sq.Select(
"buyingassettype AS type",
"coalesce(buyingassetcode, '') AS code",
"coalesce(buyingissuer, '') AS issuer").
From("offers").
Where(sq.Eq{"sellingassettype": t}).
GroupBy("buyingassettype", "buyingassetcode", "buyingissuer")
if t != xdr.AssetTypeAssetTypeNative {
sql = sql.Where(sq.Eq{"sellingassetcode": c, "sellingissuer": i})
}
var rows []struct {
Type xdr.AssetType
Code string
Issuer string
}
err = q.Select(&rows, sql)
if err != nil {
return err
}
results := make([]xdr.Asset, len(rows))
*assets = results
for i, r := range rows {
results[i], err = AssetFromDB(r.Type, r.Code, r.Issuer)
if err != nil {
return err
}
}
return nil
}
开发者ID:irisli,项目名称:horizon,代码行数:57,代码来源:offer.go
示例3: Equals
// Equals returns true if l and r are equivalent.
func Equals(l, r xdr.Asset) bool {
var le, re struct {
T xdr.AssetType
C string
I string
}
err := l.Extract(&le.T, &le.C, &le.I)
if err != nil {
panic(err)
}
err = r.Extract(&re.T, &re.C, &re.I)
if err != nil {
panic(err)
}
return le == re
}
开发者ID:zenododobird,项目名称:horizon,代码行数:20,代码来源:main.go
示例4: assetDetails
// assetDetails sets the details for `a` on `result` using keys with `prefix`
func (is *Session) assetDetails(result map[string]interface{}, a xdr.Asset, prefix string) error {
var (
t string
code string
i string
)
err := a.Extract(&t, &code, &i)
if err != nil {
return err
}
result[prefix+"asset_type"] = t
if a.Type == xdr.AssetTypeAssetTypeNative {
return nil
}
result[prefix+"asset_code"] = code
result[prefix+"asset_issuer"] = i
return nil
}
开发者ID:FihlaTV,项目名称:horizon,代码行数:21,代码来源:session.go
示例5: orderBookFilter
// OfType filters the query to only effects of the given type.
func (q *EffectsQ) orderBookFilter(a xdr.Asset, prefix string) {
var typ, code, iss string
q.Err = a.Extract(&typ, &code, &iss)
if q.Err != nil {
return
}
if a.Type == xdr.AssetTypeAssetTypeNative {
clause := fmt.Sprintf(`
(heff.details->>'%sasset_type' = ?
AND heff.details ?? '%sasset_code' = false
AND heff.details ?? '%sasset_issuer' = false)`, prefix, prefix, prefix)
q.sql = q.sql.Where(clause, typ)
return
}
clause := fmt.Sprintf(`
(heff.details->>'%sasset_type' = ?
AND heff.details->>'%sasset_code' = ?
AND heff.details->>'%sasset_issuer' = ?)`, prefix, prefix, prefix)
q.sql = q.sql.Where(clause, typ, code, iss)
}
开发者ID:irisli,项目名称:horizon,代码行数:23,代码来源:effect.go
示例6: Populate
func (this *Asset) Populate(ctx context.Context, asset xdr.Asset) error {
return asset.Extract(&this.Type, &this.Code, &this.Issuer)
}
开发者ID:FihlaTV,项目名称:horizon,代码行数:3,代码来源:asset.go
示例7:
})
It("passes a sanity test", func() {
before, err := createAccount.StateBefore(masterAccount.LedgerKey(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(before).ToNot(BeNil())
after, err := createAccount.StateAfter(masterAccount.LedgerKey(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(after).ToNot(BeNil())
Expect(before.Data.MustAccount().Balance).To(BeNumerically(">", after.Data.MustAccount().Balance))
})
})
Context("Trustlines", func() {
var tlkey xdr.LedgerKey
var line xdr.Asset
BeforeEach(func() {
line.SetCredit("USD", gatewayAccount)
tlkey.SetTrustline(newAccount, line)
})
It("properly returns the state of a trustlines that gets removed", func() {
before, err := removeTrustline.StateBefore(tlkey, 0)
Expect(err).ToNot(HaveOccurred())
Expect(before).ToNot(BeNil())
tl := before.Data.MustTrustLine()
Expect(tl.Limit).To(Equal(xdr.Int64(40000000000)))
})
It("properly returns the state of a trustlines that gets removed", func() {
开发者ID:stellar,项目名称:bridge-server,代码行数:31,代码来源:bundle_test.go
注:本文中的github.com/stellar/go-stellar-base/xdr.Asset类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论