@0xobelisk/sui-client 0.5.27 → 0.5.29

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,6 +1,6 @@
1
1
  import type { TransactionArgument, Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
2
2
  import type { SuiObjectArg, SuiAddressArg, SuiTxArg, SuiVecTxArg, SuiInputTypes, SuiAmountsArg } from 'src/types';
3
- export declare const getDefaultSuiInputType: (value: SuiTxArg) => 'u64' | 'bool' | 'object' | undefined;
3
+ export declare const getDefaultSuiInputType: (value: SuiTxArg) => "u64" | "bool" | "object" | undefined;
4
4
  /**
5
5
  * Since we know the elements in the array are the same type
6
6
  * If type is not provided, we will try to infer the type from the first element
@@ -60,10 +60,22 @@ export interface MessageMeta {
60
60
  readonly meta: SuiMoveMoudleFuncType;
61
61
  }
62
62
  export interface ContractQuery extends MessageMeta {
63
- (tx: Transaction, params: (TransactionArgument | SerializedBcs<any>)[], typeArguments?: string[], isRaw?: boolean): Promise<DevInspectResults | TransactionResult>;
63
+ (): Promise<DevInspectResults | TransactionResult>;
64
+ ({ tx, params, typeArguments, isRaw, }: {
65
+ tx: Transaction;
66
+ params?: (TransactionArgument | SerializedBcs<any>)[];
67
+ typeArguments?: string[];
68
+ isRaw?: boolean;
69
+ }): Promise<DevInspectResults | TransactionResult>;
64
70
  }
65
71
  export interface ContractTx extends MessageMeta {
66
- (tx: Transaction, params: (TransactionArgument | SerializedBcs<any>)[], typeArguments?: string[], isRaw?: boolean): Promise<SuiTransactionBlockResponse | TransactionResult>;
72
+ (): Promise<SuiTransactionBlockResponse | TransactionResult>;
73
+ ({ tx, params, typeArguments, isRaw, }: {
74
+ tx: Transaction;
75
+ params?: (TransactionArgument | SerializedBcs<any>)[];
76
+ typeArguments?: string[];
77
+ isRaw?: boolean;
78
+ }): Promise<SuiTransactionBlockResponse | TransactionResult>;
67
79
  }
68
80
  export type MapMessageTx = Record<string, ContractTx>;
69
81
  export type MapMessageQuery = Record<string, ContractQuery>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xobelisk/sui-client",
3
- "version": "0.5.27",
3
+ "version": "0.5.29",
4
4
  "description": "Tookit for interacting with move eps framework",
5
5
  "keywords": [
6
6
  "sui",
package/src/dubhe.ts CHANGED
@@ -39,6 +39,7 @@ import {
39
39
  } from './types';
40
40
  import { normalizeHexAddress, numberToAddressHex } from './utils';
41
41
  import { bcs, fromHEX, toHEX } from '@mysten/bcs';
42
+ import { ContractDataParsingError } from './errors';
42
43
 
43
44
  export function isUndefined(value?: unknown): value is undefined {
44
45
  return value === undefined;
@@ -57,19 +58,24 @@ function createQuery(
57
58
  meta: SuiMoveMoudleFuncType,
58
59
  fn: (
59
60
  tx: Transaction,
60
- params: (TransactionArgument | SerializedBcs<any>)[],
61
+ params?: (TransactionArgument | SerializedBcs<any>)[],
61
62
  typeArguments?: string[],
62
63
  isRaw?: boolean
63
64
  ) => Promise<DevInspectResults | TransactionResult>
64
65
  ): ContractQuery {
65
66
  return withMeta(
66
67
  meta,
67
- async (
68
- tx: Transaction,
69
- params: (TransactionArgument | SerializedBcs<any>)[],
70
- typeArguments?: string[],
71
- isRaw?: boolean
72
- ): Promise<DevInspectResults | TransactionResult> => {
68
+ async ({
69
+ tx,
70
+ params,
71
+ typeArguments,
72
+ isRaw,
73
+ }: {
74
+ tx: Transaction;
75
+ params?: (TransactionArgument | SerializedBcs<any>)[];
76
+ typeArguments?: string[];
77
+ isRaw?: boolean;
78
+ }): Promise<DevInspectResults | TransactionResult> => {
73
79
  const result = await fn(tx, params, typeArguments, isRaw);
74
80
  return result;
75
81
  }
@@ -80,19 +86,24 @@ function createTx(
80
86
  meta: SuiMoveMoudleFuncType,
81
87
  fn: (
82
88
  tx: Transaction,
83
- params: (TransactionArgument | SerializedBcs<any>)[],
89
+ params?: (TransactionArgument | SerializedBcs<any>)[],
84
90
  typeArguments?: string[],
85
91
  isRaw?: boolean
86
92
  ) => Promise<SuiTransactionBlockResponse | TransactionResult>
87
93
  ): ContractTx {
88
94
  return withMeta(
89
95
  meta,
90
- async (
91
- tx: Transaction,
92
- params: (TransactionArgument | SerializedBcs<any>)[],
93
- typeArguments?: string[],
94
- isRaw?: boolean
95
- ): Promise<SuiTransactionBlockResponse | TransactionResult> => {
96
+ async ({
97
+ tx,
98
+ params,
99
+ typeArguments,
100
+ isRaw,
101
+ }: {
102
+ tx: Transaction;
103
+ params?: (TransactionArgument | SerializedBcs<any>)[];
104
+ typeArguments?: string[];
105
+ isRaw?: boolean;
106
+ }): Promise<SuiTransactionBlockResponse | TransactionResult> => {
96
107
  return await fn(tx, params, typeArguments, isRaw);
97
108
  }
98
109
  );
@@ -306,7 +317,7 @@ export class Dubhe {
306
317
  #exec = async (
307
318
  meta: SuiMoveMoudleFuncType,
308
319
  tx: Transaction,
309
- params: (TransactionArgument | SerializedBcs<any>)[],
320
+ params?: (TransactionArgument | SerializedBcs<any>)[],
310
321
  typeArguments?: string[],
311
322
  isRaw?: boolean
312
323
  ) => {
@@ -329,7 +340,7 @@ export class Dubhe {
329
340
  #read = async (
330
341
  meta: SuiMoveMoudleFuncType,
331
342
  tx: Transaction,
332
- params: (TransactionArgument | SerializedBcs<any>)[],
343
+ params?: (TransactionArgument | SerializedBcs<any>)[],
333
344
  typeArguments?: string[],
334
345
  isRaw?: boolean
335
346
  ) => {
@@ -589,7 +600,7 @@ export class Dubhe {
589
600
  }
590
601
  return returnValues;
591
602
  } else {
592
- return undefined;
603
+ throw new ContractDataParsingError(dryResult);
593
604
  }
594
605
  }
595
606
 
@@ -0,0 +1,31 @@
1
+ export class ContractDataParsingError extends Error {
2
+ public readonly errorType: string;
3
+ public readonly functionName: string;
4
+ public readonly moduleAddress: string;
5
+ public readonly errorMessage: string;
6
+
7
+ constructor(dryResult: any) {
8
+ const error = dryResult?.effects?.status?.error || '';
9
+ const functionMatch = error
10
+ ? error.match(/function_name: Some\("([^"]+)"\)/)
11
+ : null;
12
+ const moduleMatch = error ? error.match(/address: ([a-fA-F0-9]+)/) : null;
13
+
14
+ const functionName = functionMatch ? functionMatch[1] : 'unknown';
15
+ const moduleAddress = moduleMatch ? '0x' + moduleMatch[1] : 'unknown';
16
+ const errorMessage = dryResult.error ? dryResult.error : 'UNKNOWN_ERROR';
17
+
18
+ const message = [
19
+ `\n- Function: ${functionName}`,
20
+ `- Module Address: ${moduleAddress}`,
21
+ `- Error Message: ${errorMessage}`,
22
+ ].join('\n');
23
+
24
+ super(message);
25
+
26
+ this.errorType = 'ContractDataParsingError';
27
+ this.functionName = functionName;
28
+ this.moduleAddress = moduleAddress;
29
+ this.errorMessage = errorMessage;
30
+ }
31
+ }
@@ -85,21 +85,33 @@ export interface MessageMeta {
85
85
  }
86
86
 
87
87
  export interface ContractQuery extends MessageMeta {
88
- (
89
- tx: Transaction,
90
- params: (TransactionArgument | SerializedBcs<any>)[],
91
- typeArguments?: string[],
92
- isRaw?: boolean
93
- ): Promise<DevInspectResults | TransactionResult>;
88
+ (): Promise<DevInspectResults | TransactionResult>;
89
+ ({
90
+ tx,
91
+ params,
92
+ typeArguments,
93
+ isRaw,
94
+ }: {
95
+ tx: Transaction;
96
+ params?: (TransactionArgument | SerializedBcs<any>)[];
97
+ typeArguments?: string[];
98
+ isRaw?: boolean;
99
+ }): Promise<DevInspectResults | TransactionResult>;
94
100
  }
95
101
 
96
102
  export interface ContractTx extends MessageMeta {
97
- (
98
- tx: Transaction,
99
- params: (TransactionArgument | SerializedBcs<any>)[],
100
- typeArguments?: string[],
101
- isRaw?: boolean
102
- ): Promise<SuiTransactionBlockResponse | TransactionResult>;
103
+ (): Promise<SuiTransactionBlockResponse | TransactionResult>;
104
+ ({
105
+ tx,
106
+ params,
107
+ typeArguments,
108
+ isRaw,
109
+ }: {
110
+ tx: Transaction;
111
+ params?: (TransactionArgument | SerializedBcs<any>)[];
112
+ typeArguments?: string[];
113
+ isRaw?: boolean;
114
+ }): Promise<SuiTransactionBlockResponse | TransactionResult>;
103
115
  }
104
116
 
105
117
  export type MapMessageTx = Record<string, ContractTx>;