@flashbacktech/flashbackclient 0.1.39 → 0.1.41
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/index.d.ts +1 -6
- package/dist/stellarv2/client/index.js +24 -10
- package/dist/stellarv2/wallet/transaction.js +0 -53
- 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,10 +0,0 @@
|
|
|
1
|
-
import { ClientContext } from './client.js';
|
|
2
|
-
import { StorageProvider, StorageUnit } from './models.js';
|
|
3
|
-
declare const get_provider: (context: ClientContext, wallet_address: string, provider_address: string, load_units?: boolean) => Promise<StorageProvider | null>;
|
|
4
|
-
declare const get_provider_units: (context: ClientContext, wallet_address: string, provider_address: string) => Promise<Map<number, StorageUnit>>;
|
|
5
|
-
declare const get_providers: (context: ClientContext, wallet_address: string, skip?: number, take?: number) => Promise<Map<string, StorageProvider>>;
|
|
6
|
-
declare const get_provider_count: (context: ClientContext, wallet_address: string) => Promise<number>;
|
|
7
|
-
declare const register_provider: (context: ClientContext, wallet_address: string, provider_address: string, provider_description: string) => Promise<void>;
|
|
8
|
-
declare const delete_provider: (context: ClientContext, wallet_address: string, provider_address: string) => Promise<void>;
|
|
9
|
-
declare const update_provider: (context: ClientContext, wallet_address: string, provider_address: string, provider_description: string) => Promise<void>;
|
|
10
|
-
export { get_provider, get_provider_units, get_providers, get_provider_count, register_provider, delete_provider, update_provider, };
|
package/dist/stellar/provider.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.update_provider = exports.delete_provider = exports.register_provider = exports.get_provider_count = exports.get_providers = exports.get_provider_units = exports.get_provider = void 0;
|
|
4
|
-
const transaction_js_1 = require("./transaction.js");
|
|
5
|
-
const get_provider = async (context, wallet_address, provider_address, load_units = false) => {
|
|
6
|
-
const [provider, units] = await Promise.all([
|
|
7
|
-
(0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
8
|
-
method: 'get_provider',
|
|
9
|
-
args: [{ value: provider_address, type: 'address' }],
|
|
10
|
-
}),
|
|
11
|
-
load_units
|
|
12
|
-
? get_provider_units(context, wallet_address, provider_address)
|
|
13
|
-
: new Map(),
|
|
14
|
-
]);
|
|
15
|
-
const typedProviderData = provider.isSuccess ? provider.result : null;
|
|
16
|
-
if (typedProviderData) {
|
|
17
|
-
typedProviderData.units = units;
|
|
18
|
-
}
|
|
19
|
-
return typedProviderData;
|
|
20
|
-
};
|
|
21
|
-
exports.get_provider = get_provider;
|
|
22
|
-
const get_provider_units = async (context, wallet_address, provider_address) => {
|
|
23
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
24
|
-
method: 'get_provider_units',
|
|
25
|
-
args: [{ value: provider_address, type: 'address' }],
|
|
26
|
-
});
|
|
27
|
-
const typedProviderUnits = response.isSuccess
|
|
28
|
-
? response.result
|
|
29
|
-
: new Map();
|
|
30
|
-
return typedProviderUnits;
|
|
31
|
-
};
|
|
32
|
-
exports.get_provider_units = get_provider_units;
|
|
33
|
-
const get_providers = async (context, wallet_address, skip = 0, take = 10) => {
|
|
34
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
35
|
-
method: 'get_providers',
|
|
36
|
-
args: [
|
|
37
|
-
{ value: skip, type: 'u32' },
|
|
38
|
-
{ value: take, type: 'u32' },
|
|
39
|
-
],
|
|
40
|
-
});
|
|
41
|
-
if (!response.isSuccess) {
|
|
42
|
-
return new Map();
|
|
43
|
-
}
|
|
44
|
-
const providersObj = response.result;
|
|
45
|
-
return new Map(Object.entries(providersObj));
|
|
46
|
-
};
|
|
47
|
-
exports.get_providers = get_providers;
|
|
48
|
-
const get_provider_count = async (context, wallet_address) => {
|
|
49
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
50
|
-
method: 'get_provider_count',
|
|
51
|
-
});
|
|
52
|
-
return response.isSuccess ? response.result : 0;
|
|
53
|
-
};
|
|
54
|
-
exports.get_provider_count = get_provider_count;
|
|
55
|
-
// Helper function to handle write-mode contract calls
|
|
56
|
-
const executeProviderTransaction = async (context, wallet_address, provider_address, method, additionalArgs = []) => {
|
|
57
|
-
const is_owner = wallet_address !== provider_address;
|
|
58
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
59
|
-
method,
|
|
60
|
-
args: [
|
|
61
|
-
{ value: provider_address, type: 'address' },
|
|
62
|
-
...additionalArgs,
|
|
63
|
-
{ value: is_owner, type: 'bool' },
|
|
64
|
-
],
|
|
65
|
-
});
|
|
66
|
-
if (response.isSuccess && !response.isReadOnly) {
|
|
67
|
-
const signedTxXDR = await context.signTransaction(response.result);
|
|
68
|
-
await (0, transaction_js_1.sendTransaction)(context, signedTxXDR);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const register_provider = async (context, wallet_address, provider_address, provider_description) => {
|
|
72
|
-
await executeProviderTransaction(context, wallet_address, provider_address, 'register_provider', [
|
|
73
|
-
{ value: provider_description, type: 'string' },
|
|
74
|
-
]);
|
|
75
|
-
};
|
|
76
|
-
exports.register_provider = register_provider;
|
|
77
|
-
const delete_provider = async (context, wallet_address, provider_address) => {
|
|
78
|
-
await executeProviderTransaction(context, wallet_address, provider_address, 'delete_provider');
|
|
79
|
-
};
|
|
80
|
-
exports.delete_provider = delete_provider;
|
|
81
|
-
const update_provider = async (context, wallet_address, provider_address, provider_description) => {
|
|
82
|
-
await executeProviderTransaction(context, wallet_address, provider_address, 'update_provider', [
|
|
83
|
-
{ value: provider_description, type: 'string' },
|
|
84
|
-
]);
|
|
85
|
-
};
|
|
86
|
-
exports.update_provider = update_provider;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ClientContext } from './client.js';
|
|
2
|
-
import { DeletionStatus, StorageReservation } from './models.js';
|
|
3
|
-
declare const get_reservation: (context: ClientContext, wallet_address: string, reservation_id: number) => Promise<StorageReservation | null>;
|
|
4
|
-
declare const create_reservation: (context: ClientContext, wallet_address: string, consumer_address: string, unit_id: number, reserved_gb: number) => Promise<boolean>;
|
|
5
|
-
declare const delete_reservation: (context: ClientContext, wallet_address: string, consumer_address: string, reservation_id: number) => Promise<DeletionStatus>;
|
|
6
|
-
declare const update_inuse_bytes_consumer: (context: ClientContext, wallet_address: string, consumer_address: string, reservation_id: number, inuse_bytes: number) => Promise<boolean>;
|
|
7
|
-
declare const update_inuse_bytes_provider: (context: ClientContext, wallet_address: string, provider_address: string, reservation_id: number, inuse_bytes: number) => Promise<boolean>;
|
|
8
|
-
export { get_reservation, create_reservation, delete_reservation, update_inuse_bytes_consumer, update_inuse_bytes_provider, };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.update_inuse_bytes_provider = exports.update_inuse_bytes_consumer = exports.delete_reservation = exports.create_reservation = exports.get_reservation = void 0;
|
|
4
|
-
const transaction_js_1 = require("./transaction.js");
|
|
5
|
-
const get_reservation = async (context, wallet_address, reservation_id) => {
|
|
6
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
7
|
-
method: 'get_reservation',
|
|
8
|
-
args: [{ value: reservation_id, type: 'u32' }],
|
|
9
|
-
});
|
|
10
|
-
return response.isSuccess ? response.result : null;
|
|
11
|
-
};
|
|
12
|
-
exports.get_reservation = get_reservation;
|
|
13
|
-
const executeReservationTransaction = async (context, wallet_address, method, additionalArgs = [], defaultValue) => {
|
|
14
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
15
|
-
method,
|
|
16
|
-
args: additionalArgs,
|
|
17
|
-
});
|
|
18
|
-
if (response.isSuccess && !response.isReadOnly) {
|
|
19
|
-
const signedTxXDR = await context.signTransaction(response.result);
|
|
20
|
-
return (0, transaction_js_1.sendTransaction)(context, signedTxXDR);
|
|
21
|
-
}
|
|
22
|
-
return defaultValue;
|
|
23
|
-
};
|
|
24
|
-
const create_reservation = async (context, wallet_address, consumer_address, unit_id, reserved_gb) => {
|
|
25
|
-
const is_owner = wallet_address !== consumer_address;
|
|
26
|
-
return executeReservationTransaction(context, wallet_address, 'create_reservation', [
|
|
27
|
-
{ value: consumer_address, type: 'address' },
|
|
28
|
-
{ value: unit_id, type: 'u32' },
|
|
29
|
-
{ value: reserved_gb, type: 'u32' },
|
|
30
|
-
{ value: is_owner, type: 'bool' },
|
|
31
|
-
]);
|
|
32
|
-
};
|
|
33
|
-
exports.create_reservation = create_reservation;
|
|
34
|
-
const delete_reservation = async (context, wallet_address, consumer_address, reservation_id) => {
|
|
35
|
-
const is_owner = wallet_address !== consumer_address;
|
|
36
|
-
return (executeReservationTransaction(context, wallet_address, 'delete_reservation', [
|
|
37
|
-
{ value: reservation_id, type: 'u32' },
|
|
38
|
-
{ value: is_owner, type: 'bool' },
|
|
39
|
-
]) || 'NotFound');
|
|
40
|
-
};
|
|
41
|
-
exports.delete_reservation = delete_reservation;
|
|
42
|
-
const update_inuse_bytes_consumer = async (context, wallet_address, consumer_address, reservation_id, inuse_bytes) => {
|
|
43
|
-
const is_owner = wallet_address !== consumer_address;
|
|
44
|
-
return executeReservationTransaction(context, wallet_address, 'update_inuse_bytes_consumer', [
|
|
45
|
-
{ value: reservation_id, type: 'u32' },
|
|
46
|
-
{ value: consumer_address, type: 'address' },
|
|
47
|
-
{ value: inuse_bytes, type: 'u64' },
|
|
48
|
-
{ value: is_owner, type: 'bool' },
|
|
49
|
-
]);
|
|
50
|
-
};
|
|
51
|
-
exports.update_inuse_bytes_consumer = update_inuse_bytes_consumer;
|
|
52
|
-
const update_inuse_bytes_provider = async (context, wallet_address, provider_address, reservation_id, inuse_bytes) => {
|
|
53
|
-
const is_owner = wallet_address !== provider_address;
|
|
54
|
-
return executeReservationTransaction(context, wallet_address, 'update_inuse_bytes_consumer', [
|
|
55
|
-
{ value: reservation_id, type: 'u32' },
|
|
56
|
-
{ value: provider_address, type: 'address' },
|
|
57
|
-
{ value: inuse_bytes, type: 'u64' },
|
|
58
|
-
{ value: is_owner, type: 'bool' },
|
|
59
|
-
]);
|
|
60
|
-
};
|
|
61
|
-
exports.update_inuse_bytes_provider = update_inuse_bytes_provider;
|
package/dist/stellar/stats.d.ts
DELETED
package/dist/stellar/stats.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.get_stats = void 0;
|
|
4
|
-
const transaction_js_1 = require("./transaction.js");
|
|
5
|
-
const get_stats = async (context, wallet_address) => {
|
|
6
|
-
const stats = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
7
|
-
method: 'get_stats',
|
|
8
|
-
args: [],
|
|
9
|
-
});
|
|
10
|
-
return stats.isSuccess ? stats.result : null;
|
|
11
|
-
};
|
|
12
|
-
exports.get_stats = get_stats;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Transaction, Memo, MemoType, Operation, FeeBumpTransaction } from '@stellar/stellar-sdk';
|
|
2
|
-
import { ClientContext } from './client.js';
|
|
3
|
-
interface StellarNetwork {
|
|
4
|
-
network: string;
|
|
5
|
-
networkPassphrase: string;
|
|
6
|
-
}
|
|
7
|
-
declare const getNetwork: (network: string) => StellarNetwork;
|
|
8
|
-
declare const getPublicKeyFromPrivateKey: (privateKey: string) => string;
|
|
9
|
-
interface ContractMethodCall {
|
|
10
|
-
method: string;
|
|
11
|
-
args?: Array<{
|
|
12
|
-
value: number | string | bigint | boolean | null | undefined;
|
|
13
|
-
type: 'u32' | 'i32' | 'u64' | 'i64' | 'string' | 'symbol' | 'address' | 'bool';
|
|
14
|
-
}>;
|
|
15
|
-
}
|
|
16
|
-
interface ContractMethodResponse {
|
|
17
|
-
isSuccess: boolean;
|
|
18
|
-
isReadOnly: boolean;
|
|
19
|
-
result: string | unknown;
|
|
20
|
-
}
|
|
21
|
-
declare const prepareTransaction: (context: ClientContext, address: string, contractCall: ContractMethodCall) => Promise<ContractMethodResponse>;
|
|
22
|
-
declare const signTransaction: (context: ClientContext, xdrToSign: string, privateKey: string) => Promise<Transaction<Memo<MemoType>, Operation[]> | FeeBumpTransaction>;
|
|
23
|
-
declare const sendTransaction: (context: ClientContext, signedTransactionXDR: string) => Promise<any>;
|
|
24
|
-
export { prepareTransaction, sendTransaction, signTransaction, getNetwork, StellarNetwork, getPublicKeyFromPrivateKey, };
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPublicKeyFromPrivateKey = exports.getNetwork = exports.signTransaction = exports.sendTransaction = exports.prepareTransaction = void 0;
|
|
4
|
-
const timing_js_1 = require("../utils/timing.js");
|
|
5
|
-
// Polyfill for BigInt JSON serialization
|
|
6
|
-
BigInt.prototype.toJSON = function () {
|
|
7
|
-
return this.toString();
|
|
8
|
-
};
|
|
9
|
-
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
10
|
-
const stellar_sdk_2 = require("@stellar/stellar-sdk");
|
|
11
|
-
const getNetwork = (network) => {
|
|
12
|
-
let networkPassphrase = '';
|
|
13
|
-
switch (network) {
|
|
14
|
-
case 'TESTNET':
|
|
15
|
-
networkPassphrase = 'Test SDF Network ; September 2015';
|
|
16
|
-
break;
|
|
17
|
-
case 'PUBLIC':
|
|
18
|
-
networkPassphrase = 'Public Global Stellar Network ; September 2015';
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
return { network, networkPassphrase };
|
|
22
|
-
};
|
|
23
|
-
exports.getNetwork = getNetwork;
|
|
24
|
-
const getPublicKeyFromPrivateKey = (privateKey) => {
|
|
25
|
-
const keypair = stellar_sdk_1.Keypair.fromSecret(privateKey);
|
|
26
|
-
return keypair.publicKey();
|
|
27
|
-
};
|
|
28
|
-
exports.getPublicKeyFromPrivateKey = getPublicKeyFromPrivateKey;
|
|
29
|
-
const getServer = (network) => {
|
|
30
|
-
let serverUrl = '';
|
|
31
|
-
switch (network.network) {
|
|
32
|
-
case 'TESTNET':
|
|
33
|
-
serverUrl = 'https://soroban-testnet.stellar.org:443';
|
|
34
|
-
break;
|
|
35
|
-
case 'PUBLIC':
|
|
36
|
-
serverUrl = 'https://rpc.stellar.org:443';
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
console.log(`@@@Creating Stellar RPC server for network: ${network.network}, URL: ${serverUrl}`);
|
|
40
|
-
const server = new stellar_sdk_2.rpc.Server(serverUrl);
|
|
41
|
-
return server;
|
|
42
|
-
};
|
|
43
|
-
const TIMEOUT_TRANSACTION = 60;
|
|
44
|
-
const prepareTransaction = async (context, address, contractCall) => {
|
|
45
|
-
const contractAddress = context.contractAddress;
|
|
46
|
-
const contract = new stellar_sdk_1.Contract(contractAddress);
|
|
47
|
-
const server = getServer(context.network);
|
|
48
|
-
const sourceAccount = await server.getAccount(address);
|
|
49
|
-
const response = {
|
|
50
|
-
isSuccess: false,
|
|
51
|
-
isReadOnly: false,
|
|
52
|
-
result: '',
|
|
53
|
-
};
|
|
54
|
-
// Convert raw values to ScVal
|
|
55
|
-
const convertedArgs = contractCall.args?.map((arg) => (0, stellar_sdk_1.nativeToScVal)(arg.value, { type: arg.type })) || [];
|
|
56
|
-
const builtTransaction = new stellar_sdk_1.TransactionBuilder(sourceAccount, {
|
|
57
|
-
fee: stellar_sdk_1.BASE_FEE,
|
|
58
|
-
networkPassphrase: context.network.networkPassphrase,
|
|
59
|
-
})
|
|
60
|
-
.addOperation(contract.call(contractCall.method, ...convertedArgs))
|
|
61
|
-
.setTimeout(TIMEOUT_TRANSACTION)
|
|
62
|
-
.build();
|
|
63
|
-
const sim = await server.simulateTransaction(builtTransaction);
|
|
64
|
-
if (stellar_sdk_2.rpc.Api.isSimulationSuccess(sim)) {
|
|
65
|
-
response.isSuccess = true;
|
|
66
|
-
//console.log('Simulation success:', JSON.stringify(sim));
|
|
67
|
-
const result = sim.result && sim.result.retval ? (0, stellar_sdk_1.scValToNative)(sim.result.retval) : undefined;
|
|
68
|
-
const footprint = sim.transactionData.getFootprint();
|
|
69
|
-
const isReadOnly = footprint.readOnly().length > 0 && footprint.readWrite().length === 0;
|
|
70
|
-
if (isReadOnly) {
|
|
71
|
-
response.isReadOnly = true;
|
|
72
|
-
response.result = result;
|
|
73
|
-
return response;
|
|
74
|
-
}
|
|
75
|
-
// For write operations, continue with the normal flow of returning the XDR
|
|
76
|
-
const preparedTransaction = await server.prepareTransaction(builtTransaction);
|
|
77
|
-
response.result = preparedTransaction.toXDR();
|
|
78
|
-
return response;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
if (stellar_sdk_2.rpc.Api.isSimulationError(sim)) {
|
|
82
|
-
throw new Error(`Tansaction simulation error: ${JSON.stringify(sim.error)}`);
|
|
83
|
-
}
|
|
84
|
-
throw new Error('Transaction simulation failed');
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
exports.prepareTransaction = prepareTransaction;
|
|
88
|
-
const signTransaction = async (context, xdrToSign, privateKey) => {
|
|
89
|
-
const preparedTransaction = stellar_sdk_1.TransactionBuilder.fromXDR(xdrToSign, context.network.networkPassphrase);
|
|
90
|
-
const sourceKeypair = stellar_sdk_1.Keypair.fromSecret(privateKey);
|
|
91
|
-
preparedTransaction.sign(sourceKeypair);
|
|
92
|
-
return preparedTransaction;
|
|
93
|
-
};
|
|
94
|
-
exports.signTransaction = signTransaction;
|
|
95
|
-
const sendTransaction = async (context, signedTransactionXDR) => {
|
|
96
|
-
const server = getServer(context.network);
|
|
97
|
-
const signedTransaction = stellar_sdk_1.TransactionBuilder.fromXDR(signedTransactionXDR, context.network.networkPassphrase);
|
|
98
|
-
// Submit the transaction to the Stellar-RPC server. The RPC server will
|
|
99
|
-
// then submit the transaction into the network for us. Then we will have to
|
|
100
|
-
// wait, polling `getTransaction` until the transaction completes.
|
|
101
|
-
try {
|
|
102
|
-
const sendResponse = await server.sendTransaction(signedTransaction);
|
|
103
|
-
if (sendResponse.status === 'PENDING') {
|
|
104
|
-
let getResponse = await server.getTransaction(sendResponse.hash);
|
|
105
|
-
// Poll `getTransaction` until the status is not "NOT_FOUND"
|
|
106
|
-
while (getResponse.status === 'NOT_FOUND') {
|
|
107
|
-
// See if the transaction is complete
|
|
108
|
-
getResponse = await server.getTransaction(sendResponse.hash);
|
|
109
|
-
// Wait one second
|
|
110
|
-
await (0, timing_js_1.sleep)(1000);
|
|
111
|
-
}
|
|
112
|
-
//console.log(`getTransaction response: ${JSON.stringify(getResponse)}`);
|
|
113
|
-
if (getResponse.status === 'SUCCESS') {
|
|
114
|
-
// Make sure the transaction's resultMetaXDR is not empty
|
|
115
|
-
if (!getResponse.resultMetaXdr) {
|
|
116
|
-
throw new Error('Empty resultMetaXDR in getTransaction response');
|
|
117
|
-
}
|
|
118
|
-
// Find the return value from the contract and return it
|
|
119
|
-
const transactionMeta = getResponse.resultMetaXdr;
|
|
120
|
-
const returnValue = transactionMeta.v3().sorobanMeta()?.returnValue();
|
|
121
|
-
if (returnValue) {
|
|
122
|
-
return (0, stellar_sdk_1.scValToNative)(returnValue);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
throw new Error(`Transaction failed: ${getResponse.resultXdr}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
throw new Error(sendResponse.errorResult?.toString() || 'Unknown error');
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
// Catch and report any errors we've thrown
|
|
135
|
-
throw new Error(`Transaction sending error: ${JSON.stringify(err)}`);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
exports.sendTransaction = sendTransaction;
|
package/dist/stellar/unit.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ClientContext } from './client.js';
|
|
2
|
-
import { DeletionStatus, StorageReservation, StorageUnit } from './models.js';
|
|
3
|
-
type RegisterUnitResponse = [unitId: number, unit: StorageUnit];
|
|
4
|
-
declare const get_unit: (context: ClientContext, wallet_address: string, unit_id: number, load_reservations?: boolean) => Promise<StorageUnit | null>;
|
|
5
|
-
declare const get_unit_reservations: (context: ClientContext, wallet_address: string, unit_id: number) => Promise<Map<number, StorageReservation>>;
|
|
6
|
-
declare const register_unit: (context: ClientContext, wallet_address: string, provider_address: string, capacity: number, endpoint: string) => Promise<RegisterUnitResponse | null>;
|
|
7
|
-
declare const delete_unit: (context: ClientContext, wallet_address: string, provider_address: string, unit_id: number) => Promise<DeletionStatus | null>;
|
|
8
|
-
declare const enter_maintenance: (context: ClientContext, wallet_address: string, provider_address: string, unit_id: number, maintenanceStart: Date, maintenanceEnd: Date) => Promise<boolean | null>;
|
|
9
|
-
declare const exit_maintenance: (context: ClientContext, wallet_address: string, provider_address: string, unit_id: number) => Promise<boolean | null>;
|
|
10
|
-
declare const enter_decommissioning: (context: ClientContext, wallet_address: string, provider_address: string, unit_id: number) => Promise<boolean | null>;
|
|
11
|
-
declare const exit_decommissioning: (context: ClientContext, wallet_address: string, provider_address: string, unit_id: number) => Promise<boolean | null>;
|
|
12
|
-
export { get_unit, get_unit_reservations, register_unit, delete_unit, enter_maintenance, exit_maintenance, enter_decommissioning, exit_decommissioning, };
|
package/dist/stellar/unit.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exit_decommissioning = exports.enter_decommissioning = exports.exit_maintenance = exports.enter_maintenance = exports.delete_unit = exports.register_unit = exports.get_unit_reservations = exports.get_unit = void 0;
|
|
4
|
-
const transaction_js_1 = require("./transaction.js");
|
|
5
|
-
const get_unit = async (context, wallet_address, unit_id, load_reservations = false) => {
|
|
6
|
-
const [unit, reservations] = await Promise.all([
|
|
7
|
-
(0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
8
|
-
method: 'get_unit',
|
|
9
|
-
args: [{ value: unit_id, type: 'u32' }],
|
|
10
|
-
}),
|
|
11
|
-
load_reservations
|
|
12
|
-
? get_unit_reservations(context, wallet_address, unit_id)
|
|
13
|
-
: new Map(),
|
|
14
|
-
]);
|
|
15
|
-
const typedUnitData = unit.isSuccess ? unit.result : null;
|
|
16
|
-
if (typedUnitData) {
|
|
17
|
-
typedUnitData.reservations = reservations;
|
|
18
|
-
}
|
|
19
|
-
return typedUnitData;
|
|
20
|
-
};
|
|
21
|
-
exports.get_unit = get_unit;
|
|
22
|
-
const get_unit_reservations = async (context, wallet_address, unit_id) => {
|
|
23
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
24
|
-
method: 'get_unit_reservations',
|
|
25
|
-
args: [{ value: unit_id, type: 'u32' }],
|
|
26
|
-
});
|
|
27
|
-
const typedUnitReservations = response.isSuccess
|
|
28
|
-
? response.result
|
|
29
|
-
: new Map();
|
|
30
|
-
return typedUnitReservations;
|
|
31
|
-
};
|
|
32
|
-
exports.get_unit_reservations = get_unit_reservations;
|
|
33
|
-
const executeUnitTransaction = async (context, wallet_address, provider_address, method, additionalArgs = []) => {
|
|
34
|
-
const is_owner = wallet_address !== provider_address;
|
|
35
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
36
|
-
method,
|
|
37
|
-
args: [
|
|
38
|
-
{ value: provider_address, type: 'address' },
|
|
39
|
-
...additionalArgs,
|
|
40
|
-
{ value: is_owner, type: 'bool' },
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
if (response.isSuccess && !response.isReadOnly) {
|
|
44
|
-
const signedTxXDR = await context.signTransaction(response.result);
|
|
45
|
-
return (0, transaction_js_1.sendTransaction)(context, signedTxXDR);
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
};
|
|
49
|
-
const register_unit = async (context, wallet_address, provider_address, capacity, endpoint) => {
|
|
50
|
-
return executeUnitTransaction(context, wallet_address, provider_address, 'register_unit', [
|
|
51
|
-
{ value: capacity, type: 'u32' },
|
|
52
|
-
{ value: endpoint, type: 'string' },
|
|
53
|
-
]);
|
|
54
|
-
};
|
|
55
|
-
exports.register_unit = register_unit;
|
|
56
|
-
const delete_unit = async (context, wallet_address, provider_address, unit_id) => {
|
|
57
|
-
return executeUnitTransaction(context, wallet_address, provider_address, 'delete_unit', [{ value: unit_id, type: 'u32' }]);
|
|
58
|
-
};
|
|
59
|
-
exports.delete_unit = delete_unit;
|
|
60
|
-
const change_unit_status = async (context, method, wallet_address, provider_address, unit_id, maintenanceStart, maintenanceEnd) => {
|
|
61
|
-
const is_owner = wallet_address !== provider_address;
|
|
62
|
-
const response = await (0, transaction_js_1.prepareTransaction)(context, wallet_address, {
|
|
63
|
-
method: method,
|
|
64
|
-
args: [
|
|
65
|
-
{ value: provider_address, type: 'address' },
|
|
66
|
-
{ value: unit_id, type: 'u32' },
|
|
67
|
-
...(method === 'enter_maintenance'
|
|
68
|
-
? [
|
|
69
|
-
{ value: Math.floor(maintenanceStart.getTime() / 1000), type: 'u64' },
|
|
70
|
-
{ value: Math.floor(maintenanceEnd.getTime() / 1000), type: 'u64' },
|
|
71
|
-
]
|
|
72
|
-
: []),
|
|
73
|
-
{ value: is_owner, type: 'bool' },
|
|
74
|
-
],
|
|
75
|
-
});
|
|
76
|
-
if (response.isSuccess && !response.isReadOnly) {
|
|
77
|
-
const signedTxXDR = await context.signTransaction(response.result);
|
|
78
|
-
const responseSend = (await (0, transaction_js_1.sendTransaction)(context, signedTxXDR));
|
|
79
|
-
return responseSend;
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
};
|
|
83
|
-
const createUnitMaintenanceChanger = (method) => {
|
|
84
|
-
return async (context, wallet_address, provider_address, unit_id, maintenanceStart, maintenanceEnd) => {
|
|
85
|
-
return change_unit_status(context, method, wallet_address, provider_address, unit_id, maintenanceStart, maintenanceEnd);
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
const createUnitStatusChanger = (method) => {
|
|
89
|
-
return async (context, wallet_address, provider_address, unit_id) => {
|
|
90
|
-
return change_unit_status(context, method, wallet_address, provider_address, unit_id);
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
const enter_maintenance = createUnitMaintenanceChanger('enter_maintenance');
|
|
94
|
-
exports.enter_maintenance = enter_maintenance;
|
|
95
|
-
const exit_maintenance = createUnitStatusChanger('exit_maintenance');
|
|
96
|
-
exports.exit_maintenance = exit_maintenance;
|
|
97
|
-
const enter_decommissioning = createUnitStatusChanger('enter_decommissioning');
|
|
98
|
-
exports.enter_decommissioning = enter_decommissioning;
|
|
99
|
-
const exit_decommissioning = createUnitStatusChanger('exit_decommissioning');
|
|
100
|
-
exports.exit_decommissioning = exit_decommissioning;
|
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
}
|