@flashbacktech/flashbackclient 0.1.39 → 0.1.40
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/wallet/transaction.js +0 -1
- package/package.json +1 -1
- package/dist/api/types.d.ts +0 -89
- package/dist/api/types.js +0 -20
- package/dist/consumer/file/delete.d.ts +0 -3
- package/dist/consumer/file/delete.js +0 -23
- package/dist/consumer/file/getUrl.d.ts +0 -3
- package/dist/consumer/file/getUrl.js +0 -20
- package/dist/consumer/file/index.d.ts +0 -30
- package/dist/consumer/file/index.js +0 -52
- package/dist/consumer/file/types.d.ts +0 -25
- package/dist/consumer/file/types.js +0 -2
- package/dist/consumer/file/upload.d.ts +0 -3
- package/dist/consumer/file/upload.js +0 -75
- package/dist/consumer/index.d.ts +0 -1
- package/dist/consumer/index.js +0 -17
- package/dist/stellar/client.d.ts +0 -282
- package/dist/stellar/client.js +0 -453
- package/dist/stellar/consumer.d.ts +0 -10
- package/dist/stellar/consumer.js +0 -86
- package/dist/stellar/decorator.d.ts +0 -1
- package/dist/stellar/decorator.js +0 -33
- package/dist/stellar/index.d.ts +0 -4
- package/dist/stellar/index.js +0 -5
- package/dist/stellar/models.d.ts +0 -55
- package/dist/stellar/models.js +0 -2
- package/dist/stellar/provider.d.ts +0 -10
- package/dist/stellar/provider.js +0 -86
- package/dist/stellar/reservation.d.ts +0 -8
- package/dist/stellar/reservation.js +0 -61
- package/dist/stellar/stats.d.ts +0 -4
- package/dist/stellar/stats.js +0 -12
- package/dist/stellar/transaction.d.ts +0 -24
- package/dist/stellar/transaction.js +0 -138
- package/dist/stellar/unit.d.ts +0 -12
- package/dist/stellar/unit.js +0 -100
- package/dist/stellarv2/bucket.d.ts +0 -111
- package/dist/stellarv2/bucket.js +0 -262
- package/dist/stellarv2/client.d.ts +0 -134
- package/dist/stellarv2/client.js +0 -240
- package/dist/stellarv2/consumer.d.ts +0 -60
- package/dist/stellarv2/consumer.js +0 -145
- package/dist/stellarv2/deal.d.ts +0 -160
- package/dist/stellarv2/deal.js +0 -357
- package/dist/stellarv2/funding.d.ts +0 -46
- package/dist/stellarv2/funding.js +0 -86
- package/dist/stellarv2/provider.d.ts +0 -72
- package/dist/stellarv2/provider.js +0 -174
- package/dist/stellarv2/transaction.d.ts +0 -36
- package/dist/stellarv2/transaction.js +0 -168
package/dist/stellarv2/bucket.js
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BucketOps = void 0;
|
|
4
|
-
const transaction_1 = require("./transaction");
|
|
5
|
-
/**
|
|
6
|
-
* Bucket operations client for FlashOnStellar V2
|
|
7
|
-
* Implements all bucket-related contract methods
|
|
8
|
-
*/
|
|
9
|
-
class BucketOps {
|
|
10
|
-
constructor(context) {
|
|
11
|
-
this.context = context;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new bucket for a provider
|
|
15
|
-
* @param provider_id - Address of the provider creating the bucket
|
|
16
|
-
* @param params - Bucket creation parameters
|
|
17
|
-
* @returns Promise resolving to the created bucket ID
|
|
18
|
-
*/
|
|
19
|
-
async createBucket(provider_id, params) {
|
|
20
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
21
|
-
method: 'create_bucket',
|
|
22
|
-
args: [
|
|
23
|
-
{ value: provider_id, type: 'address' },
|
|
24
|
-
{ value: params.name, type: 'string' },
|
|
25
|
-
{ value: params.region, type: 'string' },
|
|
26
|
-
{ value: params.country, type: 'string' },
|
|
27
|
-
{ value: params.versioning_enabled, type: 'bool' },
|
|
28
|
-
{ value: params.fb_bucket_id, type: 'string' },
|
|
29
|
-
{ value: params.api_compatibility, type: 'string' },
|
|
30
|
-
{ value: params.price_per_gb_storage, type: 'u128' },
|
|
31
|
-
{ value: params.price_per_gb_egress, type: 'u128' }
|
|
32
|
-
]
|
|
33
|
-
});
|
|
34
|
-
if (typeof result === 'number') {
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
throw new Error('Failed to create bucket');
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Creates a bucket from an existing bucket object
|
|
41
|
-
* @param bucket - Existing bucket object to clone
|
|
42
|
-
* @returns Promise resolving to the created bucket ID
|
|
43
|
-
*/
|
|
44
|
-
/*
|
|
45
|
-
async createFromBucket(bucket: Bucket): Promise<number> {
|
|
46
|
-
const result = await callContractMethod(this.context, bucket.provider_id, {
|
|
47
|
-
method: 'create_from_bucket',
|
|
48
|
-
args: [
|
|
49
|
-
{ value: bucket, type: 'string' } // Note: This might need adjustment based on how the contract expects the bucket parameter
|
|
50
|
-
]
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (typeof result === 'number') {
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
throw new Error('Failed to create bucket from existing bucket');
|
|
57
|
-
}
|
|
58
|
-
*/
|
|
59
|
-
/**
|
|
60
|
-
* Updates basic bucket information (name, region, country)
|
|
61
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
62
|
-
* @param bucket_id - ID of the bucket to update
|
|
63
|
-
* @param params - Basic update parameters
|
|
64
|
-
* @returns Promise resolving to the update result
|
|
65
|
-
*/
|
|
66
|
-
async updateBucketBasic(provider_id, bucket_id, params) {
|
|
67
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
68
|
-
method: 'update_bucket_basic',
|
|
69
|
-
args: [
|
|
70
|
-
{ value: provider_id, type: 'address' },
|
|
71
|
-
{ value: bucket_id, type: 'u32' },
|
|
72
|
-
{ value: params.name || null, type: 'string' },
|
|
73
|
-
{ value: params.region || null, type: 'string' },
|
|
74
|
-
{ value: params.country || null, type: 'string' }
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Updates bucket pricing and capacity information
|
|
80
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
81
|
-
* @param bucket_id - ID of the bucket to update
|
|
82
|
-
* @param params - Pricing update parameters
|
|
83
|
-
* @returns Promise resolving to the update result
|
|
84
|
-
*/
|
|
85
|
-
async updateBucketPricing(provider_id, bucket_id, params) {
|
|
86
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
87
|
-
method: 'update_bucket_pricing',
|
|
88
|
-
args: [
|
|
89
|
-
{ value: provider_id, type: 'address' },
|
|
90
|
-
{ value: bucket_id, type: 'u32' },
|
|
91
|
-
{ value: params.price_per_gb_storage || null, type: 'u128' },
|
|
92
|
-
{ value: params.price_per_gb_egress || null, type: 'u128' },
|
|
93
|
-
{ value: params.max_storage_gb || null, type: 'u32' },
|
|
94
|
-
{ value: params.max_egress_gb || null, type: 'u32' }
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Updates bucket SLA information
|
|
100
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
101
|
-
* @param bucket_id - ID of the bucket to update
|
|
102
|
-
* @param params - SLA update parameters
|
|
103
|
-
* @returns Promise resolving to the update result
|
|
104
|
-
*/
|
|
105
|
-
async updateBucketSLA(provider_id, bucket_id, params) {
|
|
106
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
107
|
-
method: 'update_bucket_sla',
|
|
108
|
-
args: [
|
|
109
|
-
{ value: provider_id, type: 'address' },
|
|
110
|
-
{ value: bucket_id, type: 'u32' },
|
|
111
|
-
{ value: params.sla_avg_latency_ms || null, type: 'u32' },
|
|
112
|
-
{ value: params.sla_avg_uptime_pct || null, type: 'u32' }
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Locks a bucket to prevent modifications during active deals
|
|
118
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
119
|
-
* @param bucket_id - ID of the bucket to lock
|
|
120
|
-
* @returns Promise resolving to the lock result
|
|
121
|
-
*/
|
|
122
|
-
async lockBucket(provider_id, bucket_id) {
|
|
123
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
124
|
-
method: 'lock_bucket',
|
|
125
|
-
args: [
|
|
126
|
-
{ value: provider_id, type: 'address' },
|
|
127
|
-
{ value: bucket_id, type: 'u32' }
|
|
128
|
-
]
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Unlocks a bucket to allow modifications
|
|
133
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
134
|
-
* @param bucket_id - ID of the bucket to unlock
|
|
135
|
-
* @returns Promise resolving to the unlock result
|
|
136
|
-
*/
|
|
137
|
-
async unlockBucket(provider_id, bucket_id) {
|
|
138
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
139
|
-
method: 'unlock_bucket',
|
|
140
|
-
args: [
|
|
141
|
-
{ value: provider_id, type: 'address' },
|
|
142
|
-
{ value: bucket_id, type: 'u32' }
|
|
143
|
-
]
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Deletes a bucket from the system
|
|
148
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
149
|
-
* @param bucket_id - ID of the bucket to delete
|
|
150
|
-
* @returns Promise resolving to the deletion result
|
|
151
|
-
*/
|
|
152
|
-
async deleteBucket(provider_id, bucket_id) {
|
|
153
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
154
|
-
method: 'delete_bucket',
|
|
155
|
-
args: [
|
|
156
|
-
{ value: provider_id, type: 'address' },
|
|
157
|
-
{ value: bucket_id, type: 'u32' }
|
|
158
|
-
]
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Retrieves bucket information
|
|
163
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
164
|
-
* @param bucket_id - ID of the bucket to retrieve
|
|
165
|
-
* @returns Promise resolving to Bucket object or null if not found
|
|
166
|
-
*/
|
|
167
|
-
async getBucket(provider_id, bucket_id) {
|
|
168
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
169
|
-
method: 'get_bucket',
|
|
170
|
-
args: [
|
|
171
|
-
{ value: provider_id, type: 'address' },
|
|
172
|
-
{ value: bucket_id, type: 'u32' }
|
|
173
|
-
]
|
|
174
|
-
});
|
|
175
|
-
if (result && typeof result === 'object') {
|
|
176
|
-
return result;
|
|
177
|
-
}
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Gets the total count of buckets in the system
|
|
182
|
-
* @returns Promise resolving to the total number of buckets
|
|
183
|
-
*/
|
|
184
|
-
async getBucketCount() {
|
|
185
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, '', {
|
|
186
|
-
method: 'get_bucket_count',
|
|
187
|
-
args: []
|
|
188
|
-
});
|
|
189
|
-
if (typeof result === 'number') {
|
|
190
|
-
return result;
|
|
191
|
-
}
|
|
192
|
-
return 0;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Retrieves a paginated list of all buckets
|
|
196
|
-
* @param skip - Number of items to skip for pagination
|
|
197
|
-
* @param take - Number of items to take per page
|
|
198
|
-
* @returns Promise resolving to an array of Bucket objects
|
|
199
|
-
*/
|
|
200
|
-
async getBuckets(skip = 0, take = 10) {
|
|
201
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, '', {
|
|
202
|
-
method: 'get_buckets',
|
|
203
|
-
args: [
|
|
204
|
-
{ value: skip, type: 'u32' },
|
|
205
|
-
{ value: take, type: 'u32' }
|
|
206
|
-
]
|
|
207
|
-
});
|
|
208
|
-
if (Array.isArray(result)) {
|
|
209
|
-
return result;
|
|
210
|
-
}
|
|
211
|
-
return [];
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Retrieves all buckets owned by a specific provider
|
|
215
|
-
* @param provider_id - Address of the provider
|
|
216
|
-
* @returns Promise resolving to an array of Bucket objects
|
|
217
|
-
*/
|
|
218
|
-
async getBucketsByProvider(provider_id) {
|
|
219
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
220
|
-
method: 'get_buckets_by_provider',
|
|
221
|
-
args: [
|
|
222
|
-
{ value: provider_id, type: 'address' }
|
|
223
|
-
]
|
|
224
|
-
});
|
|
225
|
-
if (Array.isArray(result)) {
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
return [];
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Checks if a bucket is locked
|
|
232
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
233
|
-
* @param bucket_id - ID of the bucket to check
|
|
234
|
-
* @returns Promise resolving to true if the bucket is locked, false otherwise
|
|
235
|
-
*/
|
|
236
|
-
async isBucketLocked(provider_id, bucket_id) {
|
|
237
|
-
const bucket = await this.getBucket(provider_id, bucket_id);
|
|
238
|
-
if (!bucket) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
return bucket.locked;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Gets bucket pricing information
|
|
245
|
-
* @param provider_id - Address of the provider owning the bucket
|
|
246
|
-
* @param bucket_id - ID of the bucket
|
|
247
|
-
* @returns Promise resolving to pricing information or null if bucket not found
|
|
248
|
-
*/
|
|
249
|
-
async getBucketPricing(provider_id, bucket_id) {
|
|
250
|
-
const bucket = await this.getBucket(provider_id, bucket_id);
|
|
251
|
-
if (!bucket) {
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
return {
|
|
255
|
-
price_per_gb_storage: bucket.price_per_gb_storage,
|
|
256
|
-
price_per_gb_egress: bucket.price_per_gb_egress,
|
|
257
|
-
max_storage_gb: bucket.max_storage_gb,
|
|
258
|
-
max_egress_gb: bucket.max_egress_gb
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
exports.BucketOps = BucketOps;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { StellarNetwork } from './transaction';
|
|
2
|
-
import { ConsumerOps } from './consumer';
|
|
3
|
-
import { ProviderOps } from './provider';
|
|
4
|
-
import { BucketOps } from './bucket';
|
|
5
|
-
import { DealOps } from './deal';
|
|
6
|
-
import { FundingOps } from './funding';
|
|
7
|
-
/**
|
|
8
|
-
* Configuration interface for the FlashOnStellar V2 client
|
|
9
|
-
*/
|
|
10
|
-
export interface FlashOnStellarClientConfigV2 {
|
|
11
|
-
/** Stellar contract address for the FlashOnStellar V2 system */
|
|
12
|
-
contractAddress: string;
|
|
13
|
-
/**
|
|
14
|
-
* Optional callback function to sign non-read Stellar transactions
|
|
15
|
-
* @param xdrToSign - The XDR-encoded transaction to sign
|
|
16
|
-
* @returns Promise resolving to the signed XDR string
|
|
17
|
-
*/
|
|
18
|
-
signTransaction?: (xdrToSign: string) => Promise<string>;
|
|
19
|
-
/** Network configuration for Stellar (testnet/public) */
|
|
20
|
-
network: StellarNetwork;
|
|
21
|
-
}
|
|
22
|
-
export type ClientContext = FlashOnStellarClientConfigV2;
|
|
23
|
-
/**
|
|
24
|
-
* Main client class for interacting with the FlashOnStellar V2 system
|
|
25
|
-
* This client provides methods for managing providers, consumers, buckets, and deals
|
|
26
|
-
* on the Stellar blockchain through organized operation classes.
|
|
27
|
-
*/
|
|
28
|
-
export declare class FlashOnStellarClientV2 {
|
|
29
|
-
private readonly signTransaction?;
|
|
30
|
-
private readonly contractAddress;
|
|
31
|
-
private readonly network;
|
|
32
|
-
readonly consumers: ConsumerOps;
|
|
33
|
-
readonly providers: ProviderOps;
|
|
34
|
-
readonly buckets: BucketOps;
|
|
35
|
-
readonly deals: DealOps;
|
|
36
|
-
readonly funding: FundingOps;
|
|
37
|
-
protected getContext(): ClientContext;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a new instance of the FlashOnStellarClient
|
|
40
|
-
* @param config - Configuration options for the client
|
|
41
|
-
*/
|
|
42
|
-
constructor(config: FlashOnStellarClientConfigV2);
|
|
43
|
-
/**
|
|
44
|
-
* Gets the contract address
|
|
45
|
-
* @returns The contract address
|
|
46
|
-
*/
|
|
47
|
-
getContractAddress(): string;
|
|
48
|
-
/**
|
|
49
|
-
* Gets the network configuration
|
|
50
|
-
* @returns The network configuration
|
|
51
|
-
*/
|
|
52
|
-
getNetwork(): StellarNetwork;
|
|
53
|
-
/**
|
|
54
|
-
* Gets the version of the contract
|
|
55
|
-
* @returns Promise resolving to the contract version
|
|
56
|
-
*/
|
|
57
|
-
getVersion(): Promise<number>;
|
|
58
|
-
/**
|
|
59
|
-
* Gets the owner address of the contract
|
|
60
|
-
* @returns Promise resolving to the owner address
|
|
61
|
-
*/
|
|
62
|
-
getOwnerAddress(): Promise<string>;
|
|
63
|
-
/**
|
|
64
|
-
* Gets the stable asset address from the contract
|
|
65
|
-
* @returns Promise resolving to the stable asset address
|
|
66
|
-
*/
|
|
67
|
-
getStableAssetAddress(): Promise<string>;
|
|
68
|
-
/**
|
|
69
|
-
* Gets the current ledger sequence
|
|
70
|
-
* @returns Promise resolving to the ledger sequence number
|
|
71
|
-
*/
|
|
72
|
-
getLedgerSequence(): Promise<number>;
|
|
73
|
-
/**
|
|
74
|
-
* Updates the owner address (owner only)
|
|
75
|
-
* @param new_owner - New owner address
|
|
76
|
-
* @returns Promise resolving to the update result
|
|
77
|
-
*/
|
|
78
|
-
updateOwner(new_owner: string): Promise<boolean>;
|
|
79
|
-
/**
|
|
80
|
-
* Sets the stable asset address (owner only)
|
|
81
|
-
* @param stable_asset_address - New stable asset address
|
|
82
|
-
* @returns Promise resolving to the update result
|
|
83
|
-
*/
|
|
84
|
-
setStableAssetAddress(stable_asset_address: string): Promise<boolean>;
|
|
85
|
-
/**
|
|
86
|
-
* Upgrades the contract (owner only)
|
|
87
|
-
* @param new_wasm_hash - Hash of the new WASM bytecode
|
|
88
|
-
* @returns Promise resolving to the upgrade result
|
|
89
|
-
*/
|
|
90
|
-
upgrade(new_wasm_hash: string): Promise<boolean>;
|
|
91
|
-
/**
|
|
92
|
-
* Gets system statistics
|
|
93
|
-
* @returns Promise resolving to system statistics
|
|
94
|
-
*/
|
|
95
|
-
getSystemStats(): Promise<{
|
|
96
|
-
consumerCount: number;
|
|
97
|
-
providerCount: number;
|
|
98
|
-
bucketCount: number;
|
|
99
|
-
dealCount: number;
|
|
100
|
-
activeDealCount: number;
|
|
101
|
-
}>;
|
|
102
|
-
/**
|
|
103
|
-
* Gets comprehensive information about a provider including their buckets and deals
|
|
104
|
-
* @param provider_id - Address of the provider
|
|
105
|
-
* @returns Promise resolving to comprehensive provider information
|
|
106
|
-
*/
|
|
107
|
-
getProviderInfo(provider_id: string): Promise<{
|
|
108
|
-
provider: any;
|
|
109
|
-
buckets: any[];
|
|
110
|
-
deals: any[];
|
|
111
|
-
activeDeals: any[];
|
|
112
|
-
} | null>;
|
|
113
|
-
/**
|
|
114
|
-
* Gets comprehensive information about a consumer including their deals
|
|
115
|
-
* @param consumer_id - Address of the consumer
|
|
116
|
-
* @returns Promise resolving to comprehensive consumer information
|
|
117
|
-
*/
|
|
118
|
-
getConsumerInfo(consumer_id: string): Promise<{
|
|
119
|
-
consumer: any;
|
|
120
|
-
deals: any[];
|
|
121
|
-
activeDeals: any[];
|
|
122
|
-
} | null>;
|
|
123
|
-
/**
|
|
124
|
-
* Gets comprehensive information about a bucket including its provider and any active deals
|
|
125
|
-
* @param provider_id - Address of the provider
|
|
126
|
-
* @param bucket_id - ID of the bucket
|
|
127
|
-
* @returns Promise resolving to comprehensive bucket information
|
|
128
|
-
*/
|
|
129
|
-
getBucketInfo(provider_id: string, bucket_id: number): Promise<{
|
|
130
|
-
bucket: any;
|
|
131
|
-
provider: any;
|
|
132
|
-
activeDeals: any[];
|
|
133
|
-
} | null>;
|
|
134
|
-
}
|
package/dist/stellarv2/client.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlashOnStellarClientV2 = void 0;
|
|
4
|
-
const consumer_1 = require("./consumer");
|
|
5
|
-
const provider_1 = require("./provider");
|
|
6
|
-
const bucket_1 = require("./bucket");
|
|
7
|
-
const deal_1 = require("./deal");
|
|
8
|
-
const funding_1 = require("./funding");
|
|
9
|
-
/**
|
|
10
|
-
* Main client class for interacting with the FlashOnStellar V2 system
|
|
11
|
-
* This client provides methods for managing providers, consumers, buckets, and deals
|
|
12
|
-
* on the Stellar blockchain through organized operation classes.
|
|
13
|
-
*/
|
|
14
|
-
class FlashOnStellarClientV2 {
|
|
15
|
-
getContext() {
|
|
16
|
-
return {
|
|
17
|
-
network: this.network,
|
|
18
|
-
signTransaction: this.signTransaction,
|
|
19
|
-
contractAddress: this.contractAddress,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new instance of the FlashOnStellarClient
|
|
24
|
-
* @param config - Configuration options for the client
|
|
25
|
-
*/
|
|
26
|
-
constructor(config) {
|
|
27
|
-
this.signTransaction = config.signTransaction;
|
|
28
|
-
this.contractAddress = config.contractAddress;
|
|
29
|
-
this.network = config.network;
|
|
30
|
-
// Initialize operation classes
|
|
31
|
-
const context = this.getContext();
|
|
32
|
-
this.consumers = new consumer_1.ConsumerOps(context);
|
|
33
|
-
this.providers = new provider_1.ProviderOps(context);
|
|
34
|
-
this.buckets = new bucket_1.BucketOps(context);
|
|
35
|
-
this.deals = new deal_1.DealOps(context);
|
|
36
|
-
this.funding = new funding_1.FundingOps(context);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Gets the contract address
|
|
40
|
-
* @returns The contract address
|
|
41
|
-
*/
|
|
42
|
-
getContractAddress() {
|
|
43
|
-
return this.contractAddress;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Gets the network configuration
|
|
47
|
-
* @returns The network configuration
|
|
48
|
-
*/
|
|
49
|
-
getNetwork() {
|
|
50
|
-
return this.network;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Gets the version of the contract
|
|
54
|
-
* @returns Promise resolving to the contract version
|
|
55
|
-
*/
|
|
56
|
-
async getVersion() {
|
|
57
|
-
// This would call the version() method on the contract
|
|
58
|
-
// Implementation depends on the transaction layer
|
|
59
|
-
throw new Error('getVersion not implemented - requires transaction layer implementation');
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Gets the owner address of the contract
|
|
63
|
-
* @returns Promise resolving to the owner address
|
|
64
|
-
*/
|
|
65
|
-
async getOwnerAddress() {
|
|
66
|
-
// This would call the get_owner_address() method on the contract
|
|
67
|
-
// Implementation depends on the transaction layer
|
|
68
|
-
throw new Error('getOwnerAddress not implemented - requires transaction layer implementation');
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Gets the stable asset address from the contract
|
|
72
|
-
* @returns Promise resolving to the stable asset address
|
|
73
|
-
*/
|
|
74
|
-
async getStableAssetAddress() {
|
|
75
|
-
// This would call the get_stable_asset_address() method on the contract
|
|
76
|
-
// Implementation depends on the transaction layer
|
|
77
|
-
throw new Error('getStableAssetAddress not implemented - requires transaction layer implementation');
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Gets the current ledger sequence
|
|
81
|
-
* @returns Promise resolving to the ledger sequence number
|
|
82
|
-
*/
|
|
83
|
-
async getLedgerSequence() {
|
|
84
|
-
// This would call the get_ledger_sequence() method on the contract
|
|
85
|
-
// Implementation depends on the transaction layer
|
|
86
|
-
throw new Error('getLedgerSequence not implemented - requires transaction layer implementation');
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Updates the owner address (owner only)
|
|
90
|
-
* @param new_owner - New owner address
|
|
91
|
-
* @returns Promise resolving to the update result
|
|
92
|
-
*/
|
|
93
|
-
async updateOwner(new_owner) {
|
|
94
|
-
// This would call the update_owner() method on the contract
|
|
95
|
-
// Implementation depends on the transaction layer
|
|
96
|
-
throw new Error('updateOwner not implemented - requires transaction layer implementation');
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Sets the stable asset address (owner only)
|
|
100
|
-
* @param stable_asset_address - New stable asset address
|
|
101
|
-
* @returns Promise resolving to the update result
|
|
102
|
-
*/
|
|
103
|
-
async setStableAssetAddress(stable_asset_address) {
|
|
104
|
-
// This would call the set_stable_asset_address() method on the contract
|
|
105
|
-
// Implementation depends on the transaction layer
|
|
106
|
-
throw new Error('setStableAssetAddress not implemented - requires transaction layer implementation');
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Upgrades the contract (owner only)
|
|
110
|
-
* @param new_wasm_hash - Hash of the new WASM bytecode
|
|
111
|
-
* @returns Promise resolving to the upgrade result
|
|
112
|
-
*/
|
|
113
|
-
async upgrade(new_wasm_hash) {
|
|
114
|
-
// This would call the upgrade() method on the contract
|
|
115
|
-
// Implementation depends on the transaction layer
|
|
116
|
-
throw new Error('upgrade not implemented - requires transaction layer implementation');
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Gets system statistics
|
|
120
|
-
* @returns Promise resolving to system statistics
|
|
121
|
-
*/
|
|
122
|
-
async getSystemStats() {
|
|
123
|
-
try {
|
|
124
|
-
const [consumerCount, providerCount, bucketCount, dealCount] = await Promise.all([
|
|
125
|
-
this.consumers.getConsumerCount(),
|
|
126
|
-
this.providers.getProviderCount(),
|
|
127
|
-
this.buckets.getBucketCount(),
|
|
128
|
-
this.deals.getDealCount()
|
|
129
|
-
]);
|
|
130
|
-
// Get active deals count
|
|
131
|
-
const activeDeals = await this.deals.getActiveDeals(0, 1000); // Get all active deals
|
|
132
|
-
const activeDealCount = activeDeals.length;
|
|
133
|
-
return {
|
|
134
|
-
consumerCount,
|
|
135
|
-
providerCount,
|
|
136
|
-
bucketCount,
|
|
137
|
-
dealCount,
|
|
138
|
-
activeDealCount
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
console.error('Error getting system stats:', error);
|
|
143
|
-
return {
|
|
144
|
-
consumerCount: 0,
|
|
145
|
-
providerCount: 0,
|
|
146
|
-
bucketCount: 0,
|
|
147
|
-
dealCount: 0,
|
|
148
|
-
activeDealCount: 0
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Gets comprehensive information about a provider including their buckets and deals
|
|
154
|
-
* @param provider_id - Address of the provider
|
|
155
|
-
* @returns Promise resolving to comprehensive provider information
|
|
156
|
-
*/
|
|
157
|
-
async getProviderInfo(provider_id) {
|
|
158
|
-
try {
|
|
159
|
-
const [provider, buckets, deals, activeDeals] = await Promise.all([
|
|
160
|
-
this.providers.getProvider(provider_id),
|
|
161
|
-
this.buckets.getBucketsByProvider(provider_id),
|
|
162
|
-
this.deals.getDealsByProvider(provider_id),
|
|
163
|
-
this.deals.getActiveDeals(0, 1000) // Get all active deals and filter by provider
|
|
164
|
-
]);
|
|
165
|
-
if (!provider) {
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
// Filter active deals for this provider
|
|
169
|
-
const providerActiveDeals = activeDeals.filter(deal => deal.provider_id === provider_id);
|
|
170
|
-
return {
|
|
171
|
-
provider,
|
|
172
|
-
buckets,
|
|
173
|
-
deals,
|
|
174
|
-
activeDeals: providerActiveDeals
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
console.error('Error getting provider info:', error);
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Gets comprehensive information about a consumer including their deals
|
|
184
|
-
* @param consumer_id - Address of the consumer
|
|
185
|
-
* @returns Promise resolving to comprehensive consumer information
|
|
186
|
-
*/
|
|
187
|
-
async getConsumerInfo(consumer_id) {
|
|
188
|
-
try {
|
|
189
|
-
const [consumer, deals, activeDeals] = await Promise.all([
|
|
190
|
-
this.consumers.getConsumer(consumer_id),
|
|
191
|
-
this.deals.getDealsByConsumer(consumer_id),
|
|
192
|
-
this.deals.getActiveDeals(0, 1000) // Get all active deals and filter by consumer
|
|
193
|
-
]);
|
|
194
|
-
if (!consumer) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
// Filter active deals for this consumer
|
|
198
|
-
const consumerActiveDeals = activeDeals.filter(deal => deal.consumer_id === consumer_id);
|
|
199
|
-
return {
|
|
200
|
-
consumer,
|
|
201
|
-
deals,
|
|
202
|
-
activeDeals: consumerActiveDeals
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
console.error('Error getting consumer info:', error);
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Gets comprehensive information about a bucket including its provider and any active deals
|
|
212
|
-
* @param provider_id - Address of the provider
|
|
213
|
-
* @param bucket_id - ID of the bucket
|
|
214
|
-
* @returns Promise resolving to comprehensive bucket information
|
|
215
|
-
*/
|
|
216
|
-
async getBucketInfo(provider_id, bucket_id) {
|
|
217
|
-
try {
|
|
218
|
-
const [bucket, provider, activeDeals] = await Promise.all([
|
|
219
|
-
this.buckets.getBucket(provider_id, bucket_id),
|
|
220
|
-
this.providers.getProvider(provider_id),
|
|
221
|
-
this.deals.getActiveDeals(0, 1000) // Get all active deals and filter by bucket
|
|
222
|
-
]);
|
|
223
|
-
if (!bucket) {
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
// Filter active deals for this bucket
|
|
227
|
-
const bucketActiveDeals = activeDeals.filter(deal => deal.bucket_id === bucket_id);
|
|
228
|
-
return {
|
|
229
|
-
bucket,
|
|
230
|
-
provider,
|
|
231
|
-
activeDeals: bucketActiveDeals
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
console.error('Error getting bucket info:', error);
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
exports.FlashOnStellarClientV2 = FlashOnStellarClientV2;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ClientContext } from './client';
|
|
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<boolean>;
|
|
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<boolean>;
|
|
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<boolean>;
|
|
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
|
-
}
|