@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
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConsumerOps = void 0;
|
|
4
|
-
const transaction_1 = require("./transaction");
|
|
5
|
-
/**
|
|
6
|
-
* Consumer operations client for FlashOnStellar V2
|
|
7
|
-
* Implements all consumer-related contract methods
|
|
8
|
-
*/
|
|
9
|
-
class ConsumerOps {
|
|
10
|
-
constructor(context) {
|
|
11
|
-
this.context = context;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Registers a new consumer in the system
|
|
15
|
-
* @param consumer_id - Address of the consumer to register
|
|
16
|
-
* @param description - Description of the consumer
|
|
17
|
-
* @returns Promise resolving to the registration result
|
|
18
|
-
*/
|
|
19
|
-
async registerConsumer(consumer_id, description) {
|
|
20
|
-
return (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
21
|
-
method: 'register_consumer',
|
|
22
|
-
args: [
|
|
23
|
-
{ value: consumer_id, type: 'address' },
|
|
24
|
-
{ value: description, type: 'string' }
|
|
25
|
-
]
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Updates an existing consumer's information
|
|
30
|
-
* @param consumer_id - Address of the consumer to update
|
|
31
|
-
* @param description - New description for the consumer
|
|
32
|
-
* @returns Promise resolving to the update result
|
|
33
|
-
*/
|
|
34
|
-
async updateConsumer(consumer_id, description) {
|
|
35
|
-
return (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
36
|
-
method: 'update_consumer',
|
|
37
|
-
args: [
|
|
38
|
-
{ value: consumer_id, type: 'address' },
|
|
39
|
-
{ value: description, type: 'string' }
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Deletes a consumer from the system
|
|
45
|
-
* @param consumer_id - Address of the consumer to delete
|
|
46
|
-
* @returns Promise resolving to the deletion result
|
|
47
|
-
*/
|
|
48
|
-
async deleteConsumer(consumer_id) {
|
|
49
|
-
return (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
50
|
-
method: 'delete_consumer',
|
|
51
|
-
args: [
|
|
52
|
-
{ value: consumer_id, type: 'address' }
|
|
53
|
-
]
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Retrieves consumer information
|
|
58
|
-
* @param consumer_id - Address of the consumer to retrieve
|
|
59
|
-
* @returns Promise resolving to Consumer object or null if not found
|
|
60
|
-
*/
|
|
61
|
-
async getConsumer(consumer_id) {
|
|
62
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
63
|
-
method: 'get_consumer',
|
|
64
|
-
args: [
|
|
65
|
-
{ value: consumer_id, type: 'address' }
|
|
66
|
-
]
|
|
67
|
-
});
|
|
68
|
-
if (result && typeof result === 'object') {
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Gets the total count of consumers in the system
|
|
75
|
-
* @returns Promise resolving to the total number of consumers
|
|
76
|
-
*/
|
|
77
|
-
async getConsumerCount() {
|
|
78
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, '', {
|
|
79
|
-
method: 'get_consumer_count',
|
|
80
|
-
args: []
|
|
81
|
-
});
|
|
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 result = await (0, transaction_1.callContractMethod)(this.context, '', {
|
|
95
|
-
method: 'get_consumers',
|
|
96
|
-
args: [
|
|
97
|
-
{ value: skip, type: 'u32' },
|
|
98
|
-
{ value: take, type: 'u32' }
|
|
99
|
-
]
|
|
100
|
-
});
|
|
101
|
-
if (result && typeof result === 'object') {
|
|
102
|
-
// Convert the result to a Map<string, Consumer>
|
|
103
|
-
const consumerMap = new Map();
|
|
104
|
-
// Note: The actual conversion depends on how the contract returns the data
|
|
105
|
-
// This is a placeholder implementation
|
|
106
|
-
return consumerMap;
|
|
107
|
-
}
|
|
108
|
-
return new Map();
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Gets all deals associated with a consumer
|
|
112
|
-
* @param consumer_id - Address of the consumer
|
|
113
|
-
* @returns Promise resolving to an array of deal IDs
|
|
114
|
-
*/
|
|
115
|
-
async getConsumerDeals(consumer_id) {
|
|
116
|
-
const consumer = await this.getConsumer(consumer_id);
|
|
117
|
-
if (!consumer) {
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
// Extract deal IDs from the consumer's deals map
|
|
121
|
-
const dealIds = [];
|
|
122
|
-
consumer.deals.forEach((_, dealId) => {
|
|
123
|
-
dealIds.push(dealId);
|
|
124
|
-
});
|
|
125
|
-
return dealIds;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Gets all active deals associated with a consumer
|
|
129
|
-
* @param consumer_id - Address of the consumer
|
|
130
|
-
* @returns Promise resolving to an array of active deal IDs
|
|
131
|
-
*/
|
|
132
|
-
async getConsumerActiveDeals(consumer_id) {
|
|
133
|
-
const consumer = await this.getConsumer(consumer_id);
|
|
134
|
-
if (!consumer) {
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
|
-
// Extract active deal IDs from the consumer's active_deals map
|
|
138
|
-
const activeDealIds = [];
|
|
139
|
-
consumer.active_deals.forEach((_, dealId) => {
|
|
140
|
-
activeDealIds.push(dealId);
|
|
141
|
-
});
|
|
142
|
-
return activeDealIds;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.ConsumerOps = ConsumerOps;
|
package/dist/stellarv2/deal.d.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { ClientContext } from './client';
|
|
2
|
-
import { Deal, DealCreateParams, DealConsumptionUpdateParams, DealSLAUpdateParams } from './models';
|
|
3
|
-
/**
|
|
4
|
-
* Deal operations client for FlashOnStellar V2
|
|
5
|
-
* Implements all deal-related contract methods
|
|
6
|
-
*/
|
|
7
|
-
export declare class DealOps {
|
|
8
|
-
private context;
|
|
9
|
-
constructor(context: ClientContext);
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new deal between a consumer and provider
|
|
12
|
-
* @param consumer_id - Address of the consumer creating the deal
|
|
13
|
-
* @param provider_id - Address of the provider
|
|
14
|
-
* @param bucket_id - ID of the bucket for the deal
|
|
15
|
-
* @param params - Deal creation parameters
|
|
16
|
-
* @returns Promise resolving to the created deal ID
|
|
17
|
-
*/
|
|
18
|
-
createDeal(consumer_id: string, provider_id: string, bucket_id: number, params: DealCreateParams): Promise<number>;
|
|
19
|
-
/**
|
|
20
|
-
* Sets a deal as accepted by the provider
|
|
21
|
-
* @param consumer_id - Address of the consumer
|
|
22
|
-
* @param provider_id - Address of the provider accepting the deal
|
|
23
|
-
* @param deal_id - ID of the deal to accept
|
|
24
|
-
* @returns Promise resolving to the acceptance result
|
|
25
|
-
*/
|
|
26
|
-
setDealAccepted(consumer_id: string, provider_id: string, deal_id: number): Promise<boolean>;
|
|
27
|
-
/**
|
|
28
|
-
* Sets a deal as funded by the consumer
|
|
29
|
-
* @param consumer_id - Address of the consumer funding the deal
|
|
30
|
-
* @param provider_id - Address of the provider
|
|
31
|
-
* @param deal_id - ID of the deal to fund
|
|
32
|
-
* @param amount_usd - Amount to fund in USD (scaled by 10^7)
|
|
33
|
-
* @returns Promise resolving to the funding result
|
|
34
|
-
*/
|
|
35
|
-
setDealFunded(consumer_id: string, provider_id: string, deal_id: number, amount_usd: bigint): Promise<boolean>;
|
|
36
|
-
/**
|
|
37
|
-
* Sets a deal as completed
|
|
38
|
-
* @param consumer_id - Address of the consumer
|
|
39
|
-
* @param provider_id - Address of the provider
|
|
40
|
-
* @param deal_id - ID of the deal to complete
|
|
41
|
-
* @returns Promise resolving to the completion result
|
|
42
|
-
*/
|
|
43
|
-
setDealCompleted(consumer_id: string, provider_id: string, deal_id: number): Promise<boolean>;
|
|
44
|
-
/**
|
|
45
|
-
* Sets a deal as cancelled
|
|
46
|
-
* @param consumer_id - Address of the consumer
|
|
47
|
-
* @param provider_id - Address of the provider
|
|
48
|
-
* @param deal_id - ID of the deal to cancel
|
|
49
|
-
* @returns Promise resolving to the cancellation result
|
|
50
|
-
*/
|
|
51
|
-
setDealCancelled(consumer_id: string, provider_id: string, deal_id: number): Promise<boolean>;
|
|
52
|
-
/**
|
|
53
|
-
* Marks a deal as breached by the consumer
|
|
54
|
-
* @param consumer_id - Address of the consumer
|
|
55
|
-
* @param provider_id - Address of the provider
|
|
56
|
-
* @param deal_id - ID of the deal
|
|
57
|
-
* @returns Promise resolving to the breach marking result
|
|
58
|
-
*/
|
|
59
|
-
setDealBreachedConsumer(consumer_id: string, provider_id: string, deal_id: number): Promise<boolean>;
|
|
60
|
-
/**
|
|
61
|
-
* Marks a deal as breached by the provider
|
|
62
|
-
* @param consumer_id - Address of the consumer
|
|
63
|
-
* @param provider_id - Address of the provider
|
|
64
|
-
* @param deal_id - ID of the deal
|
|
65
|
-
* @returns Promise resolving to the breach marking result
|
|
66
|
-
*/
|
|
67
|
-
setDealBreachedProvider(consumer_id: string, provider_id: string, deal_id: number): Promise<boolean>;
|
|
68
|
-
/**
|
|
69
|
-
* Deletes a deal from the system (owner only)
|
|
70
|
-
* @param consumer_id - Address of the consumer
|
|
71
|
-
* @param provider_id - Address of the provider
|
|
72
|
-
* @param deal_id - ID of the deal to delete
|
|
73
|
-
* @returns Promise resolving to the deletion result
|
|
74
|
-
*/
|
|
75
|
-
deleteDeal(consumer_id: string, provider_id: string, deal_id: number): Promise<boolean>;
|
|
76
|
-
/**
|
|
77
|
-
* Retrieves deal information
|
|
78
|
-
* @param consumer_id - Address of the consumer
|
|
79
|
-
* @param provider_id - Address of the provider
|
|
80
|
-
* @param deal_id - ID of the deal to retrieve
|
|
81
|
-
* @returns Promise resolving to Deal object or null if not found
|
|
82
|
-
*/
|
|
83
|
-
getDeal(consumer_id: string, provider_id: string, deal_id: number): Promise<Deal | null>;
|
|
84
|
-
/**
|
|
85
|
-
* Gets the total count of deals in the system
|
|
86
|
-
* @returns Promise resolving to the total number of deals
|
|
87
|
-
*/
|
|
88
|
-
getDealCount(): Promise<number>;
|
|
89
|
-
/**
|
|
90
|
-
* Retrieves a paginated list of all deals
|
|
91
|
-
* @param skip - Number of items to skip for pagination
|
|
92
|
-
* @param take - Number of items to take per page
|
|
93
|
-
* @returns Promise resolving to an array of Deal objects
|
|
94
|
-
*/
|
|
95
|
-
getDeals(skip?: number, take?: number): Promise<Deal[]>;
|
|
96
|
-
/**
|
|
97
|
-
* Retrieves all deals for a specific consumer
|
|
98
|
-
* @param consumer_id - Address of the consumer
|
|
99
|
-
* @returns Promise resolving to an array of Deal objects
|
|
100
|
-
*/
|
|
101
|
-
getDealsByConsumer(consumer_id: string): Promise<Deal[]>;
|
|
102
|
-
/**
|
|
103
|
-
* Retrieves all deals for a specific provider
|
|
104
|
-
* @param provider_id - Address of the provider
|
|
105
|
-
* @returns Promise resolving to an array of Deal objects
|
|
106
|
-
*/
|
|
107
|
-
getDealsByProvider(provider_id: string): Promise<Deal[]>;
|
|
108
|
-
/**
|
|
109
|
-
* Retrieves all active deals
|
|
110
|
-
* @param skip - Number of items to skip for pagination
|
|
111
|
-
* @param take - Number of items to take per page
|
|
112
|
-
* @returns Promise resolving to an array of active Deal objects
|
|
113
|
-
*/
|
|
114
|
-
getActiveDeals(skip?: number, take?: number): Promise<Deal[]>;
|
|
115
|
-
/**
|
|
116
|
-
* Pays for pending consumption in a deal (owner only)
|
|
117
|
-
* @param provider_id - Address of the provider
|
|
118
|
-
* @param consumer_id - Address of the consumer
|
|
119
|
-
* @param deal_id - ID of the deal
|
|
120
|
-
* @returns Promise resolving to the payment result
|
|
121
|
-
*/
|
|
122
|
-
payPendingConsumption(provider_id: string, consumer_id: string, deal_id: number): Promise<boolean>;
|
|
123
|
-
/**
|
|
124
|
-
* Updates deal consumption metrics (owner only)
|
|
125
|
-
* @param provider_id - Address of the provider
|
|
126
|
-
* @param consumer_id - Address of the consumer
|
|
127
|
-
* @param deal_id - ID of the deal
|
|
128
|
-
* @param params - Consumption update parameters
|
|
129
|
-
* @returns Promise resolving to the update result
|
|
130
|
-
*/
|
|
131
|
-
updateDealConsumption(provider_id: string, consumer_id: string, deal_id: number, params: DealConsumptionUpdateParams): Promise<boolean>;
|
|
132
|
-
/**
|
|
133
|
-
* Updates deal SLA metrics (owner only)
|
|
134
|
-
* @param provider_id - Address of the provider
|
|
135
|
-
* @param consumer_id - Address of the consumer
|
|
136
|
-
* @param deal_id - ID of the deal
|
|
137
|
-
* @param params - SLA update parameters
|
|
138
|
-
* @returns Promise resolving to the update result
|
|
139
|
-
*/
|
|
140
|
-
updateDealSLA(provider_id: string, consumer_id: string, deal_id: number, params: DealSLAUpdateParams): Promise<boolean>;
|
|
141
|
-
/**
|
|
142
|
-
* Gets deal status information
|
|
143
|
-
* @param consumer_id - Address of the consumer
|
|
144
|
-
* @param provider_id - Address of the provider
|
|
145
|
-
* @param deal_id - ID of the deal
|
|
146
|
-
* @returns Promise resolving to deal status or null if deal not found
|
|
147
|
-
*/
|
|
148
|
-
getDealStatus(consumer_id: string, provider_id: string, deal_id: number): Promise<string | null>;
|
|
149
|
-
/**
|
|
150
|
-
* Gets deal balance information
|
|
151
|
-
* @param consumer_id - Address of the consumer
|
|
152
|
-
* @param provider_id - Address of the provider
|
|
153
|
-
* @param deal_id - ID of the deal
|
|
154
|
-
* @returns Promise resolving to deal balances or null if deal not found
|
|
155
|
-
*/
|
|
156
|
-
getDealBalances(consumer_id: string, provider_id: string, deal_id: number): Promise<{
|
|
157
|
-
balance_consumer: bigint;
|
|
158
|
-
balance_provider: bigint;
|
|
159
|
-
} | null>;
|
|
160
|
-
}
|
package/dist/stellarv2/deal.js
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DealOps = void 0;
|
|
4
|
-
const transaction_1 = require("./transaction");
|
|
5
|
-
/**
|
|
6
|
-
* Deal operations client for FlashOnStellar V2
|
|
7
|
-
* Implements all deal-related contract methods
|
|
8
|
-
*/
|
|
9
|
-
class DealOps {
|
|
10
|
-
constructor(context) {
|
|
11
|
-
this.context = context;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new deal between a consumer and provider
|
|
15
|
-
* @param consumer_id - Address of the consumer creating the deal
|
|
16
|
-
* @param provider_id - Address of the provider
|
|
17
|
-
* @param bucket_id - ID of the bucket for the deal
|
|
18
|
-
* @param params - Deal creation parameters
|
|
19
|
-
* @returns Promise resolving to the created deal ID
|
|
20
|
-
*/
|
|
21
|
-
async createDeal(consumer_id, provider_id, bucket_id, params) {
|
|
22
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
23
|
-
method: 'create_deal',
|
|
24
|
-
args: [
|
|
25
|
-
{ value: consumer_id, type: 'address' },
|
|
26
|
-
{ value: provider_id, type: 'address' },
|
|
27
|
-
{ value: bucket_id, type: 'u32' },
|
|
28
|
-
{ value: params.duration_secs, type: 'u64' },
|
|
29
|
-
{ value: params.agreed_storage_gb, type: 'u32' },
|
|
30
|
-
{ value: params.agreed_egress_gb, type: 'u32' },
|
|
31
|
-
{ value: params.fb_repo_id, type: 'string' },
|
|
32
|
-
{ value: params.api_compatibility, type: 'string' }
|
|
33
|
-
]
|
|
34
|
-
});
|
|
35
|
-
if (typeof result === 'number') {
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
throw new Error('Failed to create deal');
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Sets a deal as accepted by the provider
|
|
42
|
-
* @param consumer_id - Address of the consumer
|
|
43
|
-
* @param provider_id - Address of the provider accepting the deal
|
|
44
|
-
* @param deal_id - ID of the deal to accept
|
|
45
|
-
* @returns Promise resolving to the acceptance result
|
|
46
|
-
*/
|
|
47
|
-
async setDealAccepted(consumer_id, provider_id, deal_id) {
|
|
48
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
49
|
-
method: 'set_deal_accepted',
|
|
50
|
-
args: [
|
|
51
|
-
{ value: consumer_id, type: 'address' },
|
|
52
|
-
{ value: provider_id, type: 'address' },
|
|
53
|
-
{ value: deal_id, type: 'u32' }
|
|
54
|
-
]
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Sets a deal as funded by the consumer
|
|
59
|
-
* @param consumer_id - Address of the consumer funding the deal
|
|
60
|
-
* @param provider_id - Address of the provider
|
|
61
|
-
* @param deal_id - ID of the deal to fund
|
|
62
|
-
* @param amount_usd - Amount to fund in USD (scaled by 10^7)
|
|
63
|
-
* @returns Promise resolving to the funding result
|
|
64
|
-
*/
|
|
65
|
-
async setDealFunded(consumer_id, provider_id, deal_id, amount_usd) {
|
|
66
|
-
return (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
67
|
-
method: 'set_deal_funded',
|
|
68
|
-
args: [
|
|
69
|
-
{ value: provider_id, type: 'address' },
|
|
70
|
-
{ value: consumer_id, type: 'address' },
|
|
71
|
-
{ value: deal_id, type: 'u32' },
|
|
72
|
-
{ value: amount_usd, type: 'u128' }
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Sets a deal as completed
|
|
78
|
-
* @param consumer_id - Address of the consumer
|
|
79
|
-
* @param provider_id - Address of the provider
|
|
80
|
-
* @param deal_id - ID of the deal to complete
|
|
81
|
-
* @returns Promise resolving to the completion result
|
|
82
|
-
*/
|
|
83
|
-
async setDealCompleted(consumer_id, provider_id, deal_id) {
|
|
84
|
-
return (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
85
|
-
method: 'set_deal_completed',
|
|
86
|
-
args: [
|
|
87
|
-
{ value: provider_id, type: 'address' },
|
|
88
|
-
{ value: consumer_id, type: 'address' },
|
|
89
|
-
{ value: deal_id, type: 'u32' }
|
|
90
|
-
]
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Sets a deal as cancelled
|
|
95
|
-
* @param consumer_id - Address of the consumer
|
|
96
|
-
* @param provider_id - Address of the provider
|
|
97
|
-
* @param deal_id - ID of the deal to cancel
|
|
98
|
-
* @returns Promise resolving to the cancellation result
|
|
99
|
-
*/
|
|
100
|
-
async setDealCancelled(consumer_id, provider_id, deal_id) {
|
|
101
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
102
|
-
method: 'set_deal_cancelled',
|
|
103
|
-
args: [
|
|
104
|
-
{ value: consumer_id, type: 'address' },
|
|
105
|
-
{ value: provider_id, type: 'address' },
|
|
106
|
-
{ value: deal_id, type: 'u32' }
|
|
107
|
-
]
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Marks a deal as breached by the consumer
|
|
112
|
-
* @param consumer_id - Address of the consumer
|
|
113
|
-
* @param provider_id - Address of the provider
|
|
114
|
-
* @param deal_id - ID of the deal
|
|
115
|
-
* @returns Promise resolving to the breach marking result
|
|
116
|
-
*/
|
|
117
|
-
async setDealBreachedConsumer(consumer_id, provider_id, deal_id) {
|
|
118
|
-
return (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
119
|
-
method: 'set_deal_breached_consumer',
|
|
120
|
-
args: [
|
|
121
|
-
{ value: consumer_id, type: 'address' },
|
|
122
|
-
{ value: provider_id, type: 'address' },
|
|
123
|
-
{ value: deal_id, type: 'u32' }
|
|
124
|
-
]
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Marks a deal as breached by the provider
|
|
129
|
-
* @param consumer_id - Address of the consumer
|
|
130
|
-
* @param provider_id - Address of the provider
|
|
131
|
-
* @param deal_id - ID of the deal
|
|
132
|
-
* @returns Promise resolving to the breach marking result
|
|
133
|
-
*/
|
|
134
|
-
async setDealBreachedProvider(consumer_id, provider_id, deal_id) {
|
|
135
|
-
return (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
136
|
-
method: 'set_deal_breached_provider',
|
|
137
|
-
args: [
|
|
138
|
-
{ value: provider_id, type: 'address' },
|
|
139
|
-
{ value: consumer_id, type: 'address' },
|
|
140
|
-
{ value: deal_id, type: 'u32' }
|
|
141
|
-
]
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Deletes a deal from the system (owner only)
|
|
146
|
-
* @param consumer_id - Address of the consumer
|
|
147
|
-
* @param provider_id - Address of the provider
|
|
148
|
-
* @param deal_id - ID of the deal to delete
|
|
149
|
-
* @returns Promise resolving to the deletion result
|
|
150
|
-
*/
|
|
151
|
-
async deleteDeal(consumer_id, provider_id, deal_id) {
|
|
152
|
-
return (0, transaction_1.callContractMethod)(this.context, '', {
|
|
153
|
-
method: 'delete_deal',
|
|
154
|
-
args: [
|
|
155
|
-
{ value: consumer_id, type: 'address' },
|
|
156
|
-
{ value: provider_id, type: 'address' },
|
|
157
|
-
{ value: deal_id, type: 'u32' }
|
|
158
|
-
]
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Retrieves deal information
|
|
163
|
-
* @param consumer_id - Address of the consumer
|
|
164
|
-
* @param provider_id - Address of the provider
|
|
165
|
-
* @param deal_id - ID of the deal to retrieve
|
|
166
|
-
* @returns Promise resolving to Deal object or null if not found
|
|
167
|
-
*/
|
|
168
|
-
async getDeal(consumer_id, provider_id, deal_id) {
|
|
169
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
170
|
-
method: 'get_deal',
|
|
171
|
-
args: [
|
|
172
|
-
{ value: consumer_id, type: 'address' },
|
|
173
|
-
{ value: provider_id, type: 'address' },
|
|
174
|
-
{ value: deal_id, type: 'u32' }
|
|
175
|
-
]
|
|
176
|
-
});
|
|
177
|
-
if (result && typeof result === 'object') {
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Gets the total count of deals in the system
|
|
184
|
-
* @returns Promise resolving to the total number of deals
|
|
185
|
-
*/
|
|
186
|
-
async getDealCount() {
|
|
187
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, '', {
|
|
188
|
-
method: 'get_deal_count',
|
|
189
|
-
args: []
|
|
190
|
-
});
|
|
191
|
-
if (typeof result === 'number') {
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
return 0;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Retrieves a paginated list of all deals
|
|
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 Deal objects
|
|
201
|
-
*/
|
|
202
|
-
async getDeals(skip = 0, take = 10) {
|
|
203
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, '', {
|
|
204
|
-
method: 'get_deals',
|
|
205
|
-
args: [
|
|
206
|
-
{ value: skip, type: 'u32' },
|
|
207
|
-
{ value: take, type: 'u32' }
|
|
208
|
-
]
|
|
209
|
-
});
|
|
210
|
-
if (Array.isArray(result)) {
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
|
-
return [];
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Retrieves all deals for a specific consumer
|
|
217
|
-
* @param consumer_id - Address of the consumer
|
|
218
|
-
* @returns Promise resolving to an array of Deal objects
|
|
219
|
-
*/
|
|
220
|
-
async getDealsByConsumer(consumer_id) {
|
|
221
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, consumer_id, {
|
|
222
|
-
method: 'get_deals_by_consumer',
|
|
223
|
-
args: [
|
|
224
|
-
{ value: consumer_id, type: 'address' }
|
|
225
|
-
]
|
|
226
|
-
});
|
|
227
|
-
if (Array.isArray(result)) {
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
return [];
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Retrieves all deals for a specific provider
|
|
234
|
-
* @param provider_id - Address of the provider
|
|
235
|
-
* @returns Promise resolving to an array of Deal objects
|
|
236
|
-
*/
|
|
237
|
-
async getDealsByProvider(provider_id) {
|
|
238
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, provider_id, {
|
|
239
|
-
method: 'get_deals_by_provider',
|
|
240
|
-
args: [
|
|
241
|
-
{ value: provider_id, type: 'address' }
|
|
242
|
-
]
|
|
243
|
-
});
|
|
244
|
-
if (Array.isArray(result)) {
|
|
245
|
-
return result;
|
|
246
|
-
}
|
|
247
|
-
return [];
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Retrieves all active deals
|
|
251
|
-
* @param skip - Number of items to skip for pagination
|
|
252
|
-
* @param take - Number of items to take per page
|
|
253
|
-
* @returns Promise resolving to an array of active Deal objects
|
|
254
|
-
*/
|
|
255
|
-
async getActiveDeals(skip = 0, take = 10) {
|
|
256
|
-
const result = await (0, transaction_1.callContractMethod)(this.context, '', {
|
|
257
|
-
method: 'get_active_deals',
|
|
258
|
-
args: [
|
|
259
|
-
{ value: skip, type: 'u32' },
|
|
260
|
-
{ value: take, type: 'u32' }
|
|
261
|
-
]
|
|
262
|
-
});
|
|
263
|
-
if (Array.isArray(result)) {
|
|
264
|
-
return result;
|
|
265
|
-
}
|
|
266
|
-
return [];
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Pays for pending consumption in a deal (owner only)
|
|
270
|
-
* @param provider_id - Address of the provider
|
|
271
|
-
* @param consumer_id - Address of the consumer
|
|
272
|
-
* @param deal_id - ID of the deal
|
|
273
|
-
* @returns Promise resolving to the payment result
|
|
274
|
-
*/
|
|
275
|
-
async payPendingConsumption(provider_id, consumer_id, deal_id) {
|
|
276
|
-
return (0, transaction_1.callContractMethod)(this.context, '', {
|
|
277
|
-
method: 'pay_pending_consumption',
|
|
278
|
-
args: [
|
|
279
|
-
{ value: provider_id, type: 'address' },
|
|
280
|
-
{ value: consumer_id, type: 'address' },
|
|
281
|
-
{ value: deal_id, type: 'u32' }
|
|
282
|
-
]
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Updates deal consumption metrics (owner only)
|
|
287
|
-
* @param provider_id - Address of the provider
|
|
288
|
-
* @param consumer_id - Address of the consumer
|
|
289
|
-
* @param deal_id - ID of the deal
|
|
290
|
-
* @param params - Consumption update parameters
|
|
291
|
-
* @returns Promise resolving to the update result
|
|
292
|
-
*/
|
|
293
|
-
async updateDealConsumption(provider_id, consumer_id, deal_id, params) {
|
|
294
|
-
return (0, transaction_1.callContractMethod)(this.context, '', {
|
|
295
|
-
method: 'update_deal_consumption',
|
|
296
|
-
args: [
|
|
297
|
-
{ value: provider_id, type: 'address' },
|
|
298
|
-
{ value: consumer_id, type: 'address' },
|
|
299
|
-
{ value: deal_id, type: 'u32' },
|
|
300
|
-
{ value: params.storage_gb, type: 'u32' },
|
|
301
|
-
{ value: params.egress_gb, type: 'u32' }
|
|
302
|
-
]
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Updates deal SLA metrics (owner only)
|
|
307
|
-
* @param provider_id - Address of the provider
|
|
308
|
-
* @param consumer_id - Address of the consumer
|
|
309
|
-
* @param deal_id - ID of the deal
|
|
310
|
-
* @param params - SLA update parameters
|
|
311
|
-
* @returns Promise resolving to the update result
|
|
312
|
-
*/
|
|
313
|
-
async updateDealSLA(provider_id, consumer_id, deal_id, params) {
|
|
314
|
-
return (0, transaction_1.callContractMethod)(this.context, '', {
|
|
315
|
-
method: 'update_deal_sla',
|
|
316
|
-
args: [
|
|
317
|
-
{ value: provider_id, type: 'address' },
|
|
318
|
-
{ value: consumer_id, type: 'address' },
|
|
319
|
-
{ value: deal_id, type: 'u32' },
|
|
320
|
-
{ value: params.sla_avg_latency_ms, type: 'u32' },
|
|
321
|
-
{ value: params.sla_avg_uptime_pct, type: 'u32' }
|
|
322
|
-
]
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Gets deal status information
|
|
327
|
-
* @param consumer_id - Address of the consumer
|
|
328
|
-
* @param provider_id - Address of the provider
|
|
329
|
-
* @param deal_id - ID of the deal
|
|
330
|
-
* @returns Promise resolving to deal status or null if deal not found
|
|
331
|
-
*/
|
|
332
|
-
async getDealStatus(consumer_id, provider_id, deal_id) {
|
|
333
|
-
const deal = await this.getDeal(consumer_id, provider_id, deal_id);
|
|
334
|
-
if (!deal) {
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
337
|
-
return deal.status;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Gets deal balance information
|
|
341
|
-
* @param consumer_id - Address of the consumer
|
|
342
|
-
* @param provider_id - Address of the provider
|
|
343
|
-
* @param deal_id - ID of the deal
|
|
344
|
-
* @returns Promise resolving to deal balances or null if deal not found
|
|
345
|
-
*/
|
|
346
|
-
async getDealBalances(consumer_id, provider_id, deal_id) {
|
|
347
|
-
const deal = await this.getDeal(consumer_id, provider_id, deal_id);
|
|
348
|
-
if (!deal) {
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
return {
|
|
352
|
-
balance_consumer: deal.balance_consumer,
|
|
353
|
-
balance_provider: deal.balance_provider
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
exports.DealOps = DealOps;
|