@flashbacktech/flashbackclient 0.1.52 → 0.1.53
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.
|
@@ -245,43 +245,98 @@ const signTransaction = async (context, xdrToSign, privateKey) => {
|
|
|
245
245
|
};
|
|
246
246
|
exports.signTransaction = signTransaction;
|
|
247
247
|
const sendTransaction = async (context, signedTransactionXDR, bDebug = false) => {
|
|
248
|
-
const server = getServer(context.network);
|
|
249
|
-
const signedTransaction = stellar_sdk_1.TransactionBuilder.fromXDR(signedTransactionXDR, context.network.networkPassphrase);
|
|
250
|
-
// Submit the transaction to the Stellar-RPC server. The RPC server will
|
|
251
|
-
// then submit the transaction into the network for us. Then we will have to
|
|
252
|
-
// wait, polling `getTransaction` until the transaction completes.
|
|
253
248
|
try {
|
|
249
|
+
console.log('sendTransaction: Starting transaction submission');
|
|
250
|
+
console.log('sendTransaction: Network:', context.network.networkPassphrase);
|
|
251
|
+
const server = getServer(context.network);
|
|
252
|
+
console.log('sendTransaction: Server obtained');
|
|
253
|
+
const signedTransaction = stellar_sdk_1.TransactionBuilder.fromXDR(signedTransactionXDR, context.network.networkPassphrase);
|
|
254
|
+
console.log('sendTransaction: Transaction parsed from XDR');
|
|
255
|
+
// Submit the transaction to the Stellar-RPC server. The RPC server will
|
|
256
|
+
// then submit the transaction into the network for us. Then we will have to
|
|
257
|
+
// wait, polling `getTransaction` until the transaction completes.
|
|
258
|
+
console.log('sendTransaction: Submitting transaction to server...');
|
|
254
259
|
const sendResponse = await server.sendTransaction(signedTransaction);
|
|
260
|
+
console.log('sendTransaction: Server response received:', sendResponse);
|
|
255
261
|
if (sendResponse.status === "PENDING") {
|
|
262
|
+
console.log('sendTransaction: Transaction is pending, hash:', sendResponse.hash);
|
|
263
|
+
console.log('sendTransaction: Starting to poll for transaction completion...');
|
|
256
264
|
let getResponse = await server.getTransaction(sendResponse.hash);
|
|
265
|
+
console.log('sendTransaction: Initial getTransaction response:', getResponse);
|
|
266
|
+
let pollCount = 0;
|
|
257
267
|
while (getResponse.status === "NOT_FOUND") {
|
|
268
|
+
pollCount++;
|
|
269
|
+
console.log(`sendTransaction: Polling attempt ${pollCount}, transaction not found yet...`);
|
|
258
270
|
// See if the transaction is complete
|
|
259
271
|
getResponse = await server.getTransaction(sendResponse.hash);
|
|
260
272
|
// Wait one second
|
|
261
273
|
await (0, timing_1.sleep)(1000);
|
|
262
274
|
}
|
|
275
|
+
console.log('sendTransaction: Final getTransaction response:', getResponse);
|
|
263
276
|
if (getResponse.status === "SUCCESS") {
|
|
277
|
+
console.log('sendTransaction: Transaction succeeded!');
|
|
278
|
+
console.log('sendTransaction: Full getResponse object:', JSON.stringify(getResponse, null, 2));
|
|
279
|
+
console.log('sendTransaction: getResponse keys:', Object.keys(getResponse));
|
|
280
|
+
console.log('sendTransaction: getResponse.resultMetaXdr exists:', !!getResponse.resultMetaXdr);
|
|
281
|
+
console.log('sendTransaction: getResponse.resultMetaXdr type:', typeof getResponse.resultMetaXdr);
|
|
264
282
|
// Make sure the transaction's resultMetaXDR is not empty
|
|
265
283
|
if (!getResponse.resultMetaXdr) {
|
|
266
|
-
|
|
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
|
+
// Try alternative response formats that might have been introduced
|
|
288
|
+
if ('result' in getResponse && getResponse.result) {
|
|
289
|
+
console.log('sendTransaction: Found result field:', getResponse.result);
|
|
290
|
+
return getResponse.result;
|
|
291
|
+
}
|
|
292
|
+
if ('returnValue' in getResponse && getResponse.returnValue) {
|
|
293
|
+
console.log('sendTransaction: Found returnValue field:', getResponse.returnValue);
|
|
294
|
+
return getResponse.returnValue;
|
|
295
|
+
}
|
|
296
|
+
// 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
|
+
return getResponse;
|
|
267
299
|
}
|
|
268
300
|
// Find the return value from the contract and return it
|
|
269
301
|
const transactionMeta = getResponse.resultMetaXdr;
|
|
302
|
+
console.log('sendTransaction: transactionMeta type:', typeof transactionMeta);
|
|
303
|
+
console.log('sendTransaction: transactionMeta keys:', Object.keys(transactionMeta));
|
|
270
304
|
const returnValue = transactionMeta.v3().sorobanMeta()?.returnValue();
|
|
305
|
+
console.log('sendTransaction: returnValue extracted:', returnValue);
|
|
271
306
|
if (returnValue) {
|
|
307
|
+
console.log('sendTransaction: Returning contract return value');
|
|
272
308
|
return (0, stellar_sdk_1.scValToNative)(returnValue);
|
|
273
309
|
}
|
|
310
|
+
console.log('sendTransaction: Returning full transaction response');
|
|
274
311
|
return getResponse; // Return the full transaction response
|
|
275
312
|
}
|
|
276
313
|
else {
|
|
314
|
+
console.error('sendTransaction: Transaction failed:', getResponse.resultXdr);
|
|
277
315
|
throw new Error(`Transaction failed: ${getResponse.resultXdr}`);
|
|
278
316
|
}
|
|
279
317
|
}
|
|
280
318
|
else {
|
|
319
|
+
console.error('sendTransaction: Send response status not PENDING:', sendResponse.status);
|
|
320
|
+
console.error('sendTransaction: Error result:', sendResponse.errorResult);
|
|
281
321
|
throw new Error(sendResponse.errorResult?.toString() || "Unknown error");
|
|
282
322
|
}
|
|
283
323
|
}
|
|
284
324
|
catch (err) {
|
|
325
|
+
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
|
+
// If it's already our wrapped error, don't wrap it again
|
|
337
|
+
if (err instanceof Error && err.message.startsWith('Transaction sending error:')) {
|
|
338
|
+
throw err;
|
|
339
|
+
}
|
|
285
340
|
// Catch and report any errors we've thrown
|
|
286
341
|
throw new Error(`Transaction sending error: ${JSON.stringify(err)}`);
|
|
287
342
|
}
|