// Populate loads this resource from `row` func (this *Base) Populate(ctx context.Context, row history.Effect) { 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) }
// 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 }
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 }