@flashbacktech/flashbackclient 0.1.54 → 0.1.56
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.
|
@@ -99,6 +99,8 @@ class BucketOps {
|
|
|
99
99
|
this.updateBucketConditions = (0, decorator_1.withSignature)(async (provider_id, bucket_id, params) => {
|
|
100
100
|
await (0, transaction_1.executeWalletTransaction)(this.context, provider_id, "update_bucket_conditions", [
|
|
101
101
|
{ value: bucket_id, type: 'u32' },
|
|
102
|
+
{ value: params.name || null, type: 'string' },
|
|
103
|
+
{ value: params.region || null, type: 'string' },
|
|
102
104
|
{ value: params.price_per_gb_storage || null, type: 'u128' },
|
|
103
105
|
{ value: params.price_per_gb_egress || null, type: 'u128' },
|
|
104
106
|
{ value: params.sla_avg_latency_ms || null, type: 'u32' },
|
|
@@ -130,6 +130,8 @@ export interface BucketUpdateBasicParams {
|
|
|
130
130
|
country?: string;
|
|
131
131
|
}
|
|
132
132
|
export interface BucketUpdateConditionsParams {
|
|
133
|
+
name?: string;
|
|
134
|
+
region?: string;
|
|
133
135
|
price_per_gb_storage?: bigint;
|
|
134
136
|
price_per_gb_egress?: bigint;
|
|
135
137
|
sla_avg_latency_ms?: number;
|
|
@@ -72,43 +72,32 @@ const getHorizonServer = (network) => {
|
|
|
72
72
|
exports.getHorizonServer = getHorizonServer;
|
|
73
73
|
const executeWalletTransaction = async (context, wallet_address, method, additionalArgs = []) => {
|
|
74
74
|
try {
|
|
75
|
-
console.log('executeWalletTransaction: Starting execution', { method, wallet_address, additionalArgs });
|
|
76
|
-
console.log('executeWalletTransaction: Calling prepareTransaction...');
|
|
77
75
|
const response = await prepareTransaction(context, wallet_address, {
|
|
78
76
|
method,
|
|
79
77
|
args: [{ value: wallet_address, type: "address" }, ...additionalArgs],
|
|
80
78
|
});
|
|
81
|
-
console.log('executeWalletTransaction: prepareTransaction response:', { isSuccess: response.isSuccess, isReadOnly: response.isReadOnly });
|
|
82
79
|
if (response.isSuccess) {
|
|
83
80
|
if (response.isReadOnly) {
|
|
84
|
-
console.log('executeWalletTransaction: Transaction is read-only, returning response');
|
|
85
81
|
return response;
|
|
86
82
|
}
|
|
87
|
-
console.log('executeWalletTransaction: Transaction is not read-only, signing...');
|
|
88
83
|
const signedTxXDR = await context.signTransaction(response.result);
|
|
89
|
-
console.log('executeWalletTransaction: Transaction signed successfully');
|
|
90
|
-
console.log('executeWalletTransaction: Sending transaction...');
|
|
91
84
|
const sendResponse = await sendTransaction(context, signedTxXDR);
|
|
92
|
-
console.log('executeWalletTransaction: Transaction sent successfully:', sendResponse);
|
|
93
85
|
return {
|
|
94
86
|
isSuccess: true,
|
|
95
87
|
isReadOnly: false,
|
|
96
88
|
result: sendResponse,
|
|
97
89
|
};
|
|
98
90
|
}
|
|
99
|
-
console.log('executeWalletTransaction: prepareTransaction failed, returning response');
|
|
100
91
|
return response;
|
|
101
92
|
}
|
|
102
93
|
catch (error) {
|
|
103
94
|
console.error('executeWalletTransaction: Error occurred:', error);
|
|
104
|
-
console.error('executeWalletTransaction: Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
|
105
95
|
throw error;
|
|
106
96
|
}
|
|
107
97
|
};
|
|
108
98
|
exports.executeWalletTransaction = executeWalletTransaction;
|
|
109
99
|
const executeMultiWalletTransactions = async (context, wallet_address, methods, extraOperations = []) => {
|
|
110
100
|
try {
|
|
111
|
-
console.log('executeMultiWalletTransactions: Starting execution', { wallet_address, methodsCount: methods.length, extraOperationsCount: extraOperations.length });
|
|
112
101
|
const contractCalls = methods.map(({ method, additionalArgs = [] }) => ({
|
|
113
102
|
method,
|
|
114
103
|
args: [
|
|
@@ -116,33 +105,23 @@ const executeMultiWalletTransactions = async (context, wallet_address, methods,
|
|
|
116
105
|
...additionalArgs,
|
|
117
106
|
],
|
|
118
107
|
}));
|
|
119
|
-
console.log('executeMultiWalletTransactions: Contract calls prepared:', contractCalls);
|
|
120
|
-
console.log('executeMultiWalletTransactions: Calling prepareTransaction...');
|
|
121
108
|
const response = await prepareTransaction(context, wallet_address, contractCalls, extraOperations);
|
|
122
|
-
console.log('executeMultiWalletTransactions: prepareTransaction response:', { isSuccess: response.isSuccess, isReadOnly: response.isReadOnly });
|
|
123
109
|
if (response.isSuccess) {
|
|
124
110
|
if (response.isReadOnly) {
|
|
125
|
-
console.log('executeMultiWalletTransactions: Transaction is read-only, returning response');
|
|
126
111
|
return response;
|
|
127
112
|
}
|
|
128
|
-
console.log('executeMultiWalletTransactions: Transaction is not read-only, signing...');
|
|
129
113
|
const signedTxXDR = await context.signTransaction(response.result);
|
|
130
|
-
console.log('executeMultiWalletTransactions: Transaction signed successfully');
|
|
131
|
-
console.log('executeMultiWalletTransactions: Sending transaction...');
|
|
132
114
|
const sendResponse = await sendTransaction(context, signedTxXDR);
|
|
133
|
-
console.log('executeMultiWalletTransactions: Transaction sent successfully:', sendResponse);
|
|
134
115
|
return {
|
|
135
116
|
isSuccess: true,
|
|
136
117
|
isReadOnly: false,
|
|
137
118
|
result: sendResponse,
|
|
138
119
|
};
|
|
139
120
|
}
|
|
140
|
-
console.log('executeMultiWalletTransactions: prepareTransaction failed, returning response');
|
|
141
121
|
return response;
|
|
142
122
|
}
|
|
143
123
|
catch (error) {
|
|
144
124
|
console.error('executeMultiWalletTransactions: Error occurred:', error);
|
|
145
|
-
console.error('executeMultiWalletTransactions: Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
|
146
125
|
throw error;
|
|
147
126
|
}
|
|
148
127
|
};
|
|
@@ -246,72 +225,101 @@ const signTransaction = async (context, xdrToSign, privateKey) => {
|
|
|
246
225
|
exports.signTransaction = signTransaction;
|
|
247
226
|
const sendTransaction = async (context, signedTransactionXDR, bDebug = false) => {
|
|
248
227
|
try {
|
|
249
|
-
console.log('sendTransaction: Starting transaction submission');
|
|
250
|
-
console.log('sendTransaction: Network:', context.network.networkPassphrase);
|
|
251
228
|
const server = getServer(context.network);
|
|
252
|
-
console.log('sendTransaction: Server obtained');
|
|
253
229
|
const signedTransaction = stellar_sdk_1.TransactionBuilder.fromXDR(signedTransactionXDR, context.network.networkPassphrase);
|
|
254
|
-
console.log('sendTransaction: Transaction parsed from XDR');
|
|
255
230
|
// Submit the transaction to the Stellar-RPC server. The RPC server will
|
|
256
231
|
// then submit the transaction into the network for us. Then we will have to
|
|
257
232
|
// wait, polling `getTransaction` until the transaction completes.
|
|
258
|
-
console.log('sendTransaction: Submitting transaction to server...');
|
|
259
233
|
const sendResponse = await server.sendTransaction(signedTransaction);
|
|
260
|
-
console.log('sendTransaction: Server response received:', sendResponse);
|
|
261
234
|
if (sendResponse.status === "PENDING") {
|
|
262
|
-
console.log('sendTransaction: Transaction is pending, hash:', sendResponse.hash);
|
|
263
|
-
console.log('sendTransaction: Starting to poll for transaction completion...');
|
|
264
235
|
let getResponse = await server.getTransaction(sendResponse.hash);
|
|
265
|
-
console.log('sendTransaction: Initial getTransaction response:', getResponse);
|
|
266
236
|
let pollCount = 0;
|
|
267
237
|
while (getResponse.status === "NOT_FOUND") {
|
|
268
238
|
pollCount++;
|
|
269
|
-
console.log(`sendTransaction: Polling attempt ${pollCount}, transaction not found yet...`);
|
|
270
239
|
// See if the transaction is complete
|
|
271
|
-
|
|
240
|
+
try {
|
|
241
|
+
getResponse = await server.getTransaction(sendResponse.hash);
|
|
242
|
+
}
|
|
243
|
+
catch (pollError) {
|
|
244
|
+
console.error(`sendTransaction: Error during polling attempt ${pollCount}:`, pollError);
|
|
245
|
+
// If we get an XDR parsing error during polling, wait a bit longer and retry
|
|
246
|
+
if (pollError instanceof Error && pollError.message.includes('Bad union switch')) {
|
|
247
|
+
await (0, timing_1.sleep)(2000); // Wait 2 seconds instead of 1
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
throw pollError;
|
|
251
|
+
}
|
|
272
252
|
// Wait one second
|
|
273
253
|
await (0, timing_1.sleep)(1000);
|
|
274
254
|
}
|
|
275
|
-
console.log('sendTransaction: Final getTransaction response:', getResponse);
|
|
276
255
|
if (getResponse.status === "SUCCESS") {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// Make sure the transaction's resultMetaXDR is not empty
|
|
256
|
+
// In SDK v14, returnValue might be directly available
|
|
257
|
+
if ('returnValue' in getResponse && getResponse.returnValue) {
|
|
258
|
+
return getResponse.returnValue;
|
|
259
|
+
}
|
|
260
|
+
// Make sure the transaction's resultMetaXdr is not empty
|
|
283
261
|
if (!getResponse.resultMetaXdr) {
|
|
284
|
-
console.error('sendTransaction: Empty resultMetaXDR in getTransaction response');
|
|
285
|
-
console.error('sendTransaction: This might indicate a network response format change');
|
|
286
|
-
console.error('sendTransaction: Available fields:', Object.keys(getResponse));
|
|
287
262
|
// Try alternative response formats that might have been introduced
|
|
288
263
|
if ('result' in getResponse && getResponse.result) {
|
|
289
|
-
console.log('sendTransaction: Found result field:', getResponse.result);
|
|
290
264
|
return getResponse.result;
|
|
291
265
|
}
|
|
292
|
-
if ('returnValue' in getResponse && getResponse.returnValue) {
|
|
293
|
-
console.log('sendTransaction: Found returnValue field:', getResponse.returnValue);
|
|
294
|
-
return getResponse.returnValue;
|
|
295
|
-
}
|
|
296
266
|
// If we still can't find the return value, return the full response instead of throwing
|
|
297
|
-
console.log('sendTransaction: No return value found, returning full response');
|
|
298
267
|
return getResponse;
|
|
299
268
|
}
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
269
|
+
// Try to parse the resultMetaXdr if it exists
|
|
270
|
+
try {
|
|
271
|
+
const transactionMeta = getResponse.resultMetaXdr;
|
|
272
|
+
// Try different approaches to extract the return value
|
|
273
|
+
let returnValue = null;
|
|
274
|
+
// Try the old v3 approach
|
|
275
|
+
if (transactionMeta.v3 && typeof transactionMeta.v3 === 'function') {
|
|
276
|
+
try {
|
|
277
|
+
const sorobanMeta = transactionMeta.v3().sorobanMeta();
|
|
278
|
+
if (sorobanMeta) {
|
|
279
|
+
returnValue = sorobanMeta.returnValue();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (v3Error) {
|
|
283
|
+
// v3 approach failed, continue to alternatives
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// Try direct property access
|
|
287
|
+
if (!returnValue && 'returnValue' in transactionMeta && transactionMeta.returnValue) {
|
|
288
|
+
returnValue = transactionMeta.returnValue;
|
|
289
|
+
}
|
|
290
|
+
// Try nested access
|
|
291
|
+
if (!returnValue && '_value' in transactionMeta && transactionMeta._value &&
|
|
292
|
+
typeof transactionMeta._value === 'object' && 'returnValue' in transactionMeta._value) {
|
|
293
|
+
returnValue = transactionMeta._value.returnValue;
|
|
294
|
+
}
|
|
295
|
+
if (returnValue) {
|
|
296
|
+
return (0, stellar_sdk_1.scValToNative)(returnValue);
|
|
297
|
+
}
|
|
298
|
+
// No return value found in metadata, returning full response
|
|
299
|
+
return getResponse;
|
|
300
|
+
}
|
|
301
|
+
catch (metaError) {
|
|
302
|
+
console.error('sendTransaction: Error parsing resultMetaXdr:', metaError);
|
|
303
|
+
// Return full response due to metadata parsing error
|
|
304
|
+
return getResponse;
|
|
309
305
|
}
|
|
310
|
-
|
|
311
|
-
|
|
306
|
+
}
|
|
307
|
+
else if (String(getResponse.status).includes("NOT_FOUND")) {
|
|
308
|
+
// If we get NOT_FOUND after polling, the transaction might have succeeded but we can't parse the response
|
|
309
|
+
// This could happen due to XDR format changes in the network
|
|
310
|
+
console.warn('sendTransaction: Transaction status indicates NOT_FOUND after polling - this might indicate XDR parsing issues');
|
|
311
|
+
console.warn('sendTransaction: Since the transaction was submitted successfully, we will assume it succeeded');
|
|
312
|
+
// Return a success response with the transaction hash
|
|
313
|
+
return {
|
|
314
|
+
status: "SUCCESS",
|
|
315
|
+
hash: sendResponse.hash,
|
|
316
|
+
message: "Transaction submitted successfully (XDR parsing issue prevented detailed response)",
|
|
317
|
+
transactionHash: sendResponse.hash
|
|
318
|
+
};
|
|
312
319
|
}
|
|
313
320
|
else {
|
|
314
|
-
console.error('sendTransaction: Transaction failed:', getResponse.
|
|
321
|
+
console.error('sendTransaction: Transaction failed with unexpected status:', getResponse.status);
|
|
322
|
+
console.error('sendTransaction: Error result:', getResponse.resultXdr);
|
|
315
323
|
throw new Error(`Transaction failed: ${getResponse.resultXdr}`);
|
|
316
324
|
}
|
|
317
325
|
}
|
|
@@ -323,16 +331,6 @@ const sendTransaction = async (context, signedTransactionXDR, bDebug = false) =>
|
|
|
323
331
|
}
|
|
324
332
|
catch (err) {
|
|
325
333
|
console.error('sendTransaction: Caught error:', err);
|
|
326
|
-
console.error('sendTransaction: Error type:', typeof err);
|
|
327
|
-
console.error('sendTransaction: Error constructor:', err?.constructor?.name);
|
|
328
|
-
// Type guard to safely access error properties
|
|
329
|
-
if (err instanceof Error) {
|
|
330
|
-
console.error('sendTransaction: Error message:', err.message);
|
|
331
|
-
console.error('sendTransaction: Error stack:', err.stack);
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
console.error('sendTransaction: Error is not an Error instance, value:', err);
|
|
335
|
-
}
|
|
336
334
|
// If it's already our wrapped error, don't wrap it again
|
|
337
335
|
if (err instanceof Error && err.message.startsWith('Transaction sending error:')) {
|
|
338
336
|
throw err;
|