Ejemplo n.º 1
0
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")
}
Ejemplo n.º 2
0
// 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
}