-
Notifications
You must be signed in to change notification settings - Fork 10
/
client.go
189 lines (175 loc) · 11.6 KB
/
client.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package blockfrost
import (
"context"
"net/http"
"os"
"github.com/hashicorp/go-retryablehttp"
)
type apiClient struct {
server string
projectId string
client *http.Client
routines int
}
// APIClientOptions contains optios used to initialize an API Client using
// NewAPIClient
type APIClientOptions struct {
// The project_id to use from blockfrost. If not set
// `BLOCKFROST_PROJECT_ID` is loaded from env
ProjectID string
// Server url to use
Server string
// Max number of routines to use for *All methods
MaxRoutines int
// Underlying http client to use. If not set, default github.com/hashicorp/go-retryablehttp is used.
Client *http.Client
}
// NewAPIClient creates a client from APIClientOptions. If no options are provided,
// client with default configurations is returned.
func NewAPIClient(options APIClientOptions) APIClient {
if options.Server == "" {
options.Server = CardanoMainNet
}
if options.Client == nil {
retryclient := retryablehttp.NewClient()
retryclient.Logger = nil
options.Client = retryclient.StandardClient()
}
if options.ProjectID == "" {
options.ProjectID = os.Getenv("BLOCKFROST_PROJECT_ID")
}
if options.MaxRoutines == 0 {
options.MaxRoutines = 10
}
client := &apiClient{
server: options.Server,
client: options.Client,
projectId: options.ProjectID,
routines: options.MaxRoutines,
}
return client
}
// APIClient defines methods implemented by the api client.
type APIClient interface {
Info(ctx context.Context) (Info, error)
Health(ctx context.Context) (Health, error)
HealthClock(ctx context.Context) (HealthClock, error)
Metrics(ctx context.Context) ([]Metric, error)
MetricsEndpoints(ctx context.Context) ([]MetricsEndpoint, error)
Block(ctx context.Context, hashOrNumber string) (Block, error)
BlockLatest(ctx context.Context) (Block, error)
BlockLatestTransactions(ctx context.Context) ([]Transaction, error)
BlockTransactions(ctx context.Context, hashOrNumer string) ([]Transaction, error)
BlocksNext(ctx context.Context, hashOrNumber string) ([]Block, error)
BlocksPrevious(ctx context.Context, hashOrNumber string) ([]Block, error)
BlockBySlot(ctx context.Context, slotNumber int) (Block, error)
BlocksBySlotAndEpoch(ctx context.Context, slotNumber int, epochNumber int) (Block, error)
BlocksAddresses(ctx context.Context, hashOrNumber string, query APIQueryParams) ([]BlockAffectedAddresses, error)
BlocksAddressesAll(ctx context.Context, hashOrNumber string) <-chan BlockAffectedAddressesResult
EpochLatest(ctx context.Context) (Epoch, error)
LatestEpochParameters(ctx context.Context) (EpochParameters, error)
Epoch(ctx context.Context, epochNumber int) (Epoch, error)
EpochsNext(ctx context.Context, epochNumber int, query APIQueryParams) ([]Epoch, error)
EpochNextAll(ctx context.Context, epochNumber int) <-chan EpochResult
EpochsPrevious(ctx context.Context, epochNumber int, query APIQueryParams) ([]Epoch, error)
EpochPreviousAll(ctx context.Context, epochNumber int) <-chan EpochResult
EpochStakeDistribution(ctx context.Context, epochNumber int, query APIQueryParams) ([]EpochStake, error)
EpochStakeDistributionAll(ctx context.Context, epochNumber int) <-chan EpochStakeResult
EpochStakeDistributionByPool(ctx context.Context, epochNumber int, poolId string, query APIQueryParams) ([]EpochStakeByPool, error)
EpochStakeDistributionByPoolAll(ctx context.Context, epochNumber int, poolId string) <-chan EpochStakeByPoolResult
EpochBlockDistribution(ctx context.Context, epochNumber int, query APIQueryParams) ([]string, error)
EpochBlockDistributionAll(ctx context.Context, epochNumber int) <-chan BlockDistributionResult
EpochBlockDistributionByPool(ctx context.Context, epochNumber int, poolId string, query APIQueryParams) ([]string, error)
EpochBlockDistributionByPoolAll(ctx context.Context, epochNumber int, poolId string) <-chan BlockDistributionResult
EpochParameters(ctx context.Context, epochNumber int) (EpochParameters, error)
Address(ctx context.Context, address string) (Address, error)
AddressDetails(ctx context.Context, address string) (AddressDetails, error)
AddressTransactions(ctx context.Context, address string, query APIQueryParams) ([]AddressTransactions, error)
AddressTransactionsAll(ctx context.Context, address string) <-chan AddressTxResult
AddressUTXOs(ctx context.Context, address string, query APIQueryParams) ([]AddressUTXO, error)
AddressUTXOsAll(ctx context.Context, address string) <-chan AddressUTXOResult
AddressUTXOsAsset(ctx context.Context, address, asset string, query APIQueryParams) ([]AddressUTXO, error)
AddressUTXOsAssetAll(ctx context.Context, address, asset string) <-chan AddressUTXOResult
Account(ctx context.Context, stakeAddress string) (Account, error)
AccountHistory(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountHistory, error)
AccountHistoryAll(ctx context.Context, address string) <-chan AccountHistoryResult
AccountRewardsHistory(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountRewardsHistory, error)
AccountRewardsHistoryAll(ctx context.Context, stakeAddress string) <-chan AccountRewardHisResult
AccountDelegationHistory(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountDelegationHistory, error)
AccountDelegationHistoryAll(ctx context.Context, stakeAddress string) <-chan AccDelegationHistoryResult
AccountRegistrationHistory(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountRegistrationHistory, error)
AccountRegistrationHistoryAll(ctx context.Context, stakeAddress string) <-chan AccountRegistrationHistoryResult
AccountWithdrawalHistory(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountWithdrawalHistory, error)
AccountWithdrawalHistoryAll(ctx context.Context, stakeAddress string) <-chan AccountWithdrawalHistoryResult
AccountMIRHistory(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountMIRHistory, error)
AccountMIRHistoryAll(ctx context.Context, stakeAddress string) <-chan AccountMIRHistoryResult
AccountAssociatedAddresses(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountAssociatedAddress, error)
AccountAssociatedAddressesAll(ctx context.Context, stakeAddress string) <-chan AccountAssociatedAddressesAll
AccountAssociatedAssets(ctx context.Context, stakeAddress string, query APIQueryParams) ([]AccountAssociatedAsset, error)
AccountAssociatedAssetsAll(ctx context.Context, stakeAddress string) <-chan AccountAssociatedAssetsAll
Asset(ctx context.Context, asset string) (Asset, error)
Assets(ctx context.Context, query APIQueryParams) ([]AssetByPolicy, error)
AssetsAll(ctx context.Context) <-chan AssetByPolicyResult
AssetHistory(ctx context.Context, asset string) ([]AssetHistory, error)
AssetTransactions(ctx context.Context, asset string) ([]AssetTransaction, error)
AssetAddresses(ctx context.Context, asset string, query APIQueryParams) ([]AssetAddress, error)
AssetAddressesAll(ctx context.Context, asset string) <-chan AssetAddressesAll
AssetsByPolicy(ctx context.Context, policyId string) ([]AssetByPolicy, error)
Genesis(ctx context.Context) (GenesisBlock, error)
Mempool(ctx context.Context, query APIQueryParams) ([]Mempool, error)
MempoolAll(ctx context.Context) <-chan MempoolResult
MempoolTx(ctx context.Context, hash string) (MempoolTransactionContent, error)
MempoolByAddress(ctx context.Context, address string, query APIQueryParams) ([]Mempool, error)
MempoolByAddressAll(ctx context.Context, address string) <-chan MempoolResult
MetadataTxLabels(ctx context.Context, query APIQueryParams) ([]MetadataTxLabel, error)
MetadataTxLabelsAll(ctx context.Context) <-chan MetadataTxLabelResult
MetadataTxContentInJSON(ctx context.Context, label string, query APIQueryParams) ([]MetadataTxContentInJSON, error)
MetadataTxContentInJSONAll(ctx context.Context, label string) <-chan MetadataTxContentInJSONResult
MetadataTxContentInCBOR(ctx context.Context, label string, query APIQueryParams) ([]MetadataTxContentInCBOR, error)
MetadataTxContentInCBORAll(ctx context.Context, label string) <-chan MetadataTxContentInCBORResult
Network(ctx context.Context) (NetworkInfo, error)
Nutlink(ctx context.Context, address string) (NutlinkAddress, error)
Tickers(ctx context.Context, address string, query APIQueryParams) ([]Ticker, error)
TickersAll(ctx context.Context, address string) <-chan TickerResult
TickerRecords(ctx context.Context, ticker string, query APIQueryParams) ([]TickerRecord, error)
TickerRecordsAll(ctx context.Context, ticker string) <-chan TickerRecordResult
AddressTickerRecords(ctx context.Context, address string, ticker string, query APIQueryParams) ([]TickerRecord, error)
AddressTickerRecordsAll(ctx context.Context, address string, ticker string) <-chan TickerRecordResult
Script(ctx context.Context, address string) (Script, error)
Scripts(ctx context.Context, query APIQueryParams) ([]Script, error)
ScriptsAll(ctx context.Context) <-chan ScriptAllResult
ScriptRedeemers(ctx context.Context, address string, query APIQueryParams) ([]ScriptRedeemer, error)
ScriptRedeemersAll(ctx context.Context, address string) <-chan ScriptRedeemerResult
Pool(ctx context.Context, poolID string) (Pool, error)
Pools(ctx context.Context, query APIQueryParams) (Pools, error)
PoolsAll(ctx context.Context) <-chan PoolsResult
PoolsRetired(ctx context.Context, query APIQueryParams) ([]PoolRetired, error)
PoolsRetiredAll(ctx context.Context) <-chan PoolsRetiredResult
PoolsRetiring(ctx context.Context, query APIQueryParams) ([]PoolRetiring, error)
PoolsRetiringAll(ctx context.Context) <-chan PoolsRetiringResult
PoolHistory(ctx context.Context, poolID string, query APIQueryParams) ([]PoolHistory, error)
PoolHistoryAll(ctx context.Context, poolId string) <-chan PoolHistoryResult
PoolMetadata(ctx context.Context, poolID string) (PoolMetadata, error)
PoolRelays(ctx context.Context, poolID string) ([]PoolRelay, error)
PoolDelegators(ctx context.Context, poolID string, query APIQueryParams) ([]PoolDelegator, error)
PoolDelegatorsAll(ctx context.Context, poolId string) <-chan PoolDelegatorsResult
PoolBlocks(ctx context.Context, poolID string, query APIQueryParams) (PoolBlocks, error)
PoolBlocksAll(ctx context.Context, poolId string) <-chan PoolBlocksResult
PoolUpdates(ctx context.Context, poolID string, query APIQueryParams) ([]PoolUpdate, error)
PoolUpdatesAll(ctx context.Context, poolId string) <-chan PoolUpdateResult
Transaction(ctx context.Context, hash string) (TransactionContent, error)
TransactionUTXOs(ctx context.Context, hash string) (TransactionUTXOs, error)
TransactionStakeAddressCerts(ctx context.Context, hash string) ([]TransactionStakeAddressCert, error)
TransactionWithdrawals(ctx context.Context, hash string) ([]TransactionWidthrawal, error)
TransactionMIRs(ctx context.Context, hash string) ([]TransactionMIR, error)
TransactionMetadata(ctx context.Context, hash string) ([]TransactionMetadata, error)
TransactionMetadataInCBORs(ctx context.Context, hash string) ([]TransactionMetadataCbor, error)
TransactionRedeemers(ctx context.Context, hash string) ([]TransactionRedeemer, error)
TransactionDelegationCerts(ctx context.Context, hash string) ([]TransactionDelegation, error)
TransactionPoolUpdates(ctx context.Context, hash string) ([]TransactionPoolCert, error)
TransactionPoolUpdateCerts(ctx context.Context, hash string) ([]TransactionPoolCert, error)
TransactionPoolRetirementCerts(ctx context.Context, hash string) ([]TransactionPoolCert, error)
TransactionSubmit(ctx context.Context, cbor []byte) (string, error)
TransactionEvaluate(ctx context.Context, cbor []byte) (OgmiosResponse, error)
TransactionEvaluateUTXOs(ctx context.Context, cbor []byte, additionalUtxoSet AdditionalUtxoSet) (OgmiosResponse, error)
}