@thru/thru-sdk 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/buf.gen.yaml +12 -0
- package/buf.lock +9 -0
- package/buf.yaml +15 -0
- package/dist/sdk.d.ts +1354 -0
- package/dist/sdk.js +1130 -0
- package/dist/sdk.js.map +1 -0
- package/package.json +39 -0
- package/proto/thru/common/v1/consensus.proto +75 -0
- package/proto/thru/common/v1/errors.proto +67 -0
- package/proto/thru/common/v1/filters.proto +50 -0
- package/proto/thru/common/v1/pagination.proto +47 -0
- package/proto/thru/core/v1/account.proto +138 -0
- package/proto/thru/core/v1/block.proto +82 -0
- package/proto/thru/core/v1/state.proto +37 -0
- package/proto/thru/core/v1/transaction.proto +95 -0
- package/proto/thru/core/v1/types.proto +52 -0
- package/proto/thru/services/v1/command_service.proto +45 -0
- package/proto/thru/services/v1/query_service.proto +344 -0
- package/proto/thru/services/v1/streaming_service.proto +128 -0
- package/thru-ts-client-sdk/core/bound-client.ts +129 -0
- package/thru-ts-client-sdk/core/client.ts +38 -0
- package/thru-ts-client-sdk/counter.ts +216 -0
- package/thru-ts-client-sdk/create-account.ts +78 -0
- package/thru-ts-client-sdk/defaults.ts +17 -0
- package/thru-ts-client-sdk/get-height.ts +52 -0
- package/thru-ts-client-sdk/modules/accounts.ts +137 -0
- package/thru-ts-client-sdk/modules/blocks.ts +75 -0
- package/thru-ts-client-sdk/modules/events.ts +20 -0
- package/thru-ts-client-sdk/modules/height.ts +9 -0
- package/thru-ts-client-sdk/modules/helpers.ts +340 -0
- package/thru-ts-client-sdk/modules/proofs.ts +20 -0
- package/thru-ts-client-sdk/modules/streaming.ts +34 -0
- package/thru-ts-client-sdk/modules/transactions.ts +274 -0
- package/thru-ts-client-sdk/proto/buf/validate/validate_pb.ts +4761 -0
- package/thru-ts-client-sdk/proto/google/api/annotations_pb.ts +39 -0
- package/thru-ts-client-sdk/proto/google/api/client_pb.ts +953 -0
- package/thru-ts-client-sdk/proto/google/api/field_behavior_pb.ts +157 -0
- package/thru-ts-client-sdk/proto/google/api/http_pb.ts +474 -0
- package/thru-ts-client-sdk/proto/google/api/launch_stage_pb.ts +118 -0
- package/thru-ts-client-sdk/proto/thru/common/v1/consensus_pb.ts +163 -0
- package/thru-ts-client-sdk/proto/thru/common/v1/errors_pb.ts +130 -0
- package/thru-ts-client-sdk/proto/thru/common/v1/filters_pb.ts +81 -0
- package/thru-ts-client-sdk/proto/thru/common/v1/pagination_pb.ts +80 -0
- package/thru-ts-client-sdk/proto/thru/core/v1/account_pb.ts +358 -0
- package/thru-ts-client-sdk/proto/thru/core/v1/block_pb.ts +260 -0
- package/thru-ts-client-sdk/proto/thru/core/v1/state_pb.ts +104 -0
- package/thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts +327 -0
- package/thru-ts-client-sdk/proto/thru/core/v1/types_pb.ts +101 -0
- package/thru-ts-client-sdk/proto/thru/services/v1/command_service_pb.ts +81 -0
- package/thru-ts-client-sdk/proto/thru/services/v1/query_service_pb.ts +813 -0
- package/thru-ts-client-sdk/proto/thru/services/v1/streaming_service_pb.ts +391 -0
- package/thru-ts-client-sdk/sdk.ts +58 -0
- package/thru-ts-client-sdk/transactions/Transaction.ts +240 -0
- package/thru-ts-client-sdk/transactions/TransactionBuilder.ts +48 -0
- package/thru-ts-client-sdk/transactions/__tests__/transaction.test.ts +95 -0
- package/thru-ts-client-sdk/transactions/index.ts +3 -0
- package/thru-ts-client-sdk/transactions/types.ts +64 -0
- package/thru-ts-client-sdk/transactions/utils.ts +134 -0
- package/thru-ts-client-sdk/types/types.ts +8 -0
- package/thru-ts-client-sdk/utils/utils.ts +70 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
edition = "2023";
|
|
2
|
+
|
|
3
|
+
package thru.services.v1;
|
|
4
|
+
|
|
5
|
+
option features.field_presence = EXPLICIT;
|
|
6
|
+
|
|
7
|
+
import "google/api/annotations.proto";
|
|
8
|
+
import "google/api/client.proto";
|
|
9
|
+
import "google/api/field_behavior.proto";
|
|
10
|
+
import "thru/core/v1/transaction.proto";
|
|
11
|
+
import "thru/core/v1/types.proto";
|
|
12
|
+
|
|
13
|
+
option go_package = "github.com/Unto-Labs/thru-net/grpc/pkg/proto/thru/services/v1;servicesv1";
|
|
14
|
+
option java_multiple_files = true;
|
|
15
|
+
option java_package = "network.thru.services.v1";
|
|
16
|
+
option csharp_namespace = "Thru.Services.V1";
|
|
17
|
+
option ruby_package = "Thru::Services::V1";
|
|
18
|
+
option objc_class_prefix = "THUS";
|
|
19
|
+
option swift_prefix = "THUS";
|
|
20
|
+
|
|
21
|
+
// SendTransactionRequest submits a transaction to the cluster.
|
|
22
|
+
message SendTransactionRequest {
|
|
23
|
+
// Raw transaction bytes encoded according to chain specification.
|
|
24
|
+
bytes raw_transaction = 1 [(google.api.field_behavior) = REQUIRED];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// SendTransactionResponse echoes submission metadata.
|
|
28
|
+
message SendTransactionResponse {
|
|
29
|
+
thru.core.v1.Signature signature = 1 [(google.api.field_behavior) = REQUIRED];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// CommandService defines transactional RPCs that mutate state or perform
|
|
33
|
+
// expensive computations.
|
|
34
|
+
service CommandService {
|
|
35
|
+
option (google.api.default_host) = "api.thru.network";
|
|
36
|
+
|
|
37
|
+
// Submit a new transaction to the cluster.
|
|
38
|
+
rpc SendTransaction(SendTransactionRequest)
|
|
39
|
+
returns (SendTransactionResponse) {
|
|
40
|
+
option (google.api.http) = {
|
|
41
|
+
post: "/v1/transactions"
|
|
42
|
+
body: "*"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
edition = "2023";
|
|
2
|
+
|
|
3
|
+
package thru.services.v1;
|
|
4
|
+
|
|
5
|
+
option features.field_presence = EXPLICIT;
|
|
6
|
+
|
|
7
|
+
import "buf/validate/validate.proto";
|
|
8
|
+
import "google/api/annotations.proto";
|
|
9
|
+
import "google/api/client.proto";
|
|
10
|
+
import "google/api/field_behavior.proto";
|
|
11
|
+
import "thru/common/v1/consensus.proto";
|
|
12
|
+
import "thru/common/v1/filters.proto";
|
|
13
|
+
import "thru/common/v1/pagination.proto";
|
|
14
|
+
import "thru/core/v1/account.proto";
|
|
15
|
+
import "thru/core/v1/block.proto";
|
|
16
|
+
import "thru/core/v1/state.proto";
|
|
17
|
+
import "thru/core/v1/transaction.proto";
|
|
18
|
+
import "thru/core/v1/types.proto";
|
|
19
|
+
|
|
20
|
+
option go_package = "github.com/Unto-Labs/thru-net/grpc/pkg/proto/thru/services/v1;servicesv1";
|
|
21
|
+
option java_multiple_files = true;
|
|
22
|
+
option java_package = "network.thru.services.v1";
|
|
23
|
+
option csharp_namespace = "Thru.Services.V1";
|
|
24
|
+
option ruby_package = "Thru::Services::V1";
|
|
25
|
+
option objc_class_prefix = "THUS";
|
|
26
|
+
option swift_prefix = "THUS";
|
|
27
|
+
|
|
28
|
+
// GetAccountRequest retrieves a decoded account by public key.
|
|
29
|
+
message GetAccountRequest {
|
|
30
|
+
thru.core.v1.Pubkey address = 1 [(google.api.field_behavior) = REQUIRED];
|
|
31
|
+
thru.core.v1.AccountView view = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
32
|
+
thru.common.v1.VersionContext version_context = 3
|
|
33
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
34
|
+
thru.common.v1.ConsensusStatus min_consensus = 4
|
|
35
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
36
|
+
thru.core.v1.DataSlice data_slice = 6
|
|
37
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
38
|
+
|
|
39
|
+
reserved 5;
|
|
40
|
+
reserved skip_data;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// GetRawAccountRequest retrieves raw account bytes by public key.
|
|
44
|
+
message GetRawAccountRequest {
|
|
45
|
+
thru.core.v1.Pubkey address = 1 [(google.api.field_behavior) = REQUIRED];
|
|
46
|
+
thru.core.v1.AccountView view = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
47
|
+
thru.common.v1.VersionContext version_context = 3
|
|
48
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
49
|
+
thru.common.v1.ConsensusStatus min_consensus = 4
|
|
50
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// GetTransactionRequest retrieves a decoded transaction by signature.
|
|
54
|
+
message GetTransactionRequest {
|
|
55
|
+
thru.core.v1.Signature signature = 1 [(google.api.field_behavior) = REQUIRED];
|
|
56
|
+
thru.core.v1.TransactionView view = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
57
|
+
thru.common.v1.VersionContext version_context = 3
|
|
58
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
59
|
+
thru.common.v1.ConsensusStatus min_consensus = 4
|
|
60
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// GetRawTransactionRequest retrieves raw transaction bytes by signature.
|
|
64
|
+
message GetRawTransactionRequest {
|
|
65
|
+
thru.core.v1.Signature signature = 1 [(google.api.field_behavior) = REQUIRED];
|
|
66
|
+
thru.common.v1.VersionContext version_context = 2
|
|
67
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
68
|
+
thru.common.v1.ConsensusStatus min_consensus = 3
|
|
69
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// GenerateStateProofRequest requests an account state proof.
|
|
73
|
+
message GenerateStateProofRequest {
|
|
74
|
+
thru.core.v1.StateProofRequest request = 1
|
|
75
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// GenerateStateProofResponse contains the generated proof.
|
|
79
|
+
message GenerateStateProofResponse {
|
|
80
|
+
thru.core.v1.StateProof proof = 1 [(google.api.field_behavior) = REQUIRED];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// GetBlockRequest retrieves decoded block information by slot or hash.
|
|
84
|
+
message GetBlockRequest {
|
|
85
|
+
option (buf.validate.message).cel = {
|
|
86
|
+
id: "block_selector_set"
|
|
87
|
+
message: "either slot or block_hash must be set"
|
|
88
|
+
expression: "has(this.slot) || has(this.block_hash)"
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
oneof selector {
|
|
92
|
+
uint64 slot = 1 [(google.api.field_behavior) = OPTIONAL];
|
|
93
|
+
thru.core.v1.BlockHash block_hash = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
94
|
+
}
|
|
95
|
+
thru.core.v1.BlockView view = 3 [(google.api.field_behavior) = OPTIONAL];
|
|
96
|
+
thru.common.v1.ConsensusStatus min_consensus = 4
|
|
97
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// GetRawBlockRequest retrieves raw block bytes by slot or hash.
|
|
101
|
+
message GetRawBlockRequest {
|
|
102
|
+
option (buf.validate.message).cel = {
|
|
103
|
+
id: "raw_block_selector_set"
|
|
104
|
+
message: "either slot or block_hash must be set"
|
|
105
|
+
expression: "has(this.slot) || has(this.block_hash)"
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
oneof selector {
|
|
109
|
+
uint64 slot = 1 [(google.api.field_behavior) = OPTIONAL];
|
|
110
|
+
thru.core.v1.BlockHash block_hash = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
111
|
+
}
|
|
112
|
+
thru.common.v1.ConsensusStatus min_consensus = 3
|
|
113
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ListOwnedAccountsRequest lists accounts for a given owner public key.
|
|
117
|
+
message ListOwnedAccountsRequest {
|
|
118
|
+
thru.core.v1.Pubkey owner = 1 [(google.api.field_behavior) = REQUIRED];
|
|
119
|
+
thru.core.v1.AccountView view = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
120
|
+
thru.common.v1.VersionContext version_context = 3
|
|
121
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
122
|
+
thru.common.v1.Filter filter = 4 [(google.api.field_behavior) = OPTIONAL];
|
|
123
|
+
thru.common.v1.PageRequest page = 5 [(google.api.field_behavior) = OPTIONAL];
|
|
124
|
+
thru.common.v1.ConsensusStatus min_consensus = 6
|
|
125
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ListOwnedAccountsResponse contains paginated accounts.
|
|
129
|
+
message ListOwnedAccountsResponse {
|
|
130
|
+
repeated thru.core.v1.Account accounts = 1
|
|
131
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
132
|
+
thru.common.v1.PageResponse page = 2
|
|
133
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ListBlocksRequest lists blocks with pagination and filtering.
|
|
137
|
+
message ListBlocksRequest {
|
|
138
|
+
thru.common.v1.Filter filter = 1 [(google.api.field_behavior) = OPTIONAL];
|
|
139
|
+
thru.common.v1.PageRequest page = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
140
|
+
thru.core.v1.BlockView view = 3 [(google.api.field_behavior) = OPTIONAL];
|
|
141
|
+
thru.common.v1.ConsensusStatus min_consensus = 4
|
|
142
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ListBlocksResponse returns a page of blocks.
|
|
146
|
+
message ListBlocksResponse {
|
|
147
|
+
repeated thru.core.v1.Block blocks = 1
|
|
148
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
149
|
+
thru.common.v1.PageResponse page = 2
|
|
150
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ListTransactionsForAccountRequest lists transaction signatures involving an account.
|
|
154
|
+
message ListTransactionsForAccountRequest {
|
|
155
|
+
thru.core.v1.Pubkey account = 1 [(google.api.field_behavior) = REQUIRED];
|
|
156
|
+
thru.common.v1.PageRequest page = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ListTransactionsForAccountResponse contains transaction signatures.
|
|
160
|
+
message ListTransactionsForAccountResponse {
|
|
161
|
+
repeated thru.core.v1.Signature signatures = 1
|
|
162
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
163
|
+
thru.common.v1.PageResponse page = 2
|
|
164
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// GetVersionRequest fetches component version strings.
|
|
168
|
+
message GetVersionRequest {}
|
|
169
|
+
|
|
170
|
+
// GetVersionResponse returns version information per component.
|
|
171
|
+
message GetVersionResponse {
|
|
172
|
+
map<string, string> versions = 1
|
|
173
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// GetEventRequest fetches an event by identifier.
|
|
177
|
+
message GetEventRequest {
|
|
178
|
+
string event_id = 1 [
|
|
179
|
+
(google.api.field_behavior) = REQUIRED,
|
|
180
|
+
(buf.validate.field).string.max_len = 128
|
|
181
|
+
];
|
|
182
|
+
thru.common.v1.VersionContext version_context = 2
|
|
183
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Event represents a transaction event emitted by the chain.
|
|
187
|
+
message Event {
|
|
188
|
+
string event_id = 1 [(google.api.field_behavior) = REQUIRED];
|
|
189
|
+
thru.core.v1.Signature transaction_signature = 2
|
|
190
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
191
|
+
thru.core.v1.Pubkey program = 3 [(google.api.field_behavior) = OPTIONAL];
|
|
192
|
+
bytes payload = 4 [(google.api.field_behavior) = OPTIONAL];
|
|
193
|
+
uint64 slot = 5 [(google.api.field_behavior) = OPTIONAL];
|
|
194
|
+
uint32 call_idx = 6 [(google.api.field_behavior) = OPTIONAL];
|
|
195
|
+
uint32 program_idx = 7 [(google.api.field_behavior) = OPTIONAL];
|
|
196
|
+
uint32 payload_size = 8 [(google.api.field_behavior) = OPTIONAL];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// GetTransactionStatusRequest fetches execution status for a transaction.
|
|
200
|
+
message GetTransactionStatusRequest {
|
|
201
|
+
thru.core.v1.Signature signature = 1 [(google.api.field_behavior) = REQUIRED];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// TransactionStatus captures status metadata for a transaction.
|
|
205
|
+
message TransactionStatus {
|
|
206
|
+
thru.core.v1.Signature signature = 1 [(google.api.field_behavior) = REQUIRED];
|
|
207
|
+
thru.common.v1.ConsensusStatus consensus_status = 2
|
|
208
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
209
|
+
thru.core.v1.TransactionExecutionResult execution_result = 3
|
|
210
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
//
|
|
214
|
+
message GetHeightRequest {}
|
|
215
|
+
|
|
216
|
+
// GetHeightResponse
|
|
217
|
+
message GetHeightResponse {
|
|
218
|
+
uint64 finalized = 1 [(google.api.field_behavior) = REQUIRED];
|
|
219
|
+
uint64 locally_executed = 2 [(google.api.field_behavior) = REQUIRED];
|
|
220
|
+
uint64 cluster_executed = 3 [(google.api.field_behavior) = REQUIRED];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
// QueryService defines unary RPCs for accessing blockchain data.
|
|
225
|
+
service QueryService {
|
|
226
|
+
option (google.api.default_host) = "api.thru.network";
|
|
227
|
+
|
|
228
|
+
// Get block heights
|
|
229
|
+
rpc GetHeight(GetHeightRequest) returns (GetHeightResponse) {
|
|
230
|
+
option (google.api.http) = {
|
|
231
|
+
get: "/v1/height"
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Get account information.
|
|
236
|
+
rpc GetAccount(GetAccountRequest) returns (thru.core.v1.Account) {
|
|
237
|
+
option (google.api.http) = {
|
|
238
|
+
get: "/v1/accounts/{address.value}"
|
|
239
|
+
};
|
|
240
|
+
option (google.api.method_signature) = "address";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Get account raw bytes.
|
|
244
|
+
rpc GetRawAccount(GetRawAccountRequest) returns (thru.core.v1.RawAccount) {
|
|
245
|
+
option (google.api.http) = {
|
|
246
|
+
get: "/v1/accounts/{address.value}:raw"
|
|
247
|
+
};
|
|
248
|
+
option (google.api.method_signature) = "address";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Get transaction by signature.
|
|
252
|
+
rpc GetTransaction(GetTransactionRequest) returns (thru.core.v1.Transaction) {
|
|
253
|
+
option (google.api.http) = {
|
|
254
|
+
get: "/v1/transactions/{signature.value}"
|
|
255
|
+
};
|
|
256
|
+
option (google.api.method_signature) = "signature";
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Get raw transaction by signature.
|
|
260
|
+
rpc GetRawTransaction(GetRawTransactionRequest)
|
|
261
|
+
returns (thru.core.v1.RawTransaction) {
|
|
262
|
+
option (google.api.http) = {
|
|
263
|
+
get: "/v1/transactions/{signature.value}:raw"
|
|
264
|
+
};
|
|
265
|
+
option (google.api.method_signature) = "signature";
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Get block by slot or hash.
|
|
269
|
+
rpc GetBlock(GetBlockRequest) returns (thru.core.v1.Block) {
|
|
270
|
+
option (google.api.http) = {
|
|
271
|
+
get: "/v1/blocks/{slot}"
|
|
272
|
+
additional_bindings {
|
|
273
|
+
get: "/v1/blocks/by-hash/{block_hash.value}"
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Get raw block bytes.
|
|
279
|
+
rpc GetRawBlock(GetRawBlockRequest) returns (thru.core.v1.RawBlock) {
|
|
280
|
+
option (google.api.http) = {
|
|
281
|
+
get: "/v1/blocks/{slot}:raw"
|
|
282
|
+
additional_bindings {
|
|
283
|
+
get: "/v1/blocks/by-hash/{block_hash.value}:raw"
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// List accounts owned by a public key.
|
|
289
|
+
rpc ListOwnedAccounts(ListOwnedAccountsRequest)
|
|
290
|
+
returns (ListOwnedAccountsResponse) {
|
|
291
|
+
option (google.api.http) = {
|
|
292
|
+
get: "/v1/accounts"
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// List blocks using pagination and filtering. By default returns blocks ordered from latest slot to the first one.
|
|
297
|
+
rpc ListBlocks(ListBlocksRequest) returns (ListBlocksResponse) {
|
|
298
|
+
option (google.api.http) = {
|
|
299
|
+
get: "/v1/blocks"
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// List executed transaction signatures involving an account.
|
|
304
|
+
rpc ListTransactionsForAccount(ListTransactionsForAccountRequest)
|
|
305
|
+
returns (ListTransactionsForAccountResponse) {
|
|
306
|
+
option (google.api.http) = {
|
|
307
|
+
get: "/v1/accounts/{account.value}/transactions"
|
|
308
|
+
};
|
|
309
|
+
option (google.api.method_signature) = "account";
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Get a specific event by ID.
|
|
313
|
+
rpc GetEvent(GetEventRequest) returns (Event) {
|
|
314
|
+
option (google.api.http) = {
|
|
315
|
+
get: "/v1/events/{event_id}"
|
|
316
|
+
};
|
|
317
|
+
option (google.api.method_signature) = "event_id";
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Get derived transaction status metadata.
|
|
321
|
+
rpc GetTransactionStatus(GetTransactionStatusRequest)
|
|
322
|
+
returns (TransactionStatus) {
|
|
323
|
+
option (google.api.http) = {
|
|
324
|
+
get: "/v1/transactions/{signature.value}:status"
|
|
325
|
+
};
|
|
326
|
+
option (google.api.method_signature) = "signature";
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Generate an account state proof snapshot.
|
|
330
|
+
rpc GenerateStateProof(GenerateStateProofRequest)
|
|
331
|
+
returns (GenerateStateProofResponse) {
|
|
332
|
+
option (google.api.http) = {
|
|
333
|
+
post: "/v1/stateproofs:generate"
|
|
334
|
+
body: "*"
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Get component version strings.
|
|
339
|
+
rpc GetVersion(GetVersionRequest) returns (GetVersionResponse) {
|
|
340
|
+
option (google.api.http) = {
|
|
341
|
+
get: "/v1/version"
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
edition = "2023";
|
|
2
|
+
|
|
3
|
+
package thru.services.v1;
|
|
4
|
+
|
|
5
|
+
option features.field_presence = EXPLICIT;
|
|
6
|
+
|
|
7
|
+
import "buf/validate/validate.proto";
|
|
8
|
+
import "google/api/field_behavior.proto";
|
|
9
|
+
import "google/protobuf/duration.proto";
|
|
10
|
+
import "google/protobuf/timestamp.proto";
|
|
11
|
+
import "thru/common/v1/consensus.proto";
|
|
12
|
+
import "thru/common/v1/filters.proto";
|
|
13
|
+
import "thru/core/v1/account.proto";
|
|
14
|
+
import "thru/core/v1/block.proto";
|
|
15
|
+
import "thru/core/v1/transaction.proto";
|
|
16
|
+
import "thru/core/v1/types.proto";
|
|
17
|
+
|
|
18
|
+
option go_package = "github.com/Unto-Labs/thru-net/grpc/pkg/proto/thru/services/v1;servicesv1";
|
|
19
|
+
option java_multiple_files = true;
|
|
20
|
+
option java_package = "network.thru.services.v1";
|
|
21
|
+
option csharp_namespace = "Thru.Services.V1";
|
|
22
|
+
option ruby_package = "Thru::Services::V1";
|
|
23
|
+
option objc_class_prefix = "THUS";
|
|
24
|
+
option swift_prefix = "THUS";
|
|
25
|
+
|
|
26
|
+
// StreamBlocksRequest subscribes to real-time block updates.
|
|
27
|
+
message StreamBlocksRequest {
|
|
28
|
+
uint64 start_slot = 1 [(google.api.field_behavior) = OPTIONAL];
|
|
29
|
+
thru.common.v1.Filter filter = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
30
|
+
thru.core.v1.BlockView view = 3 [(google.api.field_behavior) = OPTIONAL];
|
|
31
|
+
thru.common.v1.ConsensusStatus min_consensus = 4
|
|
32
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// StreamBlocksResponse delivers block updates.
|
|
36
|
+
message StreamBlocksResponse {
|
|
37
|
+
thru.core.v1.Block block = 1 [(google.api.field_behavior) = REQUIRED];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// StreamAccountUpdatesRequest subscribes to account delta events.
|
|
41
|
+
message StreamAccountUpdatesRequest {
|
|
42
|
+
thru.core.v1.Pubkey address = 1 [(google.api.field_behavior) = REQUIRED];
|
|
43
|
+
thru.core.v1.AccountView view = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
44
|
+
thru.common.v1.Filter filter = 4 [(google.api.field_behavior) = OPTIONAL];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// AccountUpdate describes a delta for an account.
|
|
48
|
+
message AccountUpdate {
|
|
49
|
+
uint64 slot = 1 [(google.api.field_behavior) = REQUIRED];
|
|
50
|
+
thru.core.v1.AccountPage page = 2
|
|
51
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
52
|
+
thru.core.v1.AccountMeta meta = 3
|
|
53
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
54
|
+
bool delete = 4 [(google.api.field_behavior) = OPTIONAL];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// StreamAccountUpdatesResponse contains either an initial snapshot or a delta.
|
|
58
|
+
message StreamAccountUpdatesResponse {
|
|
59
|
+
oneof message {
|
|
60
|
+
thru.core.v1.Account snapshot = 1;
|
|
61
|
+
AccountUpdate update = 2;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// StreamTransactionsRequest subscribes to transaction confirmations.
|
|
66
|
+
message StreamTransactionsRequest {
|
|
67
|
+
thru.common.v1.Filter filter = 1 [(google.api.field_behavior) = OPTIONAL];
|
|
68
|
+
thru.common.v1.ConsensusStatus min_consensus = 2
|
|
69
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// StreamTransactionsResponse delivers transaction events.
|
|
73
|
+
message StreamTransactionsResponse {
|
|
74
|
+
thru.core.v1.Transaction transaction = 1
|
|
75
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// StreamEventsRequest subscribes to chain events.
|
|
79
|
+
message StreamEventsRequest {
|
|
80
|
+
thru.common.v1.Filter filter = 1 [(google.api.field_behavior) = OPTIONAL];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// StreamEventsResponse delivers event payloads.
|
|
84
|
+
message StreamEventsResponse {
|
|
85
|
+
string event_id = 1 [(google.api.field_behavior) = REQUIRED];
|
|
86
|
+
bytes payload = 2 [(google.api.field_behavior) = OPTIONAL];
|
|
87
|
+
google.protobuf.Timestamp timestamp = 3
|
|
88
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
89
|
+
thru.core.v1.Pubkey program = 4 [(google.api.field_behavior) = REQUIRED];
|
|
90
|
+
uint32 call_idx = 5 [(google.api.field_behavior) = REQUIRED];
|
|
91
|
+
thru.core.v1.Signature signature = 6
|
|
92
|
+
[(google.api.field_behavior) = REQUIRED];
|
|
93
|
+
uint64 slot = 7 [(google.api.field_behavior) = REQUIRED];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// TrackTransactionRequest subscribes to status updates for a transaction.
|
|
97
|
+
message TrackTransactionRequest {
|
|
98
|
+
thru.core.v1.Signature signature = 1 [(google.api.field_behavior) = REQUIRED];
|
|
99
|
+
google.protobuf.Duration timeout = 2
|
|
100
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// TrackTransactionResponse reports status transitions for a transaction.
|
|
104
|
+
message TrackTransactionResponse {
|
|
105
|
+
thru.core.v1.Signature signature = 1 [(google.api.field_behavior) = REQUIRED];
|
|
106
|
+
thru.common.v1.ConsensusStatus consensus_status = 2
|
|
107
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
108
|
+
thru.core.v1.TransactionExecutionResult execution_result = 3
|
|
109
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// StreamingService serves server-streaming gRPC APIs for real-time data.
|
|
113
|
+
service StreamingService {
|
|
114
|
+
rpc StreamBlocks(StreamBlocksRequest)
|
|
115
|
+
returns (stream StreamBlocksResponse);
|
|
116
|
+
|
|
117
|
+
rpc StreamAccountUpdates(StreamAccountUpdatesRequest)
|
|
118
|
+
returns (stream StreamAccountUpdatesResponse);
|
|
119
|
+
|
|
120
|
+
rpc StreamTransactions(StreamTransactionsRequest)
|
|
121
|
+
returns (stream StreamTransactionsResponse);
|
|
122
|
+
|
|
123
|
+
rpc StreamEvents(StreamEventsRequest)
|
|
124
|
+
returns (stream StreamEventsResponse);
|
|
125
|
+
|
|
126
|
+
rpc TrackTransaction(TrackTransactionRequest)
|
|
127
|
+
returns (stream TrackTransactionResponse);
|
|
128
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { ThruClientContext } from "./client";
|
|
2
|
+
|
|
3
|
+
import * as accountsModule from "../modules/accounts";
|
|
4
|
+
import * as blocksModule from "../modules/blocks";
|
|
5
|
+
import * as eventsModule from "../modules/events";
|
|
6
|
+
import * as heightModule from "../modules/height";
|
|
7
|
+
import {
|
|
8
|
+
decodeAddress,
|
|
9
|
+
decodeSignature,
|
|
10
|
+
deriveProgramAddress,
|
|
11
|
+
encodeAddress,
|
|
12
|
+
encodeSignature,
|
|
13
|
+
toBlockHash,
|
|
14
|
+
toPubkey,
|
|
15
|
+
toSignature,
|
|
16
|
+
type DeriveProgramAddressOptions,
|
|
17
|
+
type DeriveProgramAddressResult,
|
|
18
|
+
} from "../modules/helpers";
|
|
19
|
+
import * as proofsModule from "../modules/proofs";
|
|
20
|
+
import * as streamingModule from "../modules/streaming";
|
|
21
|
+
import * as transactionsModule from "../modules/transactions";
|
|
22
|
+
import { BlockHash, Pubkey, Signature } from "../proto/thru/core/v1/types_pb";
|
|
23
|
+
|
|
24
|
+
type ContextualParameters<F> = F extends (ctx: ThruClientContext, ...args: infer P) => any ? P : never;
|
|
25
|
+
|
|
26
|
+
type BoundFunction<F> = F extends (ctx: ThruClientContext, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
27
|
+
|
|
28
|
+
function bind<F extends (ctx: ThruClientContext, ...args: any[]) => any>(
|
|
29
|
+
ctx: ThruClientContext,
|
|
30
|
+
fn: F,
|
|
31
|
+
): BoundFunction<F> {
|
|
32
|
+
return ((...args: ContextualParameters<F>) => fn(ctx, ...args)) as BoundFunction<F>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface BoundBlocks {
|
|
36
|
+
get: BoundFunction<typeof blocksModule.getBlock>;
|
|
37
|
+
getRaw: BoundFunction<typeof blocksModule.getRawBlock>;
|
|
38
|
+
list: BoundFunction<typeof blocksModule.listBlocks>;
|
|
39
|
+
getBlockHeight: BoundFunction<typeof heightModule.getBlockHeight>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface BoundAccounts {
|
|
43
|
+
get: BoundFunction<typeof accountsModule.getAccount>;
|
|
44
|
+
getRaw: BoundFunction<typeof accountsModule.getRawAccount>;
|
|
45
|
+
listOwned: BoundFunction<typeof accountsModule.listOwnedAccounts>;
|
|
46
|
+
create: BoundFunction<typeof accountsModule.createAccount>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface BoundTransactions {
|
|
50
|
+
get: BoundFunction<typeof transactionsModule.getTransaction>;
|
|
51
|
+
getRaw: BoundFunction<typeof transactionsModule.getRawTransaction>;
|
|
52
|
+
getStatus: BoundFunction<typeof transactionsModule.getTransactionStatus>;
|
|
53
|
+
build: BoundFunction<typeof transactionsModule.buildTransaction>;
|
|
54
|
+
buildAndSign: BoundFunction<typeof transactionsModule.buildAndSignTransaction>;
|
|
55
|
+
send: BoundFunction<typeof transactionsModule.sendTransaction>;
|
|
56
|
+
track: BoundFunction<typeof streamingModule.trackTransaction>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface BoundEvents {
|
|
60
|
+
get: BoundFunction<typeof eventsModule.getEvent>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface BoundProofs {
|
|
64
|
+
generate: BoundFunction<typeof proofsModule.generateStateProof>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Helpers {
|
|
68
|
+
toSignature(value: Uint8Array | string): Signature;
|
|
69
|
+
toPubkey(value: Uint8Array | string, field: string): Pubkey;
|
|
70
|
+
toBlockHash(value: Uint8Array | string): BlockHash;
|
|
71
|
+
encodeSignature(bytes: Uint8Array): string;
|
|
72
|
+
decodeSignature(value: string): Uint8Array;
|
|
73
|
+
encodeAddress(bytes: Uint8Array): string;
|
|
74
|
+
decodeAddress(value: string): Uint8Array;
|
|
75
|
+
deriveProgramAddress(options: DeriveProgramAddressOptions): DeriveProgramAddressResult;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface Thru {
|
|
79
|
+
ctx: ThruClientContext;
|
|
80
|
+
blocks: BoundBlocks;
|
|
81
|
+
accounts: BoundAccounts;
|
|
82
|
+
transactions: BoundTransactions;
|
|
83
|
+
events: BoundEvents;
|
|
84
|
+
proofs: BoundProofs;
|
|
85
|
+
helpers: Helpers;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function createBoundThruClient(ctx: ThruClientContext): Thru {
|
|
89
|
+
return {
|
|
90
|
+
ctx,
|
|
91
|
+
blocks: {
|
|
92
|
+
get: bind(ctx, blocksModule.getBlock),
|
|
93
|
+
getRaw: bind(ctx, blocksModule.getRawBlock),
|
|
94
|
+
list: bind(ctx, blocksModule.listBlocks),
|
|
95
|
+
getBlockHeight: bind(ctx, heightModule.getBlockHeight),
|
|
96
|
+
},
|
|
97
|
+
accounts: {
|
|
98
|
+
get: bind(ctx, accountsModule.getAccount),
|
|
99
|
+
getRaw: bind(ctx, accountsModule.getRawAccount),
|
|
100
|
+
listOwned: bind(ctx, accountsModule.listOwnedAccounts),
|
|
101
|
+
create: bind(ctx, accountsModule.createAccount),
|
|
102
|
+
},
|
|
103
|
+
transactions: {
|
|
104
|
+
get: bind(ctx, transactionsModule.getTransaction),
|
|
105
|
+
getRaw: bind(ctx, transactionsModule.getRawTransaction),
|
|
106
|
+
getStatus: bind(ctx, transactionsModule.getTransactionStatus),
|
|
107
|
+
build: bind(ctx, transactionsModule.buildTransaction),
|
|
108
|
+
buildAndSign: bind(ctx, transactionsModule.buildAndSignTransaction),
|
|
109
|
+
send: bind(ctx, transactionsModule.sendTransaction),
|
|
110
|
+
track: bind(ctx, streamingModule.trackTransaction),
|
|
111
|
+
},
|
|
112
|
+
helpers: {
|
|
113
|
+
toSignature,
|
|
114
|
+
toPubkey,
|
|
115
|
+
toBlockHash,
|
|
116
|
+
encodeSignature,
|
|
117
|
+
decodeSignature,
|
|
118
|
+
encodeAddress,
|
|
119
|
+
decodeAddress,
|
|
120
|
+
deriveProgramAddress,
|
|
121
|
+
},
|
|
122
|
+
events: {
|
|
123
|
+
get: bind(ctx, eventsModule.getEvent),
|
|
124
|
+
},
|
|
125
|
+
proofs: {
|
|
126
|
+
generate: bind(ctx, proofsModule.generateStateProof),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createClient } from "@connectrpc/connect";
|
|
2
|
+
import { createGrpcWebTransport } from "@connectrpc/connect-web";
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_HOST } from "../defaults";
|
|
5
|
+
import { CommandService } from "../proto/thru/services/v1/command_service_pb";
|
|
6
|
+
import { QueryService } from "../proto/thru/services/v1/query_service_pb";
|
|
7
|
+
import { StreamingService } from "../proto/thru/services/v1/streaming_service_pb";
|
|
8
|
+
|
|
9
|
+
export interface ThruClientConfig {
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type QueryClient = ReturnType<typeof createClient<typeof QueryService>>;
|
|
14
|
+
export type CommandClient = ReturnType<typeof createClient<typeof CommandService>>;
|
|
15
|
+
export type StreamingClient = ReturnType<typeof createClient<typeof StreamingService>>;
|
|
16
|
+
|
|
17
|
+
export interface ThruClientContext {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
transport: ReturnType<typeof createGrpcWebTransport>;
|
|
20
|
+
query: QueryClient;
|
|
21
|
+
command: CommandClient;
|
|
22
|
+
streaming: StreamingClient;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createThruClientContext(config: ThruClientConfig = {}): ThruClientContext {
|
|
26
|
+
const baseUrl = config.baseUrl ?? DEFAULT_HOST;
|
|
27
|
+
const transport = createGrpcWebTransport({
|
|
28
|
+
baseUrl,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
baseUrl,
|
|
33
|
+
transport,
|
|
34
|
+
query: createClient(QueryService, transport),
|
|
35
|
+
command: createClient(CommandService, transport),
|
|
36
|
+
streaming: createClient(StreamingService, transport),
|
|
37
|
+
};
|
|
38
|
+
}
|