@flashbacktech/flashbackclient 0.1.51 → 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.
- package/dist/stellarv2/wallet/transaction.js +128 -40
- package/package.json +1 -1
|
@@ -71,47 +71,80 @@ const getHorizonServer = (network) => {
|
|
|
71
71
|
};
|
|
72
72
|
exports.getHorizonServer = getHorizonServer;
|
|
73
73
|
const executeWalletTransaction = async (context, wallet_address, method, additionalArgs = []) => {
|
|
74
|
-
|
|
75
|
-
method,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
try {
|
|
75
|
+
console.log('executeWalletTransaction: Starting execution', { method, wallet_address, additionalArgs });
|
|
76
|
+
console.log('executeWalletTransaction: Calling prepareTransaction...');
|
|
77
|
+
const response = await prepareTransaction(context, wallet_address, {
|
|
78
|
+
method,
|
|
79
|
+
args: [{ value: wallet_address, type: "address" }, ...additionalArgs],
|
|
80
|
+
});
|
|
81
|
+
console.log('executeWalletTransaction: prepareTransaction response:', { isSuccess: response.isSuccess, isReadOnly: response.isReadOnly });
|
|
82
|
+
if (response.isSuccess) {
|
|
83
|
+
if (response.isReadOnly) {
|
|
84
|
+
console.log('executeWalletTransaction: Transaction is read-only, returning response');
|
|
85
|
+
return response;
|
|
86
|
+
}
|
|
87
|
+
console.log('executeWalletTransaction: Transaction is not read-only, signing...');
|
|
88
|
+
const signedTxXDR = await context.signTransaction(response.result);
|
|
89
|
+
console.log('executeWalletTransaction: Transaction signed successfully');
|
|
90
|
+
console.log('executeWalletTransaction: Sending transaction...');
|
|
91
|
+
const sendResponse = await sendTransaction(context, signedTxXDR);
|
|
92
|
+
console.log('executeWalletTransaction: Transaction sent successfully:', sendResponse);
|
|
93
|
+
return {
|
|
94
|
+
isSuccess: true,
|
|
95
|
+
isReadOnly: false,
|
|
96
|
+
result: sendResponse,
|
|
97
|
+
};
|
|
81
98
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
console.log('executeWalletTransaction: prepareTransaction failed, returning response');
|
|
100
|
+
return response;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error('executeWalletTransaction: Error occurred:', error);
|
|
104
|
+
console.error('executeWalletTransaction: Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
|
105
|
+
throw error;
|
|
89
106
|
}
|
|
90
|
-
return response;
|
|
91
107
|
};
|
|
92
108
|
exports.executeWalletTransaction = executeWalletTransaction;
|
|
93
109
|
const executeMultiWalletTransactions = async (context, wallet_address, methods, extraOperations = []) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
try {
|
|
111
|
+
console.log('executeMultiWalletTransactions: Starting execution', { wallet_address, methodsCount: methods.length, extraOperationsCount: extraOperations.length });
|
|
112
|
+
const contractCalls = methods.map(({ method, additionalArgs = [] }) => ({
|
|
113
|
+
method,
|
|
114
|
+
args: [
|
|
115
|
+
{ value: wallet_address, type: "address" },
|
|
116
|
+
...additionalArgs,
|
|
117
|
+
],
|
|
118
|
+
}));
|
|
119
|
+
console.log('executeMultiWalletTransactions: Contract calls prepared:', contractCalls);
|
|
120
|
+
console.log('executeMultiWalletTransactions: Calling prepareTransaction...');
|
|
121
|
+
const response = await prepareTransaction(context, wallet_address, contractCalls, extraOperations);
|
|
122
|
+
console.log('executeMultiWalletTransactions: prepareTransaction response:', { isSuccess: response.isSuccess, isReadOnly: response.isReadOnly });
|
|
123
|
+
if (response.isSuccess) {
|
|
124
|
+
if (response.isReadOnly) {
|
|
125
|
+
console.log('executeMultiWalletTransactions: Transaction is read-only, returning response');
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
console.log('executeMultiWalletTransactions: Transaction is not read-only, signing...');
|
|
129
|
+
const signedTxXDR = await context.signTransaction(response.result);
|
|
130
|
+
console.log('executeMultiWalletTransactions: Transaction signed successfully');
|
|
131
|
+
console.log('executeMultiWalletTransactions: Sending transaction...');
|
|
132
|
+
const sendResponse = await sendTransaction(context, signedTxXDR);
|
|
133
|
+
console.log('executeMultiWalletTransactions: Transaction sent successfully:', sendResponse);
|
|
134
|
+
return {
|
|
135
|
+
isSuccess: true,
|
|
136
|
+
isReadOnly: false,
|
|
137
|
+
result: sendResponse,
|
|
138
|
+
};
|
|
105
139
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
140
|
+
console.log('executeMultiWalletTransactions: prepareTransaction failed, returning response');
|
|
141
|
+
return response;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error('executeMultiWalletTransactions: Error occurred:', error);
|
|
145
|
+
console.error('executeMultiWalletTransactions: Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
|
146
|
+
throw error;
|
|
113
147
|
}
|
|
114
|
-
return response;
|
|
115
148
|
};
|
|
116
149
|
exports.executeMultiWalletTransactions = executeMultiWalletTransactions;
|
|
117
150
|
const prepareTransaction = async (context, address, contractCalls, extraOperations = []) => {
|
|
@@ -212,43 +245,98 @@ const signTransaction = async (context, xdrToSign, privateKey) => {
|
|
|
212
245
|
};
|
|
213
246
|
exports.signTransaction = signTransaction;
|
|
214
247
|
const sendTransaction = async (context, signedTransactionXDR, bDebug = false) => {
|
|
215
|
-
const server = getServer(context.network);
|
|
216
|
-
const signedTransaction = stellar_sdk_1.TransactionBuilder.fromXDR(signedTransactionXDR, context.network.networkPassphrase);
|
|
217
|
-
// Submit the transaction to the Stellar-RPC server. The RPC server will
|
|
218
|
-
// then submit the transaction into the network for us. Then we will have to
|
|
219
|
-
// wait, polling `getTransaction` until the transaction completes.
|
|
220
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...');
|
|
221
259
|
const sendResponse = await server.sendTransaction(signedTransaction);
|
|
260
|
+
console.log('sendTransaction: Server response received:', sendResponse);
|
|
222
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...');
|
|
223
264
|
let getResponse = await server.getTransaction(sendResponse.hash);
|
|
265
|
+
console.log('sendTransaction: Initial getTransaction response:', getResponse);
|
|
266
|
+
let pollCount = 0;
|
|
224
267
|
while (getResponse.status === "NOT_FOUND") {
|
|
268
|
+
pollCount++;
|
|
269
|
+
console.log(`sendTransaction: Polling attempt ${pollCount}, transaction not found yet...`);
|
|
225
270
|
// See if the transaction is complete
|
|
226
271
|
getResponse = await server.getTransaction(sendResponse.hash);
|
|
227
272
|
// Wait one second
|
|
228
273
|
await (0, timing_1.sleep)(1000);
|
|
229
274
|
}
|
|
275
|
+
console.log('sendTransaction: Final getTransaction response:', getResponse);
|
|
230
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);
|
|
231
282
|
// Make sure the transaction's resultMetaXDR is not empty
|
|
232
283
|
if (!getResponse.resultMetaXdr) {
|
|
233
|
-
|
|
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;
|
|
234
299
|
}
|
|
235
300
|
// Find the return value from the contract and return it
|
|
236
301
|
const transactionMeta = getResponse.resultMetaXdr;
|
|
302
|
+
console.log('sendTransaction: transactionMeta type:', typeof transactionMeta);
|
|
303
|
+
console.log('sendTransaction: transactionMeta keys:', Object.keys(transactionMeta));
|
|
237
304
|
const returnValue = transactionMeta.v3().sorobanMeta()?.returnValue();
|
|
305
|
+
console.log('sendTransaction: returnValue extracted:', returnValue);
|
|
238
306
|
if (returnValue) {
|
|
307
|
+
console.log('sendTransaction: Returning contract return value');
|
|
239
308
|
return (0, stellar_sdk_1.scValToNative)(returnValue);
|
|
240
309
|
}
|
|
310
|
+
console.log('sendTransaction: Returning full transaction response');
|
|
241
311
|
return getResponse; // Return the full transaction response
|
|
242
312
|
}
|
|
243
313
|
else {
|
|
314
|
+
console.error('sendTransaction: Transaction failed:', getResponse.resultXdr);
|
|
244
315
|
throw new Error(`Transaction failed: ${getResponse.resultXdr}`);
|
|
245
316
|
}
|
|
246
317
|
}
|
|
247
318
|
else {
|
|
319
|
+
console.error('sendTransaction: Send response status not PENDING:', sendResponse.status);
|
|
320
|
+
console.error('sendTransaction: Error result:', sendResponse.errorResult);
|
|
248
321
|
throw new Error(sendResponse.errorResult?.toString() || "Unknown error");
|
|
249
322
|
}
|
|
250
323
|
}
|
|
251
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
|
+
}
|
|
252
340
|
// Catch and report any errors we've thrown
|
|
253
341
|
throw new Error(`Transaction sending error: ${JSON.stringify(err)}`);
|
|
254
342
|
}
|