-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
77 lines (70 loc) · 3.6 KB
/
root.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package resourceadapter
import (
"context"
"net/url"
"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/ingest"
"github.com/shantanu-hashcash/go/services/aurora/internal/ledger"
"github.com/shantanu-hashcash/go/support/render/hal"
)
// Populate fills in the details
func PopulateRoot(
ctx context.Context,
dest *aurora.Root,
ledgerState ledger.Status,
hVersion, cVersion string,
passphrase string,
currentProtocolVersion int32,
coreSupportedProtocolVersion int32,
friendBotURL *url.URL,
templates map[string]string,
) {
dest.IngestSequence = ledgerState.ExpHistoryLatest
dest.AuroraSequence = ledgerState.HistoryLatest
dest.AuroraLatestClosedAt = ledgerState.HistoryLatestClosedAt
dest.HistoryElderSequence = ledgerState.HistoryElder
dest.CoreSequence = ledgerState.CoreLatest
dest.AuroraVersion = hVersion
dest.HcnetCoreVersion = cVersion
dest.NetworkPassphrase = passphrase
dest.CurrentProtocolVersion = currentProtocolVersion
dest.SupportedProtocolVersion = ingest.MaxSupportedProtocolVersion
dest.CoreSupportedProtocolVersion = coreSupportedProtocolVersion
lb := hal.LinkBuilder{Base: auroraContext.BaseURL(ctx)}
if friendBotURL != nil {
friendbotLinkBuild := hal.LinkBuilder{Base: friendBotURL}
l := friendbotLinkBuild.Link("{?addr}")
dest.Links.Friendbot = &l
}
dest.Links.Account = lb.Link("/accounts/{account_id}")
dest.Links.AccountTransactions = lb.PagedLink("/accounts/{account_id}/transactions")
dest.Links.Assets = lb.Link("/assets{?asset_code,asset_issuer,cursor,limit,order}")
dest.Links.Effects = lb.Link("/effects{?cursor,limit,order}")
dest.Links.Ledger = lb.Link("/ledgers/{sequence}")
dest.Links.Ledgers = lb.Link("/ledgers{?cursor,limit,order}")
dest.Links.FeeStats = lb.Link("/fee_stats")
dest.Links.Operation = lb.Link("/operations/{id}")
dest.Links.Operations = lb.Link("/operations{?cursor,limit,order,include_failed}")
dest.Links.Payments = lb.Link("/payments{?cursor,limit,order,include_failed}")
dest.Links.TradeAggregations = lb.Link("/trade_aggregations?base_asset_type={base_asset_type}&base_asset_code={base_asset_code}&base_asset_issuer={base_asset_issuer}&counter_asset_type={counter_asset_type}&counter_asset_code={counter_asset_code}&counter_asset_issuer={counter_asset_issuer}")
dest.Links.Trades = lb.Link("/trades?base_asset_type={base_asset_type}&base_asset_code={base_asset_code}&base_asset_issuer={base_asset_issuer}&counter_asset_type={counter_asset_type}&counter_asset_code={counter_asset_code}&counter_asset_issuer={counter_asset_issuer}")
accountsLink := lb.Link(templates["accounts"])
claimableBalancesLink := lb.Link(templates["claimableBalances"])
liquidityPoolsLink := lb.Link(templates["liquidityPools"])
offerLink := lb.Link("/offers/{offer_id}")
offersLink := lb.Link(templates["offers"])
strictReceivePaths := lb.Link(templates["strictReceivePaths"])
strictSendPaths := lb.Link(templates["strictSendPaths"])
dest.Links.Accounts = &accountsLink
dest.Links.ClaimableBalances = &claimableBalancesLink
dest.Links.LiquidityPools = &liquidityPoolsLink
dest.Links.Offer = &offerLink
dest.Links.Offers = &offersLink
dest.Links.StrictReceivePaths = &strictReceivePaths
dest.Links.StrictSendPaths = &strictSendPaths
dest.Links.OrderBook = lb.Link("/order_book{?selling_asset_type,selling_asset_code,selling_asset_issuer,buying_asset_type,buying_asset_code,buying_asset_issuer,limit}")
dest.Links.Self = lb.Link("/")
dest.Links.Transaction = lb.Link("/transactions/{hash}")
dest.Links.Transactions = lb.PagedLink("/transactions")
}