@flashbacktech/flashbackclient 0.1.34 → 0.1.35
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/dist/stellarv2/client/bucket.d.ts +111 -0
- package/dist/stellarv2/client/bucket.js +272 -0
- package/dist/stellarv2/client/consumer.d.ts +60 -0
- package/dist/stellarv2/client/consumer.js +149 -0
- package/dist/stellarv2/client/deal.d.ts +160 -0
- package/dist/stellarv2/client/deal.js +356 -0
- package/dist/stellarv2/client/funding.d.ts +46 -0
- package/dist/stellarv2/client/funding.js +78 -0
- package/dist/stellarv2/client/index.d.ts +134 -0
- package/dist/stellarv2/client/index.js +240 -0
- package/dist/stellarv2/client/provider.d.ts +72 -0
- package/dist/stellarv2/client/provider.js +178 -0
- package/dist/stellarv2/index.d.ts +6 -6
- package/dist/stellarv2/index.js +5 -5
- package/dist/stellarv2/utils/decorator.d.ts +2 -0
- package/dist/stellarv2/utils/decorator.js +30 -0
- package/dist/stellarv2/utils/lib.d.ts +13 -0
- package/dist/stellarv2/utils/lib.js +26 -0
- package/dist/stellarv2/utils/timing.d.ts +1 -0
- package/dist/stellarv2/utils/timing.js +19 -0
- package/dist/stellarv2/wallet/balance.d.ts +2 -0
- package/dist/stellarv2/wallet/balance.js +9 -0
- package/dist/stellarv2/wallet/batch.d.ts +44 -0
- package/dist/stellarv2/wallet/batch.js +77 -0
- package/dist/stellarv2/wallet/index.d.ts +4 -0
- package/dist/stellarv2/wallet/index.js +20 -0
- package/dist/stellarv2/wallet/token.d.ts +3 -0
- package/dist/stellarv2/wallet/token.js +23 -0
- package/dist/stellarv2/wallet/transaction.d.ts +38 -0
- package/dist/stellarv2/wallet/transaction.js +224 -0
- package/package.json +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ClientContext } from '.';
|
|
2
|
+
import { Bucket, BucketCreateParams, BucketUpdateBasicParams, BucketUpdatePricingParams, BucketUpdateSLAParams } from '../models';
|
|
3
|
+
/**
|
|
4
|
+
* Bucket operations client for FlashOnStellar V2
|
|
5
|
+
* Implements all bucket-related contract methods
|
|
6
|
+
*/
|
|
7
|
+
export declare class BucketOps {
|
|
8
|
+
private context;
|
|
9
|
+
constructor(context: ClientContext);
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new bucket for a provider
|
|
12
|
+
* @param provider_id - Address of the provider creating the bucket
|
|
13
|
+
* @param params - Bucket creation parameters
|
|
14
|
+
* @returns Promise resolving to the created bucket ID
|
|
15
|
+
*/
|
|
16
|
+
createBucket: (provider_id: string, params: BucketCreateParams) => Promise<number>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a bucket from an existing bucket object
|
|
19
|
+
* @param bucket - Existing bucket object to clone
|
|
20
|
+
* @returns Promise resolving to the created bucket ID
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Updates basic bucket information (name, region, country)
|
|
24
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
25
|
+
* @param bucket_id - ID of the bucket to update
|
|
26
|
+
* @param params - Basic update parameters
|
|
27
|
+
* @returns Promise resolving to the update result
|
|
28
|
+
*/
|
|
29
|
+
updateBucketBasic: (provider_id: string, bucket_id: number, params: BucketUpdateBasicParams) => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Updates bucket pricing and capacity information
|
|
32
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
33
|
+
* @param bucket_id - ID of the bucket to update
|
|
34
|
+
* @param params - Pricing update parameters
|
|
35
|
+
* @returns Promise resolving to the update result
|
|
36
|
+
*/
|
|
37
|
+
updateBucketPricing: (provider_id: string, bucket_id: number, params: BucketUpdatePricingParams) => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Updates bucket SLA information
|
|
40
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
41
|
+
* @param bucket_id - ID of the bucket to update
|
|
42
|
+
* @param params - SLA update parameters
|
|
43
|
+
* @returns Promise resolving to the update result
|
|
44
|
+
*/
|
|
45
|
+
updateBucketSLA: (provider_id: string, bucket_id: number, params: BucketUpdateSLAParams) => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Locks a bucket to prevent modifications during active deals
|
|
48
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
49
|
+
* @param bucket_id - ID of the bucket to lock
|
|
50
|
+
* @returns Promise resolving to the lock result
|
|
51
|
+
*/
|
|
52
|
+
lockBucket: (provider_id: string, bucket_id: number) => Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Unlocks a bucket to allow modifications
|
|
55
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
56
|
+
* @param bucket_id - ID of the bucket to unlock
|
|
57
|
+
* @returns Promise resolving to the unlock result
|
|
58
|
+
*/
|
|
59
|
+
unlockBucket: (provider_id: string, bucket_id: number) => Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Deletes a bucket from the system
|
|
62
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
63
|
+
* @param bucket_id - ID of the bucket to delete
|
|
64
|
+
* @returns Promise resolving to the deletion result
|
|
65
|
+
*/
|
|
66
|
+
deleteBucket: (provider_id: string, bucket_id: number) => Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves bucket information
|
|
69
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
70
|
+
* @param bucket_id - ID of the bucket to retrieve
|
|
71
|
+
* @returns Promise resolving to Bucket object or null if not found
|
|
72
|
+
*/
|
|
73
|
+
getBucket(provider_id: string, bucket_id: number): Promise<Bucket | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the total count of buckets in the system
|
|
76
|
+
* @returns Promise resolving to the total number of buckets
|
|
77
|
+
*/
|
|
78
|
+
getBucketCount(): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves a paginated list of all buckets
|
|
81
|
+
* @param skip - Number of items to skip for pagination
|
|
82
|
+
* @param take - Number of items to take per page
|
|
83
|
+
* @returns Promise resolving to an array of Bucket objects
|
|
84
|
+
*/
|
|
85
|
+
getBuckets(skip?: number, take?: number): Promise<Bucket[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves all buckets owned by a specific provider
|
|
88
|
+
* @param provider_id - Address of the provider
|
|
89
|
+
* @returns Promise resolving to an array of Bucket objects
|
|
90
|
+
*/
|
|
91
|
+
getBucketsByProvider(provider_id: string): Promise<Bucket[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Checks if a bucket is locked
|
|
94
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
95
|
+
* @param bucket_id - ID of the bucket to check
|
|
96
|
+
* @returns Promise resolving to true if the bucket is locked, false otherwise
|
|
97
|
+
*/
|
|
98
|
+
isBucketLocked(provider_id: string, bucket_id: number): Promise<boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Gets bucket pricing information
|
|
101
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
102
|
+
* @param bucket_id - ID of the bucket
|
|
103
|
+
* @returns Promise resolving to pricing information or null if bucket not found
|
|
104
|
+
*/
|
|
105
|
+
getBucketPricing(provider_id: string, bucket_id: number): Promise<{
|
|
106
|
+
price_per_gb_storage: bigint;
|
|
107
|
+
price_per_gb_egress: bigint;
|
|
108
|
+
max_storage_gb: number;
|
|
109
|
+
max_egress_gb: number;
|
|
110
|
+
} | null>;
|
|
111
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BucketOps = void 0;
|
|
4
|
+
const transaction_1 = require("../wallet/transaction");
|
|
5
|
+
const decorator_1 = require("../utils/decorator");
|
|
6
|
+
/**
|
|
7
|
+
* Bucket operations client for FlashOnStellar V2
|
|
8
|
+
* Implements all bucket-related contract methods
|
|
9
|
+
*/
|
|
10
|
+
class BucketOps {
|
|
11
|
+
constructor(context) {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new bucket for a provider
|
|
14
|
+
* @param provider_id - Address of the provider creating the bucket
|
|
15
|
+
* @param params - Bucket creation parameters
|
|
16
|
+
* @returns Promise resolving to the created bucket ID
|
|
17
|
+
*/
|
|
18
|
+
this.createBucket = (0, decorator_1.withSignature)(async (provider_id, params) => {
|
|
19
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, provider_id, {
|
|
20
|
+
method: 'create_bucket',
|
|
21
|
+
args: [
|
|
22
|
+
{ value: provider_id, type: 'address' },
|
|
23
|
+
{ value: params.name, type: 'string' },
|
|
24
|
+
{ value: params.region, type: 'string' },
|
|
25
|
+
{ value: params.country, type: 'string' },
|
|
26
|
+
{ value: params.versioning_enabled, type: 'bool' },
|
|
27
|
+
{ value: params.fb_bucket_id, type: 'string' },
|
|
28
|
+
{ value: params.api_compatibility, type: 'string' },
|
|
29
|
+
{ value: params.price_per_gb_storage, type: 'u128' },
|
|
30
|
+
{ value: params.price_per_gb_egress, type: 'u128' }
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
if (!response.isSuccess) {
|
|
34
|
+
throw new Error('Failed to create bucket');
|
|
35
|
+
}
|
|
36
|
+
const result = response.result;
|
|
37
|
+
if (typeof result === 'number') {
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
throw new Error('Failed to create bucket');
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Creates a bucket from an existing bucket object
|
|
44
|
+
* @param bucket - Existing bucket object to clone
|
|
45
|
+
* @returns Promise resolving to the created bucket ID
|
|
46
|
+
*/
|
|
47
|
+
/*
|
|
48
|
+
createFromBucket = withSignature(
|
|
49
|
+
async (bucket: Bucket): Promise<number> => {
|
|
50
|
+
const response = await prepareTransaction(this.context, bucket.provider_id, {
|
|
51
|
+
method: 'create_from_bucket',
|
|
52
|
+
args: [
|
|
53
|
+
{ value: bucket, type: 'string' } // Note: This might need adjustment based on how the contract expects the bucket parameter
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (!response.isSuccess) {
|
|
58
|
+
throw new Error('Failed to create bucket from existing bucket');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const result = response.result;
|
|
62
|
+
if (typeof result === 'number') {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
throw new Error('Failed to create bucket from existing bucket');
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* Updates basic bucket information (name, region, country)
|
|
71
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
72
|
+
* @param bucket_id - ID of the bucket to update
|
|
73
|
+
* @param params - Basic update parameters
|
|
74
|
+
* @returns Promise resolving to the update result
|
|
75
|
+
*/
|
|
76
|
+
this.updateBucketBasic = (0, decorator_1.withSignature)(async (provider_id, bucket_id, params) => {
|
|
77
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "update_bucket_basic", [
|
|
78
|
+
{ value: provider_id, type: 'address' },
|
|
79
|
+
{ value: bucket_id, type: 'u32' },
|
|
80
|
+
{ value: params.name || null, type: 'string' },
|
|
81
|
+
{ value: params.region || null, type: 'string' },
|
|
82
|
+
{ value: params.country || null, type: 'string' }
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Updates bucket pricing and capacity information
|
|
87
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
88
|
+
* @param bucket_id - ID of the bucket to update
|
|
89
|
+
* @param params - Pricing update parameters
|
|
90
|
+
* @returns Promise resolving to the update result
|
|
91
|
+
*/
|
|
92
|
+
this.updateBucketPricing = (0, decorator_1.withSignature)(async (provider_id, bucket_id, params) => {
|
|
93
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "update_bucket_pricing", [
|
|
94
|
+
{ value: provider_id, type: 'address' },
|
|
95
|
+
{ value: bucket_id, type: 'u32' },
|
|
96
|
+
{ value: params.price_per_gb_storage || null, type: 'u128' },
|
|
97
|
+
{ value: params.price_per_gb_egress || null, type: 'u128' },
|
|
98
|
+
{ value: params.max_storage_gb || null, type: 'u32' },
|
|
99
|
+
{ value: params.max_egress_gb || null, type: 'u32' }
|
|
100
|
+
]);
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* Updates bucket SLA information
|
|
104
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
105
|
+
* @param bucket_id - ID of the bucket to update
|
|
106
|
+
* @param params - SLA update parameters
|
|
107
|
+
* @returns Promise resolving to the update result
|
|
108
|
+
*/
|
|
109
|
+
this.updateBucketSLA = (0, decorator_1.withSignature)(async (provider_id, bucket_id, params) => {
|
|
110
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "update_bucket_sla", [
|
|
111
|
+
{ value: provider_id, type: 'address' },
|
|
112
|
+
{ value: bucket_id, type: 'u32' },
|
|
113
|
+
{ value: params.sla_avg_latency_ms || null, type: 'u32' },
|
|
114
|
+
{ value: params.sla_avg_uptime_pct || null, type: 'u32' }
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Locks a bucket to prevent modifications during active deals
|
|
119
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
120
|
+
* @param bucket_id - ID of the bucket to lock
|
|
121
|
+
* @returns Promise resolving to the lock result
|
|
122
|
+
*/
|
|
123
|
+
this.lockBucket = (0, decorator_1.withSignature)(async (provider_id, bucket_id) => {
|
|
124
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "lock_bucket", [
|
|
125
|
+
{ value: provider_id, type: 'address' },
|
|
126
|
+
{ value: bucket_id, type: 'u32' }
|
|
127
|
+
]);
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* Unlocks a bucket to allow modifications
|
|
131
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
132
|
+
* @param bucket_id - ID of the bucket to unlock
|
|
133
|
+
* @returns Promise resolving to the unlock result
|
|
134
|
+
*/
|
|
135
|
+
this.unlockBucket = (0, decorator_1.withSignature)(async (provider_id, bucket_id) => {
|
|
136
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "unlock_bucket", [
|
|
137
|
+
{ value: provider_id, type: 'address' },
|
|
138
|
+
{ value: bucket_id, type: 'u32' }
|
|
139
|
+
]);
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* Deletes a bucket from the system
|
|
143
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
144
|
+
* @param bucket_id - ID of the bucket to delete
|
|
145
|
+
* @returns Promise resolving to the deletion result
|
|
146
|
+
*/
|
|
147
|
+
this.deleteBucket = (0, decorator_1.withSignature)(async (provider_id, bucket_id) => {
|
|
148
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "delete_bucket", [
|
|
149
|
+
{ value: provider_id, type: 'address' },
|
|
150
|
+
{ value: bucket_id, type: 'u32' }
|
|
151
|
+
]);
|
|
152
|
+
});
|
|
153
|
+
this.context = context;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Retrieves bucket information
|
|
157
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
158
|
+
* @param bucket_id - ID of the bucket to retrieve
|
|
159
|
+
* @returns Promise resolving to Bucket object or null if not found
|
|
160
|
+
*/
|
|
161
|
+
async getBucket(provider_id, bucket_id) {
|
|
162
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, provider_id, {
|
|
163
|
+
method: 'get_bucket',
|
|
164
|
+
args: [
|
|
165
|
+
{ value: provider_id, type: 'address' },
|
|
166
|
+
{ value: bucket_id, type: 'u32' }
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
if (!response.isSuccess) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const result = response.result;
|
|
173
|
+
if (result && typeof result === 'object') {
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gets the total count of buckets in the system
|
|
180
|
+
* @returns Promise resolving to the total number of buckets
|
|
181
|
+
*/
|
|
182
|
+
async getBucketCount() {
|
|
183
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
184
|
+
method: 'get_bucket_count',
|
|
185
|
+
args: []
|
|
186
|
+
});
|
|
187
|
+
if (!response.isSuccess) {
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
const result = response.result;
|
|
191
|
+
if (typeof result === 'number') {
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves a paginated list of all buckets
|
|
198
|
+
* @param skip - Number of items to skip for pagination
|
|
199
|
+
* @param take - Number of items to take per page
|
|
200
|
+
* @returns Promise resolving to an array of Bucket objects
|
|
201
|
+
*/
|
|
202
|
+
async getBuckets(skip = 0, take = 10) {
|
|
203
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
204
|
+
method: 'get_buckets',
|
|
205
|
+
args: [
|
|
206
|
+
{ value: skip, type: 'u32' },
|
|
207
|
+
{ value: take, type: 'u32' }
|
|
208
|
+
]
|
|
209
|
+
});
|
|
210
|
+
if (!response.isSuccess) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
const result = response.result;
|
|
214
|
+
if (Array.isArray(result)) {
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Retrieves all buckets owned by a specific provider
|
|
221
|
+
* @param provider_id - Address of the provider
|
|
222
|
+
* @returns Promise resolving to an array of Bucket objects
|
|
223
|
+
*/
|
|
224
|
+
async getBucketsByProvider(provider_id) {
|
|
225
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, provider_id, {
|
|
226
|
+
method: 'get_buckets_by_provider',
|
|
227
|
+
args: [
|
|
228
|
+
{ value: provider_id, type: 'address' }
|
|
229
|
+
]
|
|
230
|
+
});
|
|
231
|
+
if (!response.isSuccess) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
const result = response.result;
|
|
235
|
+
if (Array.isArray(result)) {
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Checks if a bucket is locked
|
|
242
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
243
|
+
* @param bucket_id - ID of the bucket to check
|
|
244
|
+
* @returns Promise resolving to true if the bucket is locked, false otherwise
|
|
245
|
+
*/
|
|
246
|
+
async isBucketLocked(provider_id, bucket_id) {
|
|
247
|
+
const bucket = await this.getBucket(provider_id, bucket_id);
|
|
248
|
+
if (!bucket) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return bucket.locked;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Gets bucket pricing information
|
|
255
|
+
* @param provider_id - Address of the provider owning the bucket
|
|
256
|
+
* @param bucket_id - ID of the bucket
|
|
257
|
+
* @returns Promise resolving to pricing information or null if bucket not found
|
|
258
|
+
*/
|
|
259
|
+
async getBucketPricing(provider_id, bucket_id) {
|
|
260
|
+
const bucket = await this.getBucket(provider_id, bucket_id);
|
|
261
|
+
if (!bucket) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
price_per_gb_storage: bucket.price_per_gb_storage,
|
|
266
|
+
price_per_gb_egress: bucket.price_per_gb_egress,
|
|
267
|
+
max_storage_gb: bucket.max_storage_gb,
|
|
268
|
+
max_egress_gb: bucket.max_egress_gb
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.BucketOps = BucketOps;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ClientContext } from '.';
|
|
2
|
+
import { Consumer } from '../models';
|
|
3
|
+
/**
|
|
4
|
+
* Consumer operations client for FlashOnStellar V2
|
|
5
|
+
* Implements all consumer-related contract methods
|
|
6
|
+
*/
|
|
7
|
+
export declare class ConsumerOps {
|
|
8
|
+
private context;
|
|
9
|
+
constructor(context: ClientContext);
|
|
10
|
+
/**
|
|
11
|
+
* Registers a new consumer in the system
|
|
12
|
+
* @param consumer_id - Address of the consumer to register
|
|
13
|
+
* @param description - Description of the consumer
|
|
14
|
+
* @returns Promise resolving to the registration result
|
|
15
|
+
*/
|
|
16
|
+
registerConsumer: (consumer_id: string, description: string) => Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Updates an existing consumer's information
|
|
19
|
+
* @param consumer_id - Address of the consumer to update
|
|
20
|
+
* @param description - New description for the consumer
|
|
21
|
+
* @returns Promise resolving to the update result
|
|
22
|
+
*/
|
|
23
|
+
updateConsumer: (consumer_id: string, description: string) => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Deletes a consumer from the system
|
|
26
|
+
* @param consumer_id - Address of the consumer to delete
|
|
27
|
+
* @returns Promise resolving to the deletion result
|
|
28
|
+
*/
|
|
29
|
+
deleteConsumer: (consumer_id: string) => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves consumer information
|
|
32
|
+
* @param consumer_id - Address of the consumer to retrieve
|
|
33
|
+
* @returns Promise resolving to Consumer object or null if not found
|
|
34
|
+
*/
|
|
35
|
+
getConsumer(consumer_id: string): Promise<Consumer | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the total count of consumers in the system
|
|
38
|
+
* @returns Promise resolving to the total number of consumers
|
|
39
|
+
*/
|
|
40
|
+
getConsumerCount(): Promise<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves a paginated list of consumers
|
|
43
|
+
* @param skip - Number of items to skip for pagination
|
|
44
|
+
* @param take - Number of items to take per page
|
|
45
|
+
* @returns Promise resolving to a map of consumer addresses to Consumer objects
|
|
46
|
+
*/
|
|
47
|
+
getConsumers(skip?: number, take?: number): Promise<Map<string, Consumer>>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets all deals associated with a consumer
|
|
50
|
+
* @param consumer_id - Address of the consumer
|
|
51
|
+
* @returns Promise resolving to an array of deal IDs
|
|
52
|
+
*/
|
|
53
|
+
getConsumerDeals(consumer_id: string): Promise<string[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Gets all active deals associated with a consumer
|
|
56
|
+
* @param consumer_id - Address of the consumer
|
|
57
|
+
* @returns Promise resolving to an array of active deal IDs
|
|
58
|
+
*/
|
|
59
|
+
getConsumerActiveDeals(consumer_id: string): Promise<string[]>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsumerOps = void 0;
|
|
4
|
+
const transaction_1 = require("../wallet/transaction");
|
|
5
|
+
const decorator_1 = require("../utils/decorator");
|
|
6
|
+
/**
|
|
7
|
+
* Consumer operations client for FlashOnStellar V2
|
|
8
|
+
* Implements all consumer-related contract methods
|
|
9
|
+
*/
|
|
10
|
+
class ConsumerOps {
|
|
11
|
+
constructor(context) {
|
|
12
|
+
/**
|
|
13
|
+
* Registers a new consumer in the system
|
|
14
|
+
* @param consumer_id - Address of the consumer to register
|
|
15
|
+
* @param description - Description of the consumer
|
|
16
|
+
* @returns Promise resolving to the registration result
|
|
17
|
+
*/
|
|
18
|
+
this.registerConsumer = (0, decorator_1.withSignature)(async (consumer_id, description) => {
|
|
19
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, consumer_id, "register_consumer", [
|
|
20
|
+
{ value: consumer_id, type: 'address' },
|
|
21
|
+
{ value: description, type: 'string' }
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Updates an existing consumer's information
|
|
26
|
+
* @param consumer_id - Address of the consumer to update
|
|
27
|
+
* @param description - New description for the consumer
|
|
28
|
+
* @returns Promise resolving to the update result
|
|
29
|
+
*/
|
|
30
|
+
this.updateConsumer = (0, decorator_1.withSignature)(async (consumer_id, description) => {
|
|
31
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, consumer_id, "update_consumer", [
|
|
32
|
+
{ value: consumer_id, type: 'address' },
|
|
33
|
+
{ value: description, type: 'string' }
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Deletes a consumer from the system
|
|
38
|
+
* @param consumer_id - Address of the consumer to delete
|
|
39
|
+
* @returns Promise resolving to the deletion result
|
|
40
|
+
*/
|
|
41
|
+
this.deleteConsumer = (0, decorator_1.withSignature)(async (consumer_id) => {
|
|
42
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, consumer_id, "delete_consumer", [
|
|
43
|
+
{ value: consumer_id, type: 'address' }
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
this.context = context;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves consumer information
|
|
50
|
+
* @param consumer_id - Address of the consumer to retrieve
|
|
51
|
+
* @returns Promise resolving to Consumer object or null if not found
|
|
52
|
+
*/
|
|
53
|
+
async getConsumer(consumer_id) {
|
|
54
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, consumer_id, {
|
|
55
|
+
method: 'get_consumer',
|
|
56
|
+
args: [
|
|
57
|
+
{ value: consumer_id, type: 'address' }
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
if (!response.isSuccess) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const result = response.result;
|
|
64
|
+
if (result && typeof result === 'object') {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the total count of consumers in the system
|
|
71
|
+
* @returns Promise resolving to the total number of consumers
|
|
72
|
+
*/
|
|
73
|
+
async getConsumerCount() {
|
|
74
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
75
|
+
method: 'get_consumer_count',
|
|
76
|
+
args: []
|
|
77
|
+
});
|
|
78
|
+
if (!response.isSuccess) {
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
const result = response.result;
|
|
82
|
+
if (typeof result === 'number') {
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves a paginated list of consumers
|
|
89
|
+
* @param skip - Number of items to skip for pagination
|
|
90
|
+
* @param take - Number of items to take per page
|
|
91
|
+
* @returns Promise resolving to a map of consumer addresses to Consumer objects
|
|
92
|
+
*/
|
|
93
|
+
async getConsumers(skip = 0, take = 10) {
|
|
94
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
95
|
+
method: 'get_consumers',
|
|
96
|
+
args: [
|
|
97
|
+
{ value: skip, type: 'u32' },
|
|
98
|
+
{ value: take, type: 'u32' }
|
|
99
|
+
]
|
|
100
|
+
});
|
|
101
|
+
if (!response.isSuccess) {
|
|
102
|
+
return new Map();
|
|
103
|
+
}
|
|
104
|
+
const result = response.result;
|
|
105
|
+
if (result && typeof result === 'object') {
|
|
106
|
+
// Convert the result to a Map<string, Consumer>
|
|
107
|
+
const consumerMap = new Map();
|
|
108
|
+
// Note: The actual conversion depends on how the contract returns the data
|
|
109
|
+
// This is a placeholder implementation
|
|
110
|
+
return consumerMap;
|
|
111
|
+
}
|
|
112
|
+
return new Map();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets all deals associated with a consumer
|
|
116
|
+
* @param consumer_id - Address of the consumer
|
|
117
|
+
* @returns Promise resolving to an array of deal IDs
|
|
118
|
+
*/
|
|
119
|
+
async getConsumerDeals(consumer_id) {
|
|
120
|
+
const consumer = await this.getConsumer(consumer_id);
|
|
121
|
+
if (!consumer) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
// Extract deal IDs from the consumer's deals map
|
|
125
|
+
const dealIds = [];
|
|
126
|
+
consumer.deals.forEach((_, dealId) => {
|
|
127
|
+
dealIds.push(dealId);
|
|
128
|
+
});
|
|
129
|
+
return dealIds;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets all active deals associated with a consumer
|
|
133
|
+
* @param consumer_id - Address of the consumer
|
|
134
|
+
* @returns Promise resolving to an array of active deal IDs
|
|
135
|
+
*/
|
|
136
|
+
async getConsumerActiveDeals(consumer_id) {
|
|
137
|
+
const consumer = await this.getConsumer(consumer_id);
|
|
138
|
+
if (!consumer) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
// Extract active deal IDs from the consumer's active_deals map
|
|
142
|
+
const activeDealIds = [];
|
|
143
|
+
consumer.active_deals.forEach((_, dealId) => {
|
|
144
|
+
activeDealIds.push(dealId);
|
|
145
|
+
});
|
|
146
|
+
return activeDealIds;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.ConsumerOps = ConsumerOps;
|