コード例 #1
0
ファイル: resource_operation.go プロジェクト: raymens/horizon
// NewOperationResource initializes a new resource from an OperationRecord
func NewOperationResource(op db.OperationRecord) (OperationResource, error) {
	result, err := op.Details()

	if err != nil {
		return nil, err
	}

	if result == nil {
		result = make(map[string]interface{})
	}

	self := fmt.Sprintf("/operations/%d", op.Id)

	result["_links"] = halgo.Links{}.
		Self(self).
		Link("transaction", "/transactions/%s", op.TransactionHash).
		Link("effects", "%s/effects%s", self, hal.StandardPagingOptions).
		Link("precedes", "/operations?cursor=%s&order=asc", op.PagingToken()).
		Link("succeeds", "/operations?cursor=%s&order=desc", op.PagingToken()).
		Items
	result["id"] = op.Id
	result["source_account"] = op.SourceAccount
	result["paging_token"] = op.PagingToken()
	result["type_i"] = op.Type

	ts, ok := operationResourceTypeNames[op.Type]

	if ok {
		result["type"] = ts
	} else {
		result["type"] = "unknown"
	}

	return result, nil
}
コード例 #2
0
ファイル: base.go プロジェクト: zenododobird/horizon
func (this *Base) Populate(ctx context.Context, row db.OperationRecord) {
	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")
}
コード例 #3
0
ファイル: main.go プロジェクト: zenododobird/horizon
// New creates a new operation resource, finding the appropriate type to use
// based upon the row's type.
func New(
	ctx context.Context,
	row db.OperationRecord,
) (result hal.Pageable, err error) {

	switch row.Type {
	case xdr.OperationTypeCreateAccount:
		e := CreateAccount{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypePayment:
		e := Payment{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypePathPayment:
		e := PathPayment{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypeManageOffer:
		e := ManageOffer{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypeCreatePassiveOffer:
		e := CreatePassiveOffer{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypeSetOptions:
		e := SetOptions{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypeChangeTrust:
		e := ChangeTrust{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypeAllowTrust:
		e := AllowTrust{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypeAccountMerge:
		e := AccountMerge{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	case xdr.OperationTypeInflation:
		e := Inflation{}
		e.Populate(ctx, row)
		err = row.UnmarshalDetails(&e)
		result = e
	default:
		e := Base{}
		e.Populate(ctx, row)
		result = e
	}

	return
}