forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
executable file
·60 lines (52 loc) · 1.85 KB
/
transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package resourceadapter
import (
"context"
"fmt"
"strings"
"time"
"github.com/guregu/null"
"github.com/fonero-project/fonero-golang/services/horizon/internal/db2/history"
"github.com/fonero-project/fonero-golang/services/horizon/internal/httpx"
. "github.com/fonero-project/fonero-golang/protocols/horizon"
"github.com/fonero-project/fonero-golang/support/render/hal"
)
// Populate fills out the details
func PopulateTransaction(
ctx context.Context,
dest *Transaction,
row history.Transaction,
) (err error) {
dest.ID = row.TransactionHash
dest.PT = row.PagingToken()
dest.Hash = row.TransactionHash
dest.Ledger = row.LedgerSequence
dest.LedgerCloseTime = row.LedgerCloseTime
dest.Account = row.Account
dest.AccountSequence = row.AccountSequence
dest.FeePaid = row.FeePaid
dest.OperationCount = row.OperationCount
dest.EnvelopeXdr = row.TxEnvelope
dest.ResultXdr = row.TxResult
dest.ResultMetaXdr = row.TxMeta
dest.FeeMetaXdr = row.TxFeeMeta
dest.MemoType = row.MemoType
dest.Memo = row.Memo.String
dest.Signatures = strings.Split(row.SignatureString, ",")
dest.ValidBefore = timeString(dest, row.ValidBefore)
dest.ValidAfter = timeString(dest, row.ValidAfter)
lb := hal.LinkBuilder{Base: httpx.BaseURL(ctx)}
dest.Links.Account = lb.Link("/accounts", dest.Account)
dest.Links.Ledger = lb.Link("/ledgers", fmt.Sprintf("%d", dest.Ledger))
dest.Links.Operations = lb.PagedLink("/transactions", dest.ID, "operations")
dest.Links.Effects = lb.PagedLink("/transactions", dest.ID, "effects")
dest.Links.Self = lb.Link("/transactions", dest.ID)
dest.Links.Succeeds = lb.Linkf("/transactions?order=desc&cursor=%s", dest.PT)
dest.Links.Precedes = lb.Linkf("/transactions?order=asc&cursor=%s", dest.PT)
return
}
func timeString(res *Transaction, in null.Int) string {
if !in.Valid {
return ""
}
return time.Unix(in.Int64, 0).UTC().Format(time.RFC3339)
}