@flashbacktech/flashbackclient 0.1.33 → 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 +4 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { StellarNetwork } from '../wallet/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
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
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;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ClientContext } from '.';
|
|
2
|
+
import { Provider } from '../models';
|
|
3
|
+
/**
|
|
4
|
+
* Provider operations client for FlashOnStellar V2
|
|
5
|
+
* Implements all provider-related contract methods
|
|
6
|
+
*/
|
|
7
|
+
export declare class ProviderOps {
|
|
8
|
+
private context;
|
|
9
|
+
constructor(context: ClientContext);
|
|
10
|
+
/**
|
|
11
|
+
* Registers a new provider in the system
|
|
12
|
+
* @param provider_id - Address of the provider to register
|
|
13
|
+
* @param description - Description of the provider
|
|
14
|
+
* @returns Promise resolving to the registration result
|
|
15
|
+
*/
|
|
16
|
+
registerProvider: (provider_id: string, description: string) => Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Updates an existing provider's information
|
|
19
|
+
* @param provider_id - Address of the provider to update
|
|
20
|
+
* @param description - New description for the provider
|
|
21
|
+
* @returns Promise resolving to the update result
|
|
22
|
+
*/
|
|
23
|
+
updateProvider: (provider_id: string, description: string) => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Deletes a provider from the system
|
|
26
|
+
* @param provider_id - Address of the provider to delete
|
|
27
|
+
* @returns Promise resolving to the deletion result
|
|
28
|
+
*/
|
|
29
|
+
deleteProvider: (provider_id: string) => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves provider information
|
|
32
|
+
* @param provider_id - Address of the provider to retrieve
|
|
33
|
+
* @returns Promise resolving to Provider object or null if not found
|
|
34
|
+
*/
|
|
35
|
+
getProvider(provider_id: string): Promise<Provider | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the total count of providers in the system
|
|
38
|
+
* @returns Promise resolving to the total number of providers
|
|
39
|
+
*/
|
|
40
|
+
getProviderCount(): Promise<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves a paginated list of providers
|
|
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 provider addresses to Provider objects
|
|
46
|
+
*/
|
|
47
|
+
getProviders(skip?: number, take?: number): Promise<Map<string, Provider>>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets all buckets associated with a provider
|
|
50
|
+
* @param provider_id - Address of the provider
|
|
51
|
+
* @returns Promise resolving to an array of bucket IDs
|
|
52
|
+
*/
|
|
53
|
+
getProviderBuckets(provider_id: string): Promise<string[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Gets all deals associated with a provider
|
|
56
|
+
* @param provider_id - Address of the provider
|
|
57
|
+
* @returns Promise resolving to an array of deal IDs
|
|
58
|
+
*/
|
|
59
|
+
getProviderDeals(provider_id: string): Promise<string[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets all active deals associated with a provider
|
|
62
|
+
* @param provider_id - Address of the provider
|
|
63
|
+
* @returns Promise resolving to an array of active deal IDs
|
|
64
|
+
*/
|
|
65
|
+
getProviderActiveDeals(provider_id: string): Promise<string[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the total number of units (buckets) owned by a provider
|
|
68
|
+
* @param provider_id - Address of the provider
|
|
69
|
+
* @returns Promise resolving to the total number of units
|
|
70
|
+
*/
|
|
71
|
+
getProviderUnitsCount(provider_id: string): Promise<number>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderOps = void 0;
|
|
4
|
+
const transaction_1 = require("../wallet/transaction");
|
|
5
|
+
const decorator_1 = require("../utils/decorator");
|
|
6
|
+
/**
|
|
7
|
+
* Provider operations client for FlashOnStellar V2
|
|
8
|
+
* Implements all provider-related contract methods
|
|
9
|
+
*/
|
|
10
|
+
class ProviderOps {
|
|
11
|
+
constructor(context) {
|
|
12
|
+
/**
|
|
13
|
+
* Registers a new provider in the system
|
|
14
|
+
* @param provider_id - Address of the provider to register
|
|
15
|
+
* @param description - Description of the provider
|
|
16
|
+
* @returns Promise resolving to the registration result
|
|
17
|
+
*/
|
|
18
|
+
this.registerProvider = (0, decorator_1.withSignature)(async (provider_id, description) => {
|
|
19
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "register_provider", [
|
|
20
|
+
{ value: provider_id, type: 'address' },
|
|
21
|
+
{ value: description, type: 'string' }
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Updates an existing provider's information
|
|
26
|
+
* @param provider_id - Address of the provider to update
|
|
27
|
+
* @param description - New description for the provider
|
|
28
|
+
* @returns Promise resolving to the update result
|
|
29
|
+
*/
|
|
30
|
+
this.updateProvider = (0, decorator_1.withSignature)(async (provider_id, description) => {
|
|
31
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "update_provider", [
|
|
32
|
+
{ value: provider_id, type: 'address' },
|
|
33
|
+
{ value: description, type: 'string' }
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Deletes a provider from the system
|
|
38
|
+
* @param provider_id - Address of the provider to delete
|
|
39
|
+
* @returns Promise resolving to the deletion result
|
|
40
|
+
*/
|
|
41
|
+
this.deleteProvider = (0, decorator_1.withSignature)(async (provider_id) => {
|
|
42
|
+
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "delete_provider", [
|
|
43
|
+
{ value: provider_id, type: 'address' }
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
this.context = context;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves provider information
|
|
50
|
+
* @param provider_id - Address of the provider to retrieve
|
|
51
|
+
* @returns Promise resolving to Provider object or null if not found
|
|
52
|
+
*/
|
|
53
|
+
async getProvider(provider_id) {
|
|
54
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, provider_id, {
|
|
55
|
+
method: 'get_provider',
|
|
56
|
+
args: [
|
|
57
|
+
{ value: provider_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 providers in the system
|
|
71
|
+
* @returns Promise resolving to the total number of providers
|
|
72
|
+
*/
|
|
73
|
+
async getProviderCount() {
|
|
74
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
75
|
+
method: 'get_provider_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 providers
|
|
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 provider addresses to Provider objects
|
|
92
|
+
*/
|
|
93
|
+
async getProviders(skip = 0, take = 10) {
|
|
94
|
+
const response = await (0, transaction_1.prepareTransaction)(this.context, '', {
|
|
95
|
+
method: 'get_providers',
|
|
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, Provider>
|
|
107
|
+
const providerMap = new Map();
|
|
108
|
+
// Note: The actual conversion depends on how the contract returns the data
|
|
109
|
+
// This is a placeholder implementation
|
|
110
|
+
return providerMap;
|
|
111
|
+
}
|
|
112
|
+
return new Map();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets all buckets associated with a provider
|
|
116
|
+
* @param provider_id - Address of the provider
|
|
117
|
+
* @returns Promise resolving to an array of bucket IDs
|
|
118
|
+
*/
|
|
119
|
+
async getProviderBuckets(provider_id) {
|
|
120
|
+
const provider = await this.getProvider(provider_id);
|
|
121
|
+
if (!provider) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
// Extract bucket IDs from the provider's buckets map
|
|
125
|
+
const bucketIds = [];
|
|
126
|
+
provider.buckets.forEach((_, bucketId) => {
|
|
127
|
+
bucketIds.push(bucketId);
|
|
128
|
+
});
|
|
129
|
+
return bucketIds;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets all deals associated with a provider
|
|
133
|
+
* @param provider_id - Address of the provider
|
|
134
|
+
* @returns Promise resolving to an array of deal IDs
|
|
135
|
+
*/
|
|
136
|
+
async getProviderDeals(provider_id) {
|
|
137
|
+
const provider = await this.getProvider(provider_id);
|
|
138
|
+
if (!provider) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
// Extract deal IDs from the provider's deals map
|
|
142
|
+
const dealIds = [];
|
|
143
|
+
provider.deals.forEach((_, dealId) => {
|
|
144
|
+
dealIds.push(dealId);
|
|
145
|
+
});
|
|
146
|
+
return dealIds;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Gets all active deals associated with a provider
|
|
150
|
+
* @param provider_id - Address of the provider
|
|
151
|
+
* @returns Promise resolving to an array of active deal IDs
|
|
152
|
+
*/
|
|
153
|
+
async getProviderActiveDeals(provider_id) {
|
|
154
|
+
const provider = await this.getProvider(provider_id);
|
|
155
|
+
if (!provider) {
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
// Extract active deal IDs from the provider's active_deals map
|
|
159
|
+
const activeDealIds = [];
|
|
160
|
+
provider.active_deals.forEach((_, dealId) => {
|
|
161
|
+
activeDealIds.push(dealId);
|
|
162
|
+
});
|
|
163
|
+
return activeDealIds;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Gets the total number of units (buckets) owned by a provider
|
|
167
|
+
* @param provider_id - Address of the provider
|
|
168
|
+
* @returns Promise resolving to the total number of units
|
|
169
|
+
*/
|
|
170
|
+
async getProviderUnitsCount(provider_id) {
|
|
171
|
+
const provider = await this.getProvider(provider_id);
|
|
172
|
+
if (!provider) {
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
return provider.units_count;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.ProviderOps = ProviderOps;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { StellarNetwork } from './transaction';
|
|
1
|
+
import { StellarNetwork } from './wallet/transaction';
|
|
2
2
|
import { FlashOnStellarClientV2, FlashOnStellarClientConfigV2 } from './client';
|
|
3
|
-
export { ConsumerOps } from './consumer';
|
|
4
|
-
export { ProviderOps } from './provider';
|
|
5
|
-
export { BucketOps } from './bucket';
|
|
6
|
-
export { DealOps } from './deal';
|
|
7
|
-
export { FundingOps } from './funding';
|
|
3
|
+
export { ConsumerOps } from './client/consumer';
|
|
4
|
+
export { ProviderOps } from './client/provider';
|
|
5
|
+
export { BucketOps } from './client/bucket';
|
|
6
|
+
export { DealOps } from './client/deal';
|
|
7
|
+
export { FundingOps } from './client/funding';
|
|
8
8
|
export * from './models';
|
|
9
9
|
export { StellarNetwork, FlashOnStellarClientV2, FlashOnStellarClientConfigV2 };
|
package/dist/stellarv2/index.js
CHANGED
|
@@ -18,15 +18,15 @@ exports.FlashOnStellarClientV2 = exports.FundingOps = exports.DealOps = exports.
|
|
|
18
18
|
const client_1 = require("./client");
|
|
19
19
|
Object.defineProperty(exports, "FlashOnStellarClientV2", { enumerable: true, get: function () { return client_1.FlashOnStellarClientV2; } });
|
|
20
20
|
// Export operation classes
|
|
21
|
-
var consumer_1 = require("./consumer");
|
|
21
|
+
var consumer_1 = require("./client/consumer");
|
|
22
22
|
Object.defineProperty(exports, "ConsumerOps", { enumerable: true, get: function () { return consumer_1.ConsumerOps; } });
|
|
23
|
-
var provider_1 = require("./provider");
|
|
23
|
+
var provider_1 = require("./client/provider");
|
|
24
24
|
Object.defineProperty(exports, "ProviderOps", { enumerable: true, get: function () { return provider_1.ProviderOps; } });
|
|
25
|
-
var bucket_1 = require("./bucket");
|
|
25
|
+
var bucket_1 = require("./client/bucket");
|
|
26
26
|
Object.defineProperty(exports, "BucketOps", { enumerable: true, get: function () { return bucket_1.BucketOps; } });
|
|
27
|
-
var deal_1 = require("./deal");
|
|
27
|
+
var deal_1 = require("./client/deal");
|
|
28
28
|
Object.defineProperty(exports, "DealOps", { enumerable: true, get: function () { return deal_1.DealOps; } });
|
|
29
|
-
var funding_1 = require("./funding");
|
|
29
|
+
var funding_1 = require("./client/funding");
|
|
30
30
|
Object.defineProperty(exports, "FundingOps", { enumerable: true, get: function () { return funding_1.FundingOps; } });
|
|
31
31
|
// Export models and types
|
|
32
32
|
__exportStar(require("./models"), exports);
|