-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledger.go
50 lines (45 loc) · 1.74 KB
/
ledger.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
package resourceadapter
import (
"context"
"fmt"
"github.com/shantanu-hashcash/go/amount"
protocol "github.com/shantanu-hashcash/go/protocols/aurora"
auroraContext "github.com/shantanu-hashcash/go/services/aurora/internal/context"
"github.com/shantanu-hashcash/go/services/aurora/internal/db2/history"
"github.com/shantanu-hashcash/go/support/render/hal"
"github.com/shantanu-hashcash/go/xdr"
)
func PopulateLedger(ctx context.Context, dest *protocol.Ledger, row history.Ledger) {
dest.ID = row.LedgerHash
dest.PT = row.PagingToken()
dest.Hash = row.LedgerHash
dest.PrevHash = row.PreviousLedgerHash.String
dest.Sequence = row.Sequence
// Default to `transaction_count`
dest.SuccessfulTransactionCount = row.TransactionCount
if row.SuccessfulTransactionCount != nil {
dest.SuccessfulTransactionCount = *row.SuccessfulTransactionCount
}
dest.FailedTransactionCount = row.FailedTransactionCount
dest.OperationCount = row.OperationCount
dest.TxSetOperationCount = row.TxSetOperationCount
dest.ClosedAt = row.ClosedAt
dest.TotalCoins = amount.String(xdr.Int64(row.TotalCoins))
dest.FeePool = amount.String(xdr.Int64(row.FeePool))
dest.BaseFee = row.BaseFee
dest.BaseReserve = row.BaseReserve
dest.MaxTxSetSize = row.MaxTxSetSize
dest.ProtocolVersion = row.ProtocolVersion
if row.LedgerHeaderXDR.Valid {
dest.HeaderXDR = row.LedgerHeaderXDR.String
} else {
dest.HeaderXDR = ""
}
self := fmt.Sprintf("/ledgers/%d", row.Sequence)
lb := hal.LinkBuilder{auroraContext.BaseURL(ctx)}
dest.Links.Self = lb.Link(self)
dest.Links.Transactions = lb.PagedLink(self, "transactions")
dest.Links.Operations = lb.PagedLink(self, "operations")
dest.Links.Payments = lb.PagedLink(self, "payments")
dest.Links.Effects = lb.PagedLink(self, "effects")
}