@0xobelisk/sui-client 1.1.1 → 1.1.3

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/dubhe.d.ts CHANGED
@@ -135,7 +135,12 @@ export declare class Dubhe {
135
135
  getObject(objectId: string): Promise<SuiObjectData>;
136
136
  getObjects(objectIds: string[]): Promise<SuiObjectData[]>;
137
137
  signTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/dist/cjs/cryptography").SignatureWithBytes>;
138
- signAndSendTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
138
+ signAndSendTxn({ tx, derivePathParams, onSuccess, onError, }: {
139
+ tx: Uint8Array | Transaction | SuiTx;
140
+ derivePathParams?: DerivePathParams;
141
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
142
+ onError?: (error: Error) => void | Promise<void>;
143
+ }): Promise<SuiTransactionBlockResponse>;
139
144
  sendTx(transaction: Uint8Array | string, signature: string | string[]): Promise<SuiTransactionBlockResponse>;
140
145
  waitForTransaction(digest: string): Promise<SuiTransactionBlockResponse>;
141
146
  /**
package/dist/index.js CHANGED
@@ -1477,9 +1477,11 @@ function createTx(meta, fn) {
1477
1477
  tx,
1478
1478
  params,
1479
1479
  typeArguments,
1480
- isRaw
1480
+ isRaw,
1481
+ onSuccess,
1482
+ onError
1481
1483
  }) => {
1482
- return await fn(tx, params, typeArguments, isRaw);
1484
+ return await fn(tx, params, typeArguments, isRaw, onSuccess, onError);
1483
1485
  }
1484
1486
  );
1485
1487
  }
@@ -1600,7 +1602,7 @@ var Dubhe = class {
1600
1602
  value: import_bcs3.bcs.u64()
1601
1603
  })
1602
1604
  });
1603
- __privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw) => {
1605
+ __privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw, onSuccess, onError) => {
1604
1606
  if (isRaw === true) {
1605
1607
  return tx.moveCall({
1606
1608
  target: `${this.contractFactory.packageId}::${meta.moduleName}::${meta.funcName}`,
@@ -1613,7 +1615,7 @@ var Dubhe = class {
1613
1615
  arguments: params,
1614
1616
  typeArguments
1615
1617
  });
1616
- return await this.signAndSendTxn(tx);
1618
+ return await this.signAndSendTxn({ tx, onSuccess, onError });
1617
1619
  });
1618
1620
  __privateAdd(this, _read, async (meta, tx, params, typeArguments, isRaw) => {
1619
1621
  if (isRaw === true) {
@@ -2010,7 +2012,7 @@ var Dubhe = class {
2010
2012
  (moudlevalue) => {
2011
2013
  const data = moudlevalue;
2012
2014
  const moduleName = data.name;
2013
- const objMoudleId = `${packageId}::${moduleName}`;
2015
+ const objMoudleId = `${this.packageId}::${moduleName}`;
2014
2016
  if (data.enums) {
2015
2017
  Object.entries(data.enums).forEach(([enumName, enumType]) => {
2016
2018
  const objectId = `${objMoudleId}::${enumName}`;
@@ -2072,7 +2074,7 @@ var Dubhe = class {
2072
2074
  if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
2073
2075
  __privateGet(this, _tx)[moduleName][funcName] = createTx(
2074
2076
  meta,
2075
- (tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
2077
+ (tx, p, typeArguments, isRaw, onSuccess, onError) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw, onSuccess, onError)
2076
2078
  );
2077
2079
  }
2078
2080
  }
@@ -2084,7 +2086,7 @@ var Dubhe = class {
2084
2086
  }
2085
2087
  }
2086
2088
  this.contractFactory = new SuiContractFactory({
2087
- packageId,
2089
+ packageId: this.packageId,
2088
2090
  metadata
2089
2091
  });
2090
2092
  }
@@ -2457,9 +2459,33 @@ var Dubhe = class {
2457
2459
  const keyPair = this.getSigner(derivePathParams);
2458
2460
  return await keyPair.signTransaction(txBytes);
2459
2461
  }
2460
- async signAndSendTxn(tx, derivePathParams) {
2461
- const { bytes, signature } = await this.signTxn(tx, derivePathParams);
2462
- return this.sendTx(bytes, signature);
2462
+ async signAndSendTxn({
2463
+ tx,
2464
+ derivePathParams,
2465
+ onSuccess,
2466
+ onError
2467
+ }) {
2468
+ try {
2469
+ const { bytes, signature } = await this.signTxn(tx, derivePathParams);
2470
+ const result = await this.sendTx(bytes, signature);
2471
+ if (result.effects?.status.status === "success") {
2472
+ if (onSuccess) {
2473
+ await onSuccess(result);
2474
+ }
2475
+ } else {
2476
+ if (onError) {
2477
+ await onError(
2478
+ new Error(`Transaction failed: ${result.effects?.status.error}`)
2479
+ );
2480
+ }
2481
+ }
2482
+ return result;
2483
+ } catch (error) {
2484
+ if (onError) {
2485
+ await onError(error);
2486
+ }
2487
+ throw error;
2488
+ }
2463
2489
  }
2464
2490
  async sendTx(transaction, signature) {
2465
2491
  return this.suiInteractor.sendTx(transaction, signature);
@@ -2476,7 +2502,7 @@ var Dubhe = class {
2476
2502
  async transferSui(recipient, amount, derivePathParams) {
2477
2503
  const tx = new SuiTx();
2478
2504
  tx.transferSui(recipient, amount);
2479
- return this.signAndSendTxn(tx, derivePathParams);
2505
+ return this.signAndSendTxn({ tx, derivePathParams });
2480
2506
  }
2481
2507
  /**
2482
2508
  * Transfer to mutliple recipients
@@ -2487,7 +2513,7 @@ var Dubhe = class {
2487
2513
  async transferSuiToMany(recipients, amounts, derivePathParams) {
2488
2514
  const tx = new SuiTx();
2489
2515
  tx.transferSuiToMany(recipients, amounts);
2490
- return this.signAndSendTxn(tx, derivePathParams);
2516
+ return this.signAndSendTxn({ tx, derivePathParams });
2491
2517
  }
2492
2518
  /**
2493
2519
  * Transfer the given amounts of coin to multiple recipients
@@ -2511,7 +2537,7 @@ var Dubhe = class {
2511
2537
  recipients,
2512
2538
  amounts
2513
2539
  );
2514
- return this.signAndSendTxn(tx, derivePathParams);
2540
+ return this.signAndSendTxn({ tx, derivePathParams });
2515
2541
  }
2516
2542
  async transferCoin(recipient, amount, coinType, derivePathParams) {
2517
2543
  return this.transferCoinToMany(
@@ -2524,7 +2550,7 @@ var Dubhe = class {
2524
2550
  async transferObjects(objects, recipient, derivePathParams) {
2525
2551
  const tx = new SuiTx();
2526
2552
  tx.transferObjects(objects, recipient);
2527
- return this.signAndSendTxn(tx, derivePathParams);
2553
+ return this.signAndSendTxn({ tx, derivePathParams });
2528
2554
  }
2529
2555
  async moveCall(callParams) {
2530
2556
  const {
@@ -2535,7 +2561,7 @@ var Dubhe = class {
2535
2561
  } = callParams;
2536
2562
  const tx = new SuiTx();
2537
2563
  tx.moveCall(target, args, typeArguments);
2538
- return this.signAndSendTxn(tx, derivePathParams);
2564
+ return this.signAndSendTxn({ tx, derivePathParams });
2539
2565
  }
2540
2566
  /**
2541
2567
  * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount
@@ -2562,7 +2588,7 @@ var Dubhe = class {
2562
2588
  async stakeSui(amount, validatorAddr, derivePathParams) {
2563
2589
  const tx = new SuiTx();
2564
2590
  tx.stakeSui(amount, validatorAddr);
2565
- return this.signAndSendTxn(tx, derivePathParams);
2591
+ return this.signAndSendTxn({ tx, derivePathParams });
2566
2592
  }
2567
2593
  /**
2568
2594
  * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.