@flashbacktech/flashbackclient 0.0.13

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.
@@ -0,0 +1,450 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { get_provider, get_provider_units, get_providers, get_provider_count, register_provider, delete_provider, update_provider, } from './provider.js';
11
+ import { get_consumer, get_consumer_reservations, get_consumers, get_consumer_count, register_consumer, delete_consumer, update_consumer, } from './consumer.js';
12
+ import { get_unit, get_unit_reservations, delete_unit, enter_maintenance, exit_maintenance, enter_decommissioning, exit_decommissioning, register_unit, } from './unit.js';
13
+ import { create_reservation, get_reservation, delete_reservation, update_inuse_bytes_consumer, update_inuse_bytes_provider, } from './reservation.js';
14
+ import { signTransaction, getPublicKeyFromPrivateKey } from './transaction.js';
15
+ import { requiresSignature } from './decorator.js';
16
+ import { get_stats } from './stats.js';
17
+ /**
18
+ * Main client class for interacting with the FlashOnStellar system
19
+ * This client provides methods for managing providers, consumers, units, and reservations
20
+ * on the Stellar blockchain.
21
+ */
22
+ class FlashOnStellarClient {
23
+ getContext() {
24
+ return {
25
+ network: this.network,
26
+ signTransaction: this.signTransaction,
27
+ contractAddress: this.contractAddress,
28
+ };
29
+ }
30
+ /**
31
+ * Creates a new instance of the FlashOnStellarClient
32
+ * @param config - Configuration options for the client
33
+ */
34
+ constructor(config) {
35
+ /**
36
+ * Derives a public key from a private key
37
+ * @param privateKey - Stellar private key
38
+ * @returns The corresponding public key
39
+ */
40
+ this.getPublicKey = (privateKey) => {
41
+ return getPublicKeyFromPrivateKey(privateKey);
42
+ };
43
+ /**
44
+ * Signs a transaction using the provided private key using Stellar SDK
45
+ * The alternative is providing your own signing function (for example, using Wallet Kit).
46
+ * @param xdrToSign - XDR-encoded transaction to sign
47
+ * @param privateKey - Stellar private key to sign with
48
+ * @returns Promise resolving to the signed XDR string
49
+ */
50
+ this.signTransactionWithKey = async (xdrToSign, privateKey) => {
51
+ const signedTx = await signTransaction(this.getContext(), xdrToSign, privateKey);
52
+ return signedTx.toXDR();
53
+ };
54
+ // Stats methods
55
+ /**
56
+ * Retrieves stats for the current user
57
+ * @param wallet_address - Address of the wallet requesting the information
58
+ * @returns Promise resolving to DashboardStats object
59
+ */
60
+ this.get_stats = (wallet_address) => {
61
+ return get_stats(this.getContext(), wallet_address);
62
+ };
63
+ // Provider methods
64
+ /**
65
+ * Retrieves provider information
66
+ * @param wallet_address - Address of the wallet requesting the information
67
+ * @param provider_address - Address of the provider to retrieve
68
+ * @param load_units - Optional flag to include provider's units in the response
69
+ * @returns Promise resolving to StorageProvider object
70
+ */
71
+ this.get_provider = (wallet_address, provider_address, load_units) => {
72
+ return get_provider(this.getContext(), wallet_address, provider_address, load_units);
73
+ };
74
+ /**
75
+ * Retrieves all units associated with a provider
76
+ * @param wallet_address - Address of the wallet requesting the information
77
+ * @param provider_address - Address of the provider
78
+ * @returns Promise resolving to an array of StorageUnit objects
79
+ */
80
+ this.get_provider_units = (wallet_address, provider_address) => {
81
+ return get_provider_units(this.getContext(), wallet_address, provider_address);
82
+ };
83
+ /**
84
+ * Retrieves a paginated list of providers
85
+ * @param wallet_address - Address of the wallet requesting the information
86
+ * @param skip - Number of items to skip for pagination
87
+ * @param take - Number of items to take per page
88
+ * @returns Promise resolving to an array of StorageProvider objects
89
+ */
90
+ this.get_providers = (wallet_address, skip = 0, take = 10) => {
91
+ return get_providers(this.getContext(), wallet_address, skip, take);
92
+ };
93
+ /**
94
+ * Gets the total count of providers in the system
95
+ * @param wallet_address - Address of the wallet requesting the information
96
+ * @returns Promise resolving to the total number of providers
97
+ */
98
+ this.get_provider_count = (wallet_address) => {
99
+ return get_provider_count(this.getContext(), wallet_address);
100
+ };
101
+ // Consumer methods
102
+ /**
103
+ * Retrieves consumer information
104
+ * @param wallet_address - Address of the wallet requesting the information
105
+ * @param consumer_address - Address of the consumer to retrieve
106
+ * @param load_reservations - Optional flag to include consumer's reservations
107
+ * @returns Promise resolving to StorageConsumer object
108
+ */
109
+ this.get_consumer = (wallet_address, consumer_address, load_reservations) => {
110
+ return get_consumer(this.getContext(), wallet_address, consumer_address, load_reservations);
111
+ };
112
+ /**
113
+ * Retrieves a paginated list of consumers
114
+ * @param wallet_address - Address of the wallet requesting the information
115
+ * @param skip - Number of items to skip for pagination
116
+ * @param take - Number of items to take per page
117
+ * @returns Promise resolving to an array of StorageConsumer objects
118
+ */
119
+ this.get_consumers = (wallet_address, skip = 0, take = 10) => {
120
+ return get_consumers(this.getContext(), wallet_address, skip, take);
121
+ };
122
+ /**
123
+ * Gets the total count of consumers in the system
124
+ * @param wallet_address - Address of the wallet requesting the information
125
+ * @returns Promise resolving to the total number of consumers
126
+ */
127
+ this.get_consumer_count = (wallet_address) => {
128
+ return get_consumer_count(this.getContext(), wallet_address);
129
+ };
130
+ /**
131
+ * Retrieves all reservations associated with a consumer
132
+ * @param wallet_address - Address of the wallet requesting the information
133
+ * @param consumer_address - Address of the consumer
134
+ * @returns Promise resolving to an array of StorageReservation objects
135
+ */
136
+ this.get_consumer_reservations = (wallet_address, consumer_address) => {
137
+ return get_consumer_reservations(this.getContext(), wallet_address, consumer_address);
138
+ };
139
+ /**
140
+ * Retrieves storage unit information
141
+ * @param wallet_address - Address of the wallet requesting the information
142
+ * @param unit_id - Identifier of the storage unit
143
+ * @param load_reservations - Optional flag to include unit's reservations
144
+ * @returns Promise resolving to StorageUnit object
145
+ */
146
+ this.get_unit = (wallet_address, unit_id, load_reservations) => {
147
+ return get_unit(this.getContext(), wallet_address, unit_id, load_reservations);
148
+ };
149
+ /**
150
+ * Retrieves all reservations for a specific storage unit
151
+ * @param wallet_address - Address of the wallet requesting the information
152
+ * @param unit_id - Identifier of the storage unit
153
+ * @returns Promise resolving to an array of StorageReservation objects
154
+ */
155
+ this.get_unit_reservations = (wallet_address, unit_id) => {
156
+ return get_unit_reservations(this.getContext(), wallet_address, unit_id);
157
+ };
158
+ // Reservation methods
159
+ /**
160
+ * Retrieves information about a specific reservation
161
+ * @param wallet_address - Address of the wallet requesting the information
162
+ * @param reservation_id - Identifier of the reservation
163
+ * @returns Promise resolving to StorageReservation object
164
+ */
165
+ this.get_reservation = (wallet_address, reservation_id) => {
166
+ return get_reservation(this.getContext(), wallet_address, reservation_id);
167
+ };
168
+ this.signTransaction = config.signTransaction;
169
+ this.contractAddress = config.contractAddress;
170
+ this.network = config.network;
171
+ }
172
+ /**
173
+ * Registers a new provider in the system
174
+ * @param wallet_address - Address of the wallet registering the provider
175
+ * @param provider_address - Address for the new provider
176
+ * @param provider_description - Description of the provider
177
+ * @returns Promise resolving to the registration transaction result
178
+ * @requires Signature - This method requires a transaction signature
179
+ * @throws Will throw if provider address is already registered
180
+ */
181
+ register_provider(wallet_address, provider_address, provider_description) {
182
+ return register_provider(this.getContext(), wallet_address, provider_address, provider_description);
183
+ }
184
+ /**
185
+ * Deletes a provider from the system
186
+ * @param wallet_address - Address of the wallet making the request
187
+ * @param provider_address - Address of the provider to delete
188
+ * @returns Promise resolving to the deletion transaction result
189
+ * @requires Signature - This method requires a transaction signature
190
+ */
191
+ delete_provider(wallet_address, provider_address) {
192
+ return delete_provider(this.getContext(), wallet_address, provider_address);
193
+ }
194
+ /**
195
+ * Updates provider information
196
+ * @param wallet_address - Address of the wallet making the request
197
+ * @param provider_address - Address of the provider to update
198
+ * @param provider_description - New description for the provider
199
+ * @returns Promise resolving to the update transaction result
200
+ * @requires Signature - This method requires a transaction signature
201
+ */
202
+ update_provider(wallet_address, provider_address, provider_description) {
203
+ return update_provider(this.getContext(), wallet_address, provider_address, provider_description);
204
+ }
205
+ /**
206
+ * Registers a new consumer in the system
207
+ * @param wallet_address - Address of the wallet registering the consumer
208
+ * @param consumer_address - Address for the new consumer
209
+ * @param consumer_description - Description of the consumer
210
+ * @returns Promise resolving to the registration transaction result
211
+ * @requires Signature - This method requires a transaction signature
212
+ */
213
+ register_consumer(wallet_address, consumer_address, consumer_description) {
214
+ return register_consumer(this.getContext(), wallet_address, consumer_address, consumer_description);
215
+ }
216
+ delete_consumer(wallet_address, consumer_address) {
217
+ return delete_consumer(this.getContext(), wallet_address, consumer_address);
218
+ }
219
+ update_consumer(wallet_address, consumer_address, consumer_description) {
220
+ return update_consumer(this.getContext(), wallet_address, consumer_address, consumer_description);
221
+ }
222
+ // Unit methods
223
+ /**
224
+ * Registers a new storage unit in the system
225
+ * @param wallet_address - Address of the wallet registering the unit
226
+ * @param provider_address - Address of the provider owning the unit
227
+ * @param capacity - Capacity of the storage unit in gigabytes
228
+ * @param endpoint - Endpoint for the storage unit
229
+ * @returns Promise resolving to the registration transaction result
230
+ * @requires Signature - This method requires a transaction signature
231
+ */
232
+ register_unit(wallet_address, provider_address, capacity, endpoint) {
233
+ return register_unit(this.getContext(), wallet_address, provider_address, capacity, endpoint);
234
+ }
235
+ /**
236
+ * Deletes a storage unit from the system
237
+ * @param wallet_address - Address of the wallet making the request
238
+ * @param provider_address - Address of the provider owning the unit
239
+ * @param unit_id - Identifier of the storage unit
240
+ * @returns Promise resolving to the deletion transaction result
241
+ * @requires Signature - This method requires a transaction signature
242
+ * @throws Will throw if unit has active reservations
243
+ */
244
+ delete_unit(wallet_address, provider_address, unit_id) {
245
+ return delete_unit(this.getContext(), wallet_address, provider_address, unit_id);
246
+ }
247
+ /**
248
+ * Places a storage unit into maintenance mode
249
+ * @param wallet_address - Address of the wallet making the request
250
+ * @param provider_address - Address of the provider owning the unit
251
+ * @param unit_id - Identifier of the storage unit
252
+ * @param maintenance_start - Start date of maintenance period
253
+ * @param maintenance_end - End date of maintenance period
254
+ * @returns Promise resolving to the maintenance transaction result
255
+ * @requires Signature - This method requires a transaction signature
256
+ * @throws Will throw if unit has active reservations that conflict with the maintenance window
257
+ */
258
+ enter_maintenance(wallet_address, provider_address, unit_id, maintenance_start, maintenance_end) {
259
+ return enter_maintenance(this.getContext(), wallet_address, provider_address, unit_id, maintenance_start, maintenance_end);
260
+ }
261
+ /**
262
+ * Exits maintenance mode for a storage unit
263
+ * @param wallet_address - Address of the wallet making the request
264
+ * @param provider_address - Address of the provider owning the unit
265
+ * @param unit_id - Identifier of the storage unit
266
+ * @returns Promise resolving to the maintenance exit transaction result
267
+ * @requires Signature - This method requires a transaction signature
268
+ * @throws Will throw if unit is not in maintenance mode
269
+ */
270
+ exit_maintenance(wallet_address, provider_address, unit_id) {
271
+ return exit_maintenance(this.getContext(), wallet_address, provider_address, unit_id);
272
+ }
273
+ /**
274
+ * Places a storage unit into decommissioning mode
275
+ * This starts the process of removing the unit from service.
276
+ * @param wallet_address - Address of the wallet making the request
277
+ * @param provider_address - Address of the provider owning the unit
278
+ * @param unit_id - Identifier of the storage unit
279
+ * @returns Promise resolving to the decommissioning transaction result
280
+ * @requires Signature - This method requires a transaction signature
281
+ * @throws Will throw if unit has active reservations
282
+ */
283
+ enter_decommissioning(wallet_address, provider_address, unit_id) {
284
+ return enter_decommissioning(this.getContext(), wallet_address, provider_address, unit_id);
285
+ }
286
+ /**
287
+ * Exits decommissioning mode for a storage unit
288
+ * This cancels the decommissioning process and returns the unit to service.
289
+ * @param wallet_address - Address of the wallet making the request
290
+ * @param provider_address - Address of the provider owning the unit
291
+ * @param unit_id - Identifier of the storage unit
292
+ * @returns Promise resolving to the decommissioning exit transaction result
293
+ * @requires Signature - This method requires a transaction signature
294
+ * @throws Will throw if unit is not in decommissioning mode
295
+ */
296
+ exit_decommissioning(wallet_address, provider_address, unit_id) {
297
+ return exit_decommissioning(this.getContext(), wallet_address, provider_address, unit_id);
298
+ }
299
+ /**
300
+ * Creates a new storage reservation
301
+ * @param wallet_address - Address of the wallet making the request
302
+ * @param consumer_address - Address of the consumer requesting storage
303
+ * @param unit_id - Identifier of the storage unit to reserve
304
+ * @param reserved_gb - Amount of storage to reserve in gigabytes
305
+ * @returns Promise resolving to the reservation creation transaction result
306
+ * @requires Signature - This method requires a transaction signature
307
+ * @throws Will throw if unit doesn't have enough available capacity
308
+ * @throws Will throw if unit is in maintenance or decommissioning mode
309
+ */
310
+ reserve_unit(wallet_address, consumer_address, unit_id, reserved_gb) {
311
+ return create_reservation(this.getContext(), wallet_address, consumer_address, unit_id, reserved_gb);
312
+ }
313
+ /**
314
+ * Deletes an existing reservation
315
+ * @param wallet_address - Address of the wallet making the request
316
+ * @param consumer_address - Address of the consumer who owns the reservation
317
+ * @param reservation_id - Identifier of the reservation to delete
318
+ * @returns Promise resolving to the reservation deletion transaction result
319
+ * @requires Signature - This method requires a transaction signature
320
+ * @throws Will throw if reservation has non-zero inuse_bytes
321
+ */
322
+ delete_reservation(wallet_address, consumer_address, reservation_id) {
323
+ return delete_reservation(this.getContext(), wallet_address, consumer_address, reservation_id);
324
+ }
325
+ /**
326
+ * Updates the amount of storage currently in use by a consumer
327
+ * @param wallet_address - Address of the wallet making the request
328
+ * @param consumer_address - Address of the consumer
329
+ * @param reservation_id - Identifier of the reservation
330
+ * @param inuse_bytes - Current number of bytes in use
331
+ * @returns Promise resolving to the update transaction result
332
+ * @requires Signature - This method requires a transaction signature
333
+ * @throws Will throw if inuse_bytes exceeds reserved amount
334
+ */
335
+ update_inuse_bytes_consumer(wallet_address, consumer_address, reservation_id, inuse_bytes) {
336
+ return update_inuse_bytes_consumer(this.getContext(), wallet_address, consumer_address, reservation_id, inuse_bytes);
337
+ }
338
+ /**
339
+ * Updates the amount of storage currently in use, reported by provider
340
+ * @param wallet_address - Address of the wallet making the request
341
+ * @param provider_address - Address of the provider
342
+ * @param reservation_id - Identifier of the reservation
343
+ * @param inuse_bytes - Current number of bytes in use
344
+ * @returns Promise resolving to the update transaction result
345
+ * @requires Signature - This method requires a transaction signature
346
+ * @throws Will throw if inuse_bytes exceeds reserved amount
347
+ * @throws Will throw if provider's report differs significantly from consumer's report
348
+ */
349
+ update_inuse_bytes_provider(wallet_address, provider_address, reservation_id, inuse_bytes) {
350
+ return update_inuse_bytes_provider(this.getContext(), wallet_address, provider_address, reservation_id, inuse_bytes);
351
+ }
352
+ }
353
+ __decorate([
354
+ requiresSignature,
355
+ __metadata("design:type", Function),
356
+ __metadata("design:paramtypes", [String, String, String]),
357
+ __metadata("design:returntype", void 0)
358
+ ], FlashOnStellarClient.prototype, "register_provider", null);
359
+ __decorate([
360
+ requiresSignature,
361
+ __metadata("design:type", Function),
362
+ __metadata("design:paramtypes", [String, String]),
363
+ __metadata("design:returntype", void 0)
364
+ ], FlashOnStellarClient.prototype, "delete_provider", null);
365
+ __decorate([
366
+ requiresSignature,
367
+ __metadata("design:type", Function),
368
+ __metadata("design:paramtypes", [String, String, String]),
369
+ __metadata("design:returntype", void 0)
370
+ ], FlashOnStellarClient.prototype, "update_provider", null);
371
+ __decorate([
372
+ requiresSignature,
373
+ __metadata("design:type", Function),
374
+ __metadata("design:paramtypes", [String, String, String]),
375
+ __metadata("design:returntype", void 0)
376
+ ], FlashOnStellarClient.prototype, "register_consumer", null);
377
+ __decorate([
378
+ requiresSignature,
379
+ __metadata("design:type", Function),
380
+ __metadata("design:paramtypes", [String, String]),
381
+ __metadata("design:returntype", void 0)
382
+ ], FlashOnStellarClient.prototype, "delete_consumer", null);
383
+ __decorate([
384
+ requiresSignature,
385
+ __metadata("design:type", Function),
386
+ __metadata("design:paramtypes", [String, String, String]),
387
+ __metadata("design:returntype", void 0)
388
+ ], FlashOnStellarClient.prototype, "update_consumer", null);
389
+ __decorate([
390
+ requiresSignature,
391
+ __metadata("design:type", Function),
392
+ __metadata("design:paramtypes", [String, String, Number, String]),
393
+ __metadata("design:returntype", void 0)
394
+ ], FlashOnStellarClient.prototype, "register_unit", null);
395
+ __decorate([
396
+ requiresSignature,
397
+ __metadata("design:type", Function),
398
+ __metadata("design:paramtypes", [String, String, Number]),
399
+ __metadata("design:returntype", void 0)
400
+ ], FlashOnStellarClient.prototype, "delete_unit", null);
401
+ __decorate([
402
+ requiresSignature,
403
+ __metadata("design:type", Function),
404
+ __metadata("design:paramtypes", [String, String, Number, Date,
405
+ Date]),
406
+ __metadata("design:returntype", void 0)
407
+ ], FlashOnStellarClient.prototype, "enter_maintenance", null);
408
+ __decorate([
409
+ requiresSignature,
410
+ __metadata("design:type", Function),
411
+ __metadata("design:paramtypes", [String, String, Number]),
412
+ __metadata("design:returntype", void 0)
413
+ ], FlashOnStellarClient.prototype, "exit_maintenance", null);
414
+ __decorate([
415
+ requiresSignature,
416
+ __metadata("design:type", Function),
417
+ __metadata("design:paramtypes", [String, String, Number]),
418
+ __metadata("design:returntype", void 0)
419
+ ], FlashOnStellarClient.prototype, "enter_decommissioning", null);
420
+ __decorate([
421
+ requiresSignature,
422
+ __metadata("design:type", Function),
423
+ __metadata("design:paramtypes", [String, String, Number]),
424
+ __metadata("design:returntype", void 0)
425
+ ], FlashOnStellarClient.prototype, "exit_decommissioning", null);
426
+ __decorate([
427
+ requiresSignature,
428
+ __metadata("design:type", Function),
429
+ __metadata("design:paramtypes", [String, String, Number, Number]),
430
+ __metadata("design:returntype", void 0)
431
+ ], FlashOnStellarClient.prototype, "reserve_unit", null);
432
+ __decorate([
433
+ requiresSignature,
434
+ __metadata("design:type", Function),
435
+ __metadata("design:paramtypes", [String, String, Number]),
436
+ __metadata("design:returntype", void 0)
437
+ ], FlashOnStellarClient.prototype, "delete_reservation", null);
438
+ __decorate([
439
+ requiresSignature,
440
+ __metadata("design:type", Function),
441
+ __metadata("design:paramtypes", [String, String, Number, Number]),
442
+ __metadata("design:returntype", void 0)
443
+ ], FlashOnStellarClient.prototype, "update_inuse_bytes_consumer", null);
444
+ __decorate([
445
+ requiresSignature,
446
+ __metadata("design:type", Function),
447
+ __metadata("design:paramtypes", [String, String, Number, Number]),
448
+ __metadata("design:returntype", void 0)
449
+ ], FlashOnStellarClient.prototype, "update_inuse_bytes_provider", null);
450
+ export { FlashOnStellarClient };
@@ -0,0 +1,10 @@
1
+ import { ClientContext } from './client.js';
2
+ import { StorageConsumer, StorageReservation } from './models.js';
3
+ declare const get_consumer: (context: ClientContext, wallet_address: string, consumer_address: string, load_reservations?: boolean) => Promise<StorageConsumer | null>;
4
+ declare const get_consumers: (context: ClientContext, wallet_address: string, skip?: number, take?: number) => Promise<Map<string, StorageConsumer>>;
5
+ declare const get_consumer_count: (context: ClientContext, wallet_address: string) => Promise<number>;
6
+ declare const get_consumer_reservations: (context: ClientContext, wallet_address: string, consumer_address: string) => Promise<Map<number, StorageReservation>>;
7
+ declare const register_consumer: (context: ClientContext, wallet_address: string, consumer_address: string, consumer_description: string) => Promise<void>;
8
+ declare const delete_consumer: (context: ClientContext, wallet_address: string, consumer_address: string) => Promise<void>;
9
+ declare const update_consumer: (context: ClientContext, wallet_address: string, consumer_address: string, consumer_description: string) => Promise<void>;
10
+ export { get_consumer, get_consumers, get_consumer_count, get_consumer_reservations, register_consumer, delete_consumer, update_consumer, };
@@ -0,0 +1,77 @@
1
+ import { prepareTransaction, sendTransaction } from './transaction.js';
2
+ const get_consumer = async (context, wallet_address, consumer_address, load_reservations = false) => {
3
+ const [consumer, reservations] = await Promise.all([
4
+ prepareTransaction(context, wallet_address, {
5
+ method: 'get_consumer',
6
+ args: [{ value: consumer_address, type: 'address' }],
7
+ }),
8
+ load_reservations
9
+ ? get_consumer_reservations(context, wallet_address, consumer_address)
10
+ : new Map(),
11
+ ]);
12
+ const typedConsumerData = consumer.isSuccess ? consumer.result : null;
13
+ if (typedConsumerData) {
14
+ typedConsumerData.reservations = reservations;
15
+ }
16
+ return typedConsumerData;
17
+ };
18
+ const get_consumers = async (context, wallet_address, skip = 0, take = 10) => {
19
+ const response = await prepareTransaction(context, wallet_address, {
20
+ method: 'get_consumers',
21
+ args: [
22
+ { value: skip, type: 'u32' },
23
+ { value: take, type: 'u32' },
24
+ ],
25
+ });
26
+ if (!response.isSuccess) {
27
+ return new Map();
28
+ }
29
+ // Convert the plain object to a Map
30
+ const consumersObj = response.result;
31
+ return new Map(Object.entries(consumersObj));
32
+ };
33
+ const get_consumer_count = async (context, wallet_address) => {
34
+ const response = await prepareTransaction(context, wallet_address, {
35
+ method: 'get_consumer_count',
36
+ });
37
+ return response.isSuccess ? response.result : 0;
38
+ };
39
+ const get_consumer_reservations = async (context, wallet_address, consumer_address) => {
40
+ const response = await prepareTransaction(context, wallet_address, {
41
+ method: 'get_consumer_reservations',
42
+ args: [{ value: consumer_address, type: 'address' }],
43
+ });
44
+ const typedConsumerReservations = response.isSuccess
45
+ ? response.result
46
+ : new Map();
47
+ return typedConsumerReservations;
48
+ };
49
+ const executeConsumerTransaction = async (context, wallet_address, consumer_address, method, additionalArgs = []) => {
50
+ const isOwner = wallet_address !== consumer_address;
51
+ const response = await prepareTransaction(context, wallet_address, {
52
+ method,
53
+ args: [
54
+ { value: consumer_address, type: 'address' },
55
+ ...additionalArgs,
56
+ { value: isOwner, type: 'bool' },
57
+ ],
58
+ });
59
+ if (response.isSuccess && !response.isReadOnly) {
60
+ const signedTxXDR = await context.signTransaction(response.result);
61
+ await sendTransaction(context, signedTxXDR);
62
+ }
63
+ };
64
+ const register_consumer = async (context, wallet_address, consumer_address, consumer_description) => {
65
+ await executeConsumerTransaction(context, wallet_address, consumer_address, 'register_consumer', [
66
+ { value: consumer_description, type: 'string' },
67
+ ]);
68
+ };
69
+ const delete_consumer = async (context, wallet_address, consumer_address) => {
70
+ await executeConsumerTransaction(context, wallet_address, consumer_address, 'delete_consumer');
71
+ };
72
+ const update_consumer = async (context, wallet_address, consumer_address, consumer_description) => {
73
+ await executeConsumerTransaction(context, wallet_address, consumer_address, 'update_consumer', [
74
+ { value: consumer_description, type: 'string' },
75
+ ]);
76
+ };
77
+ export { get_consumer, get_consumers, get_consumer_count, get_consumer_reservations, register_consumer, delete_consumer, update_consumer, };
@@ -0,0 +1 @@
1
+ export declare function requiresSignature(target: any, propertyKey: string | symbol, descriptor?: PropertyDescriptor): any;
@@ -0,0 +1,30 @@
1
+ export function requiresSignature(target, propertyKey, descriptor) {
2
+ if (descriptor) {
3
+ // Method decorator
4
+ const originalMethod = descriptor.value;
5
+ descriptor.value = function (...args) {
6
+ const context = this.getContext();
7
+ if (!context.signTransaction) {
8
+ throw new Error('FlashOnStellarClient: signTransaction method is required for write operations');
9
+ }
10
+ return originalMethod.apply(this, args);
11
+ };
12
+ return descriptor;
13
+ }
14
+ // Property decorator (for arrow functions)
15
+ const propertyDescriptor = {
16
+ configurable: true,
17
+ enumerable: true,
18
+ get() {
19
+ const value = target[propertyKey];
20
+ return (...args) => {
21
+ const context = this.getContext();
22
+ if (!context.signTransaction) {
23
+ throw new Error('FlashOnStellarClient: signTransaction method is required for write operations');
24
+ }
25
+ return value.apply(this, args);
26
+ };
27
+ },
28
+ };
29
+ Object.defineProperty(target, propertyKey, propertyDescriptor);
30
+ }
@@ -0,0 +1,4 @@
1
+ import { StellarNetwork } from './transaction.js';
2
+ import { FlashOnStellarClient, FlashOnStellarClientConfig } from './client.js';
3
+ export type * from './models.js';
4
+ export { StellarNetwork, FlashOnStellarClient, FlashOnStellarClientConfig };
@@ -0,0 +1,2 @@
1
+ import { FlashOnStellarClient } from './client.js';
2
+ export { FlashOnStellarClient };
@@ -0,0 +1,55 @@
1
+ interface StorageConsumer {
2
+ description: string;
3
+ reputation: number;
4
+ registered_ts: number;
5
+ last_update_ts: number;
6
+ reservations: Map<number, StorageReservation>;
7
+ reservations_count: number;
8
+ }
9
+ type StorageReservationStatus = 'Reserved' | 'In Use' | 'Maintenance' | 'Decommissioning';
10
+ interface StorageReservation {
11
+ unit_id: number;
12
+ consumer_id: string;
13
+ status: StorageReservationStatus | StorageReservationStatus[];
14
+ reserved_gb: number;
15
+ inuse_bytes_consumer: bigint;
16
+ inuse_bytes_consumer_ts: bigint;
17
+ inuse_bytes_provider: bigint;
18
+ inuse_bytes_provider_ts: bigint;
19
+ creation_ts: number;
20
+ }
21
+ type StorageUnitStatus = 'Available' | 'Reserved' | 'In Use' | 'Maintenance' | 'Decommissioning';
22
+ type DeletionStatus = 'ReservationInUse' | 'UnitInUse' | 'UnitNotDecommissioned' | 'Unauthorized' | 'NotFound' | 'Success';
23
+ interface StorageUnit {
24
+ provider_id: string;
25
+ address: string;
26
+ status: StorageUnitStatus | StorageUnitStatus[];
27
+ last_update_ts: number;
28
+ maintenance_start_ts: number;
29
+ maintenance_end_ts: number;
30
+ previous_status: StorageUnitStatus | StorageUnitStatus[];
31
+ capacity_gb: number;
32
+ reserved_gb: number;
33
+ inuse_bytes_provider: number;
34
+ inuse_bytes_provider_ts: number;
35
+ reservations_count: number;
36
+ reservations: Map<number, StorageReservation>;
37
+ }
38
+ interface StorageProvider {
39
+ units: Map<number, StorageUnit>;
40
+ description: string;
41
+ reputation: number;
42
+ registered_ts: number;
43
+ last_update_ts: number;
44
+ units_count: number;
45
+ }
46
+ interface ContractStats {
47
+ unit_count: number;
48
+ total_capacity_gb: number;
49
+ total_reserved_gb: number;
50
+ total_inuse_bytes_consumer: number;
51
+ total_inuse_bytes_provider: number;
52
+ total_maintenance_gb: number;
53
+ total_decommissioning_gb: number;
54
+ }
55
+ export type { StorageConsumer, StorageReservation, StorageUnit, StorageProvider, ContractStats, StorageUnitStatus, StorageReservationStatus, DeletionStatus, };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { ClientContext } from './client.js';
2
+ import { StorageProvider, StorageUnit } from './models.js';
3
+ declare const get_provider: (context: ClientContext, wallet_address: string, provider_address: string, load_units?: boolean) => Promise<StorageProvider | null>;
4
+ declare const get_provider_units: (context: ClientContext, wallet_address: string, provider_address: string) => Promise<Map<number, StorageUnit>>;
5
+ declare const get_providers: (context: ClientContext, wallet_address: string, skip?: number, take?: number) => Promise<Map<string, StorageProvider>>;
6
+ declare const get_provider_count: (context: ClientContext, wallet_address: string) => Promise<number>;
7
+ declare const register_provider: (context: ClientContext, wallet_address: string, provider_address: string, provider_description: string) => Promise<void>;
8
+ declare const delete_provider: (context: ClientContext, wallet_address: string, provider_address: string) => Promise<void>;
9
+ declare const update_provider: (context: ClientContext, wallet_address: string, provider_address: string, provider_description: string) => Promise<void>;
10
+ export { get_provider, get_provider_units, get_providers, get_provider_count, register_provider, delete_provider, update_provider, };