@flashbacktech/flashbackclient 0.1.28 → 0.1.31
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/api/client.d.ts +7 -2
- package/dist/api/client.js +10 -4
- package/dist/api/types/auth.d.ts +6 -0
- package/dist/stellarv2/bucket.d.ts +111 -0
- package/dist/stellarv2/bucket.js +262 -0
- package/dist/stellarv2/client.d.ts +134 -0
- package/dist/stellarv2/client.js +240 -0
- package/dist/stellarv2/consumer.d.ts +60 -0
- package/dist/stellarv2/consumer.js +145 -0
- package/dist/stellarv2/deal.d.ts +160 -0
- package/dist/stellarv2/deal.js +357 -0
- package/dist/stellarv2/funding.d.ts +46 -0
- package/dist/stellarv2/funding.js +86 -0
- package/dist/stellarv2/index.d.ts +9 -0
- package/dist/stellarv2/index.js +32 -0
- package/dist/stellarv2/models.d.ts +149 -0
- package/dist/stellarv2/models.js +49 -0
- package/dist/stellarv2/provider.d.ts +72 -0
- package/dist/stellarv2/provider.js +174 -0
- package/dist/stellarv2/transaction.d.ts +36 -0
- package/dist/stellarv2/transaction.js +168 -0
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CreateUnitRequest, CreateUnitResponse, CreateRepoRequest, CreateRepoResponse, StorageUnit, CreateRepoKeyRequest, CreateRepoKeyResponse, GetUnitsResponse, GetReposResponse, GetRepoKeysResponse, UpdateUnitRequest, UpdateUnitResponse, ActionResponse, UpdateRepoRequest, UpdateRepoResponse, UpdateRepoKeyRequest, UpdateRepoKeyResponse, ValidateUnitRequest, ValidateUnitResponse, ValidateRepoUnitsRequest, ValidateRepoUnitsResponse, StorageUnitStatusResponse, GetUnitNodeStatsResponse, GetUnitNodeStatsRequest, CreateBucketRequest, CreateBucketResponse, UpdateBucketRequest, UpdateBucketResponse, ValidateBucketRequest, ValidateBucketResponse, StorageBucket, GetBucketsResponse, StorageBucketStatusResponse, GetBucketNodeStatsRequest, GetBucketNodeStatsResponse, CreateRepoWithBucketsRequest, UpdateRepoWithBucketsRequest, ValidateRepoBucketsRequest, ValidateRepoBucketsResponse } from './types/storage';
|
|
2
2
|
import { IApiClient, ProviderType } from './interfaces';
|
|
3
|
-
import { ActivateResponse, DeactivateResponse, LoginBody, LoginResponse, LogoutResponse, OAuth2ResponseDTO, RefreshTokenErrorResponse, RefreshTokenResponse, RegisterBody, RegisterResponse, ResetPasswordBody } from './types/auth';
|
|
3
|
+
import { ActivateResponse, DeactivateResponse, LoginBody, LoginResponse, LogoutResponse, OAuth2ResponseDTO, RefreshTokenErrorResponse, RefreshTokenResponse, RegisterBody, RegisterResponse, ResetPasswordBody, Web3RegisterBody } from './types/auth';
|
|
4
4
|
import { StatsQueryParams, StatsResponse, NodeStatsMinuteResponse, NodeStatsDailyResponse, NodeStatsQueryParams, UnitStatsResponse, RepoStatsResponse, NodeStatsDailyQueryParams, BucketStatsResponse, StatsQueryWithBucketParams, NodeStatsQueryWithBucketParams, NodeStatsDailyQueryWithBucketParams } from './types/stats';
|
|
5
5
|
import { NodeInfo } from './types/bridge';
|
|
6
6
|
import { QuotaResponse } from './types/quota';
|
|
@@ -33,10 +33,15 @@ export declare class ApiClient implements IApiClient {
|
|
|
33
33
|
* @returns The refreshed token
|
|
34
34
|
*/
|
|
35
35
|
refreshToken: (refreshToken: string, provider: ProviderType) => Promise<RefreshTokenResponse | RefreshTokenErrorResponse>;
|
|
36
|
-
private authenticateWeb3Stellar;
|
|
37
36
|
private makeRequest;
|
|
38
37
|
private authenticateGoogle;
|
|
39
38
|
private authenticateGithub;
|
|
39
|
+
/**
|
|
40
|
+
* Authenticate with a web3 provider
|
|
41
|
+
* @param data - The data to authenticate with
|
|
42
|
+
* @returns The authentication response
|
|
43
|
+
*/
|
|
44
|
+
web3Authenticate: (data: Web3RegisterBody) => Promise<any>;
|
|
40
45
|
private refreshGoogleToken;
|
|
41
46
|
private refreshGithubToken;
|
|
42
47
|
private exchangeGoogleCode;
|
package/dist/api/client.js
CHANGED
|
@@ -33,7 +33,7 @@ class ApiClient {
|
|
|
33
33
|
case interfaces_1.ProviderType.GITHUB:
|
|
34
34
|
return this.authenticateGithub(token);
|
|
35
35
|
case interfaces_1.ProviderType.WEB3_STELLAR:
|
|
36
|
-
|
|
36
|
+
throw new Error('Call web3Authenticate for web3 authentication');
|
|
37
37
|
case interfaces_1.ProviderType.LOCAL:
|
|
38
38
|
throw new Error('Call userLogin for local authentication');
|
|
39
39
|
default:
|
|
@@ -71,14 +71,12 @@ class ApiClient {
|
|
|
71
71
|
case interfaces_1.ProviderType.GITHUB:
|
|
72
72
|
return this.refreshGithubToken(refreshToken);
|
|
73
73
|
case interfaces_1.ProviderType.LOCAL:
|
|
74
|
+
case interfaces_1.ProviderType.WEB3_STELLAR:
|
|
74
75
|
return this.userRefresh(refreshToken);
|
|
75
76
|
default:
|
|
76
77
|
throw new Error(`Unsupported provider: ${provider}`);
|
|
77
78
|
}
|
|
78
79
|
};
|
|
79
|
-
this.authenticateWeb3Stellar = async (token) => {
|
|
80
|
-
throw new Error('Not implemented');
|
|
81
|
-
};
|
|
82
80
|
this.makeRequest = async (path, method, data) => {
|
|
83
81
|
const isFormData = data instanceof FormData;
|
|
84
82
|
const options = {
|
|
@@ -136,6 +134,14 @@ class ApiClient {
|
|
|
136
134
|
this.setAuthToken(code);
|
|
137
135
|
return this.makeRequest('auth/github', 'POST', { code });
|
|
138
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* Authenticate with a web3 provider
|
|
139
|
+
* @param data - The data to authenticate with
|
|
140
|
+
* @returns The authentication response
|
|
141
|
+
*/
|
|
142
|
+
this.web3Authenticate = async (data) => {
|
|
143
|
+
return this.makeRequest('auth/web3', 'POST', data);
|
|
144
|
+
};
|
|
139
145
|
this.refreshGoogleToken = async (refreshToken) => {
|
|
140
146
|
return this.makeRequest('auth/google/refresh', 'POST', {
|
|
141
147
|
refresh_token: refreshToken,
|
package/dist/api/types/auth.d.ts
CHANGED
|
@@ -35,6 +35,12 @@ export interface JwtPayload {
|
|
|
35
35
|
iat?: number;
|
|
36
36
|
exp?: number;
|
|
37
37
|
}
|
|
38
|
+
export interface Web3RegisterBody {
|
|
39
|
+
address: string;
|
|
40
|
+
network: string;
|
|
41
|
+
signature: string;
|
|
42
|
+
nonce: string;
|
|
43
|
+
}
|
|
38
44
|
export interface RegisterBody {
|
|
39
45
|
email: string;
|
|
40
46
|
password: string;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ClientContext } from './client';
|
|
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<boolean>;
|
|
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<boolean>;
|
|
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<boolean>;
|
|
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<boolean>;
|
|
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<boolean>;
|
|
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<boolean>;
|
|
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,262 @@
|
|
|
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;
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
}
|