コード例 #1
0
ファイル: trade.go プロジェクト: irisli/horizon
// 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
}
コード例 #2
0
ファイル: main.go プロジェクト: irisli/horizon
func New(
	ctx context.Context,
	row history.Effect,
) (result hal.Pageable, err error) {

	base := Base{}
	base.Populate(ctx, row)

	switch row.Type {
	case history.EffectAccountCreated:
		e := AccountCreated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectAccountCredited:
		e := AccountCredited{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectAccountDebited:
		e := AccountDebited{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectAccountThresholdsUpdated:
		e := AccountThresholdsUpdated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectAccountHomeDomainUpdated:
		e := AccountHomeDomainUpdated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectAccountFlagsUpdated:
		e := AccountFlagsUpdated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectSignerCreated:
		e := SignerCreated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectSignerUpdated:
		e := SignerUpdated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectSignerRemoved:
		e := SignerRemoved{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectTrustlineCreated:
		e := TrustlineCreated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectTrustlineUpdated:
		e := TrustlineUpdated{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectTrustlineRemoved:
		e := TrustlineRemoved{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectTrustlineAuthorized:
		e := TrustlineAuthorized{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectTrustlineDeauthorized:
		e := TrustlineDeauthorized{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	case history.EffectTrade:
		e := Trade{Base: base}
		err = row.UnmarshalDetails(&e)
		result = e
	default:
		result = base
	}

	return
}