-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbundles.go
89 lines (76 loc) · 2.31 KB
/
bundles.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
78
79
80
81
82
83
84
85
86
87
88
89
package jitorpc
import (
"encoding/json"
"fmt"
"math/rand"
)
type TipAccount struct {
Address string `json:"address"`
}
type BundleStatusResponse struct {
Context struct {
Slot int64 `json:"slot"`
} `json:"context"`
Value []struct {
BundleID string `json:"bundle_id"`
Transactions []string `json:"transactions"`
Slot int64 `json:"slot"`
ConfirmationStatus string `json:"confirmation_status"`
Err struct {
Ok interface{} `json:"Ok"`
} `json:"err"`
} `json:"value"`
}
func (c *JitoJsonRpcClient) GetTipAccounts() (json.RawMessage, error) {
endpoint := "/bundles"
if c.UUID != "" {
endpoint = fmt.Sprintf("%s?uuid=%s", endpoint, c.UUID)
}
return c.sendRequest(endpoint, "getTipAccounts", nil)
}
func (c *JitoJsonRpcClient) GetRandomTipAccount() (*TipAccount, error) {
rawResponse, err := c.GetTipAccounts()
if err != nil {
return nil, err
}
var tipAddresses []string
err = json.Unmarshal(rawResponse, &tipAddresses)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal tip accounts: %w", err)
}
if len(tipAddresses) == 0 {
return nil, fmt.Errorf("no tip accounts available")
}
randomIndex := rand.Intn(len(tipAddresses))
return &TipAccount{Address: tipAddresses[randomIndex]}, nil
}
func (c *JitoJsonRpcClient) GetBundleStatuses(bundleIds []string) (*BundleStatusResponse, error) {
endpoint := "/bundles"
if c.UUID != "" {
endpoint = fmt.Sprintf("%s?uuid=%s", endpoint, c.UUID)
}
params := [][]string{bundleIds}
responseBody, err := c.sendRequest(endpoint, "getBundleStatuses", params)
if err != nil {
return nil, err
}
var response BundleStatusResponse
if err := json.Unmarshal(responseBody, &response); err != nil {
return nil, fmt.Errorf("failed to unmarshal bundle statuses: %w", err)
}
return &response, nil
}
func (c *JitoJsonRpcClient) SendBundle(params interface{}) (json.RawMessage, error) {
endpoint := "/bundles"
if c.UUID != "" {
endpoint = fmt.Sprintf("%s?uuid=%s", endpoint, c.UUID)
}
return c.sendRequest(endpoint, "sendBundle", params)
}
func (c *JitoJsonRpcClient) GetInflightBundleStatuses(params interface{}) (json.RawMessage, error) {
endpoint := "/bundles"
if c.UUID != "" {
endpoint = fmt.Sprintf("%s?uuid=%s", endpoint, c.UUID)
}
return c.sendRequest(endpoint, "getInflightBundleStatuses", params)
}