Skip to content

Commit 39fdbf4

Browse files
committed
mark internal types as private
1 parent 9ac5f91 commit 39fdbf4

File tree

1 file changed

+62
-68
lines changed

1 file changed

+62
-68
lines changed

internal/xrp/xrp.go

Lines changed: 62 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import (
1717
"github.com/pkg/errors"
1818
)
1919

20-
const XRPCurrency = "XRP"
21-
const XRPTimeToUTD = uint64(946684800)
20+
const (
21+
xrpCurrency = "XRP"
22+
XRPTimeToUTD = uint64(946684800)
23+
)
2224

2325
type Config struct {
2426
Url string `toml:"url"`
@@ -29,118 +31,110 @@ func New(cfg *Config) (indexer.BlockchainClient[Block, Transaction], error) {
2931
return nil, errors.New("url must be provided")
3032
}
3133

32-
xrpClient := XRPClient{
33-
Client: http.DefaultClient,
34-
Url: cfg.Url}
34+
xrpClient := xrpClient{
35+
client: http.DefaultClient,
36+
url: cfg.Url,
37+
}
3538

3639
return xrpClient, nil
3740
}
3841

39-
type XRPClient struct {
40-
Client *http.Client
41-
Url string
42-
Headers http.Header
42+
type xrpClient struct {
43+
client *http.Client
44+
url string
4345
}
4446

45-
type XRPRequest struct {
47+
type xrpRequest struct {
4648
Method string `json:"method"`
4749
Params []interface{} `json:"params"`
4850
}
4951

50-
type LedgerParams struct {
52+
type ledgerParams struct {
5153
LedgerIndex string `json:"ledger_index"`
5254
Transactions bool `json:"transactions"`
5355
Expand bool `json:"expand"`
5456
OwnerFunds bool `json:"owner_funds"`
5557
}
5658

57-
type LedgerResponse struct {
58-
Result LedgerResult `json:"result"`
59+
type ledgerResponse struct {
60+
Result ledgerResult `json:"result"`
5961
}
6062

61-
type LedgerResult struct {
63+
type ledgerResult struct {
6264
LedgerIndex uint64 `json:"ledger_index"`
6365
LedgerHash string `json:"ledger_hash"`
6466
Validated bool `json:"validated"`
65-
Ledger XRPLedger `json:"ledger"`
67+
Ledger xrpLedger `json:"ledger"`
6668
}
6769

68-
type XRPLedger struct {
70+
type xrpLedger struct {
6971
CloseTime uint64 `json:"close_time"`
7072
Transactions []json.RawMessage
7173
}
7274

73-
type XRPTransaction struct {
75+
type xrpTransaction struct {
7476
Hash string `json:"hash"`
7577
Memos []map[string]map[string]string `json:"Memos"`
7678
TransactionType string `json:"TransactionType"`
7779
Amount json.RawMessage `json:"Amount"`
7880
MetaData json.RawMessage `json:"metaData"`
7981
}
8082

81-
type XRPAmount struct {
83+
type xrpAmount struct {
8284
Currency string `json:"currency"`
8385
}
8486

85-
type XRPMeta struct {
86-
AffectedNodes []XRPAffectedNodes `json:"AffectedNodes"`
87+
type xrpMeta struct {
88+
AffectedNodes []xrpAffectedNodes `json:"AffectedNodes"`
8789
}
8890

89-
type XRPAffectedNodes struct {
90-
XRPModifiedNode XRPModifiedNode `json:"ModifiedNode"`
91+
type xrpAffectedNodes struct {
92+
ModifiedNode xrpModifiedNode `json:"ModifiedNode"`
9193
}
9294

93-
type XRPModifiedNode struct {
94-
FinalFields XRPFields `json:"FinalFields"`
95-
PreviousFields XRPFields `json:"PreviousFields"`
95+
type xrpModifiedNode struct {
96+
FinalFields xrpFields `json:"FinalFields"`
97+
PreviousFields xrpFields `json:"PreviousFields"`
9698
LedgerEntryType string `json:"LedgerEntryType"`
9799
}
98100

99-
type XRPFields struct {
101+
type xrpFields struct {
100102
Account string `json:"Account"`
101103
Balance json.RawMessage `json:"Balance"`
102104
}
103105

104-
type ServerInfoRequest struct {
105-
Method string `json:"method"`
106+
type serverInfoResponse struct {
107+
Result serverInfoResult `json:"result"`
106108
}
107109

108-
type ServerInfoResponse struct {
109-
Result ServerInfoResult `json:"result"`
110+
type serverInfoResult struct {
111+
Info serverInfo `json:"info"`
110112
}
111113

112-
type ServerInfoResult struct {
113-
Info ServerInfo `json:"info"`
114-
}
115-
116-
type ServerInfo struct {
114+
type serverInfo struct {
117115
BuildVersion string `json:"build_version"`
118116
ServerState string `json:"server_state"`
119117
}
120118

121-
var getLatestParams LedgerParams
122-
var getServerState XRPRequest
119+
var getLatestParams = ledgerParams{
120+
LedgerIndex: "validated",
121+
Transactions: false,
122+
Expand: false,
123+
OwnerFunds: false,
124+
}
123125

124-
func init() {
125-
getLatestParams = LedgerParams{
126-
LedgerIndex: "validated",
127-
Transactions: false,
128-
Expand: false,
129-
OwnerFunds: false,
130-
}
131-
getServerState = XRPRequest{
132-
Method: "server_info",
133-
}
126+
var getServerState = xrpRequest{
127+
Method: "server_info",
134128
}
135129

136-
func (c XRPClient) GetResponse(ctx context.Context, request XRPRequest) ([]byte, error) {
130+
func (c xrpClient) GetResponse(ctx context.Context, request xrpRequest) ([]byte, error) {
137131
getReq, err := json.Marshal(request)
138132
if err != nil {
139133
return nil, err
140134
}
141135

142136
buf := bytes.NewBuffer(getReq)
143-
req, err := http.NewRequest("POST", c.Url, buf)
137+
req, err := http.NewRequest("POST", c.url, buf)
144138
if err != nil {
145139
return nil, err
146140
}
@@ -149,7 +143,7 @@ func (c XRPClient) GetResponse(ctx context.Context, request XRPRequest) ([]byte,
149143
req.Header.Set("content-type", "application/json")
150144
req = req.WithContext(ctx)
151145

152-
resp, err := c.Client.Do(req)
146+
resp, err := c.client.Do(req)
153147
if err != nil {
154148
return nil, err
155149
}
@@ -165,8 +159,8 @@ func (c XRPClient) GetResponse(ctx context.Context, request XRPRequest) ([]byte,
165159
return resBody, nil
166160
}
167161

168-
func (c XRPClient) GetLedgerResponse(ctx context.Context, params LedgerParams) (*LedgerResponse, error) {
169-
request := XRPRequest{
162+
func (c xrpClient) GetLedgerResponse(ctx context.Context, params ledgerParams) (*ledgerResponse, error) {
163+
request := xrpRequest{
170164
Method: "ledger",
171165
Params: []interface{}{params},
172166
}
@@ -176,7 +170,7 @@ func (c XRPClient) GetLedgerResponse(ctx context.Context, params LedgerParams) (
176170
return nil, err
177171
}
178172

179-
var respStruct LedgerResponse
173+
var respStruct ledgerResponse
180174
err = json.Unmarshal(resBody, &respStruct)
181175
if err != nil {
182176
return nil, err
@@ -185,7 +179,7 @@ func (c XRPClient) GetLedgerResponse(ctx context.Context, params LedgerParams) (
185179
return &respStruct, nil
186180
}
187181

188-
func (c XRPClient) GetLatestBlockInfo(ctx context.Context) (*indexer.BlockInfo, error) {
182+
func (c xrpClient) GetLatestBlockInfo(ctx context.Context) (*indexer.BlockInfo, error) {
189183
respStruct, err := c.GetLedgerResponse(ctx, getLatestParams)
190184
if err != nil {
191185
return nil, err
@@ -197,8 +191,8 @@ func (c XRPClient) GetLatestBlockInfo(ctx context.Context) (*indexer.BlockInfo,
197191
}, nil
198192
}
199193

200-
func (c XRPClient) GetBlockTimestamp(ctx context.Context, blockNum uint64) (uint64, error) {
201-
getBlockParams := LedgerParams{
194+
func (c xrpClient) GetBlockTimestamp(ctx context.Context, blockNum uint64) (uint64, error) {
195+
getBlockParams := ledgerParams{
202196
LedgerIndex: strconv.Itoa(int(blockNum)),
203197
Transactions: false,
204198
Expand: false,
@@ -212,9 +206,9 @@ func (c XRPClient) GetBlockTimestamp(ctx context.Context, blockNum uint64) (uint
212206
return respStruct.Result.Ledger.CloseTime + XRPTimeToUTD, nil
213207
}
214208

215-
func (c XRPClient) GetBlockResult(ctx context.Context, blockNum uint64,
209+
func (c xrpClient) GetBlockResult(ctx context.Context, blockNum uint64,
216210
) (*indexer.BlockResult[Block, Transaction], error) {
217-
getBlockParams := LedgerParams{
211+
getBlockParams := ledgerParams{
218212
LedgerIndex: strconv.Itoa(int(blockNum)),
219213
Transactions: true,
220214
Expand: true,
@@ -237,7 +231,7 @@ func (c XRPClient) GetBlockResult(ctx context.Context, blockNum uint64,
237231

238232
transactions := make([]Transaction, len(respStruct.Result.Ledger.Transactions))
239233
for i := range transactions {
240-
var tx XRPTransaction
234+
var tx xrpTransaction
241235
err = json.Unmarshal([]byte(respStruct.Result.Ledger.Transactions[i]), &tx)
242236
if err != nil {
243237
return nil, err
@@ -261,7 +255,7 @@ func (c XRPClient) GetBlockResult(ctx context.Context, blockNum uint64,
261255
return &indexer.BlockResult[Block, Transaction]{Block: block, Transactions: transactions}, nil
262256
}
263257

264-
func paymentReference(tx XRPTransaction) string {
258+
func paymentReference(tx xrpTransaction) string {
265259
if len(tx.Memos) == 1 {
266260
if memo, ok := tx.Memos[0]["Memo"]; ok {
267261
if memoData, ok := memo["MemoData"]; ok {
@@ -275,7 +269,7 @@ func paymentReference(tx XRPTransaction) string {
275269
return ""
276270
}
277271

278-
func isNativePayment(tx XRPTransaction) bool {
272+
func isNativePayment(tx xrpTransaction) bool {
279273
if tx.TransactionType == "Payment" {
280274
var amountStr string
281275
err := json.Unmarshal(tx.Amount, &amountStr)
@@ -285,18 +279,18 @@ func isNativePayment(tx XRPTransaction) bool {
285279
return true
286280
}
287281
}
288-
var amountStruct XRPAmount
282+
var amountStruct xrpAmount
289283
err = json.Unmarshal(tx.Amount, &amountStruct)
290-
if err == nil && amountStruct.Currency == XRPCurrency {
284+
if err == nil && amountStruct.Currency == xrpCurrency {
291285
return true
292286
}
293287
}
294288

295289
return false
296290
}
297291

298-
func sourceAddressesRoot(tx XRPTransaction) (string, error) {
299-
var meta XRPMeta
292+
func sourceAddressesRoot(tx xrpTransaction) (string, error) {
293+
var meta xrpMeta
300294

301295
err := json.Unmarshal(tx.MetaData, &meta)
302296
if err != nil {
@@ -305,7 +299,7 @@ func sourceAddressesRoot(tx XRPTransaction) (string, error) {
305299

306300
sourceAddresses := make([]common.Hash, 0)
307301
for _, node := range meta.AffectedNodes {
308-
modifiedNode := node.XRPModifiedNode
302+
modifiedNode := node.ModifiedNode
309303
if modifiedNode.LedgerEntryType != "AccountRoot" || modifiedNode.FinalFields.Account == "" {
310304
continue
311305
}
@@ -356,12 +350,12 @@ func sourceAddressesRoot(tx XRPTransaction) (string, error) {
356350
return "", nil
357351
}
358352

359-
func (c XRPClient) GetServerInfo(ctx context.Context) (string, error) {
353+
func (c xrpClient) GetServerInfo(ctx context.Context) (string, error) {
360354
resBody, err := c.GetResponse(ctx, getServerState)
361355
if err != nil {
362356
return "", err
363357
}
364-
var respStruct ServerInfoResponse
358+
var respStruct serverInfoResponse
365359
err = json.Unmarshal(resBody, &respStruct)
366360
if err != nil {
367361
return "", err

0 commit comments

Comments
 (0)