@flashbacktech/flashbackclient 0.1.55 → 0.1.57

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.
@@ -1,5 +1,5 @@
1
1
  import { ClientContext } from '.';
2
- import { Bucket, BucketCreateParams, BucketUpdateBasicParams, BucketUpdateConditionsParams } from '../models';
2
+ import { Bucket, BucketCreateParams, BucketMarketplace, BucketUpdateBasicParams, BucketUpdateConditionsParams } from '../models';
3
3
  /**
4
4
  * Bucket operations client for FlashOnStellar V2
5
5
  * Implements all bucket-related contract methods
@@ -74,7 +74,7 @@ export declare class BucketOps {
74
74
  * @param take - Number of items to take per page
75
75
  * @returns Promise resolving to an array of Bucket objects
76
76
  */
77
- getBuckets(skip?: number, take?: number): Promise<Bucket[]>;
77
+ getBuckets(skip?: number, take?: number): Promise<BucketMarketplace[]>;
78
78
  /**
79
79
  * Retrieves all buckets owned by a specific provider
80
80
  * @param provider_id - Address of the provider
@@ -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' },
@@ -46,6 +46,27 @@ export interface Bucket {
46
46
  status: BucketStatus;
47
47
  locked: boolean;
48
48
  }
49
+ export interface BucketMarketplace {
50
+ bucket_id: number;
51
+ name: string;
52
+ region: string;
53
+ provider_id: string;
54
+ provider_name: string;
55
+ provider_reputation: string;
56
+ fb_bucket_id: string;
57
+ price_per_gb_storage: bigint;
58
+ price_per_gb_egress: bigint;
59
+ versioning_enabled: boolean;
60
+ encryption_at_rest: boolean;
61
+ encryption_in_transit: boolean;
62
+ object_locking: boolean;
63
+ api_compatibility: string;
64
+ sla_avg_latency_ms: number;
65
+ sla_avg_uptime_pct: number;
66
+ created_ts: bigint;
67
+ status: BucketStatus;
68
+ locked: boolean;
69
+ }
49
70
  export declare enum BucketStatus {
50
71
  Active = "Active",
51
72
  Inactive = "Inactive",
@@ -130,6 +151,8 @@ export interface BucketUpdateBasicParams {
130
151
  country?: string;
131
152
  }
132
153
  export interface BucketUpdateConditionsParams {
154
+ name?: string;
155
+ region?: string;
133
156
  price_per_gb_storage?: bigint;
134
157
  price_per_gb_egress?: bigint;
135
158
  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,63 +225,50 @@ 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
- getResponse = await server.getTransaction(sendResponse.hash);
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
- 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);
282
256
  // In SDK v14, returnValue might be directly available
283
257
  if ('returnValue' in getResponse && getResponse.returnValue) {
284
- console.log('sendTransaction: Found returnValue directly in response:', getResponse.returnValue);
285
258
  return getResponse.returnValue;
286
259
  }
287
260
  // Make sure the transaction's resultMetaXdr is not empty
288
261
  if (!getResponse.resultMetaXdr) {
289
- console.error('sendTransaction: Empty resultMetaXdr in getTransaction response');
290
- console.error('sendTransaction: This might indicate a network response format change');
291
- console.error('sendTransaction: Available fields:', Object.keys(getResponse));
292
262
  // Try alternative response formats that might have been introduced
293
263
  if ('result' in getResponse && getResponse.result) {
294
- console.log('sendTransaction: Found result field:', getResponse.result);
295
264
  return getResponse.result;
296
265
  }
297
266
  // If we still can't find the return value, return the full response instead of throwing
298
- console.log('sendTransaction: No return value found, returning full response');
299
267
  return getResponse;
300
268
  }
301
269
  // Try to parse the resultMetaXdr if it exists
302
270
  try {
303
271
  const transactionMeta = getResponse.resultMetaXdr;
304
- console.log('sendTransaction: transactionMeta type:', typeof transactionMeta);
305
- console.log('sendTransaction: transactionMeta keys:', Object.keys(transactionMeta));
306
272
  // Try different approaches to extract the return value
307
273
  let returnValue = null;
308
274
  // Try the old v3 approach
@@ -314,7 +280,7 @@ const sendTransaction = async (context, signedTransactionXDR, bDebug = false) =>
314
280
  }
315
281
  }
316
282
  catch (v3Error) {
317
- console.log('sendTransaction: v3 approach failed, trying alternatives...');
283
+ // v3 approach failed, continue to alternatives
318
284
  }
319
285
  }
320
286
  // Try direct property access
@@ -327,22 +293,29 @@ const sendTransaction = async (context, signedTransactionXDR, bDebug = false) =>
327
293
  returnValue = transactionMeta._value.returnValue;
328
294
  }
329
295
  if (returnValue) {
330
- console.log('sendTransaction: returnValue extracted:', returnValue);
331
296
  return (0, stellar_sdk_1.scValToNative)(returnValue);
332
297
  }
333
- console.log('sendTransaction: No return value found in metadata, returning full response');
298
+ // No return value found in metadata, returning full response
334
299
  return getResponse;
335
300
  }
336
301
  catch (metaError) {
337
302
  console.error('sendTransaction: Error parsing resultMetaXdr:', metaError);
338
- console.log('sendTransaction: Returning full response due to metadata parsing error');
303
+ // Return full response due to metadata parsing error
339
304
  return getResponse;
340
305
  }
341
306
  }
342
307
  else if (String(getResponse.status).includes("NOT_FOUND")) {
343
- console.log('sendTransaction: Transaction not found yet, continuing to poll...');
344
- // Wait one second before the next poll
345
- await (0, timing_1.sleep)(1000);
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
+ };
346
319
  }
347
320
  else {
348
321
  console.error('sendTransaction: Transaction failed with unexpected status:', getResponse.status);
@@ -358,16 +331,6 @@ const sendTransaction = async (context, signedTransactionXDR, bDebug = false) =>
358
331
  }
359
332
  catch (err) {
360
333
  console.error('sendTransaction: Caught error:', err);
361
- console.error('sendTransaction: Error type:', typeof err);
362
- console.error('sendTransaction: Error constructor:', err?.constructor?.name);
363
- // Type guard to safely access error properties
364
- if (err instanceof Error) {
365
- console.error('sendTransaction: Error message:', err.message);
366
- console.error('sendTransaction: Error stack:', err.stack);
367
- }
368
- else {
369
- console.error('sendTransaction: Error is not an Error instance, value:', err);
370
- }
371
334
  // If it's already our wrapped error, don't wrap it again
372
335
  if (err instanceof Error && err.message.startsWith('Transaction sending error:')) {
373
336
  throw err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.1.55",
3
+ "version": "0.1.57",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"