@0xobelisk/sui-client 0.5.26 → 0.5.28
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/README.md +89 -196
- package/dist/dubhe.d.ts +1 -1
- package/dist/errors/index.d.ts +7 -0
- package/dist/index.js +59 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dubhe.ts +34 -1
- package/src/errors/index.ts +31 -0
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;
|
|
@@ -140,6 +141,22 @@ export class Dubhe {
|
|
|
140
141
|
'0x1::option::Option<u128>': bcs.option(bcs.u128()),
|
|
141
142
|
'0x1::option::Option<u256>': bcs.option(bcs.u256()),
|
|
142
143
|
'0x1::option::Option<bool>': bcs.option(bcs.bool()),
|
|
144
|
+
'0x1::option::Option<vector<address>>': bcs.option(
|
|
145
|
+
bcs.vector(
|
|
146
|
+
bcs.bytes(32).transform({
|
|
147
|
+
// To change the input type, you need to provide a type definition for the input
|
|
148
|
+
input: (val: string) => fromHEX(val),
|
|
149
|
+
output: (val) => toHEX(val),
|
|
150
|
+
})
|
|
151
|
+
)
|
|
152
|
+
),
|
|
153
|
+
'0x1::option::Option<vector<u8>>': bcs.option(bcs.vector(bcs.u8())),
|
|
154
|
+
'0x1::option::Option<vector<u16>>': bcs.option(bcs.vector(bcs.u16())),
|
|
155
|
+
'0x1::option::Option<vector<u32>>': bcs.option(bcs.vector(bcs.u32())),
|
|
156
|
+
'0x1::option::Option<vector<u64>>': bcs.option(bcs.vector(bcs.u64())),
|
|
157
|
+
'0x1::option::Option<vector<u128>>': bcs.option(bcs.vector(bcs.u128())),
|
|
158
|
+
'0x1::option::Option<vector<u256>>': bcs.option(bcs.vector(bcs.u256())),
|
|
159
|
+
'0x1::option::Option<vector<bool>>': bcs.option(bcs.vector(bcs.bool())),
|
|
143
160
|
'vector<address>': bcs.vector(
|
|
144
161
|
bcs.bytes(32).transform({
|
|
145
162
|
// To change the input type, you need to provide a type definition for the input
|
|
@@ -154,6 +171,22 @@ export class Dubhe {
|
|
|
154
171
|
'vector<u128>': bcs.vector(bcs.u128()),
|
|
155
172
|
'vector<u256>': bcs.vector(bcs.u256()),
|
|
156
173
|
'vector<bool>': bcs.vector(bcs.bool()),
|
|
174
|
+
'vector<vector<address>>': bcs.vector(
|
|
175
|
+
bcs.vector(
|
|
176
|
+
bcs.bytes(32).transform({
|
|
177
|
+
// To change the input type, you need to provide a type definition for the input
|
|
178
|
+
input: (val: string) => fromHEX(val),
|
|
179
|
+
output: (val) => toHEX(val),
|
|
180
|
+
})
|
|
181
|
+
)
|
|
182
|
+
),
|
|
183
|
+
'vector<vector<u8>>': bcs.vector(bcs.vector(bcs.u8())),
|
|
184
|
+
'vector<vector<u16>>': bcs.vector(bcs.vector(bcs.u16())),
|
|
185
|
+
'vector<vector<u32>>': bcs.vector(bcs.vector(bcs.u32())),
|
|
186
|
+
'vector<vector<u64>>': bcs.vector(bcs.vector(bcs.u64())),
|
|
187
|
+
'vector<vector<u128>>': bcs.vector(bcs.vector(bcs.u128())),
|
|
188
|
+
'vector<vector<u256>>': bcs.vector(bcs.vector(bcs.u256())),
|
|
189
|
+
'vector<vector<bool>>': bcs.vector(bcs.vector(bcs.bool())),
|
|
157
190
|
};
|
|
158
191
|
|
|
159
192
|
/**
|
|
@@ -557,7 +590,7 @@ export class Dubhe {
|
|
|
557
590
|
}
|
|
558
591
|
return returnValues;
|
|
559
592
|
} else {
|
|
560
|
-
|
|
593
|
+
throw new ContractDataParsingError(dryResult);
|
|
561
594
|
}
|
|
562
595
|
}
|
|
563
596
|
|
|
@@ -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
|
+
}
|