@thalalabs/surf 0.0.12 → 0.0.14
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/.changeset/README.md +1 -1
- package/.github/dependabot.yml +3 -3
- package/.github/workflows/publish.yml +2 -2
- package/CHANGELOG.md +12 -0
- package/README.md +22 -11
- package/build/cjs/abi/aggregator.js +56 -74
- package/build/cjs/abi/aggregator.js.map +1 -1
- package/build/cjs/abi/aptos_coin.js +98 -125
- package/build/cjs/abi/aptos_coin.js.map +1 -1
- package/build/cjs/abi/coin.js +456 -587
- package/build/cjs/abi/coin.js.map +1 -1
- package/build/cjs/abi/event.js +66 -106
- package/build/cjs/abi/event.js.map +1 -1
- package/build/cjs/abi/fixed_point64.js +287 -320
- package/build/cjs/abi/fixed_point64.js.map +1 -1
- package/build/cjs/abi/guid.js +84 -129
- package/build/cjs/abi/guid.js.map +1 -1
- package/build/cjs/abi/optional_aggregator.js +79 -108
- package/build/cjs/abi/optional_aggregator.js.map +1 -1
- package/build/cjs/abi/table.js +131 -222
- package/build/cjs/abi/table.js.map +1 -1
- package/build/cjs/core/Client.js +6 -2
- package/build/cjs/core/Client.js.map +1 -1
- package/build/cjs/core/createEntryPayload.js.map +1 -1
- package/build/cjs/core/index.js +1 -3
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/ensureTypes.js +11 -10
- package/build/cjs/ensureTypes.js.map +1 -1
- package/build/cjs/hooks/useWalletClient.js +2 -2
- package/build/cjs/hooks/useWalletClient.js.map +1 -1
- package/build/cjs/index.js.map +1 -1
- package/build/esm/abi/aggregator.js +56 -74
- package/build/esm/abi/aggregator.js.map +1 -1
- package/build/esm/abi/aptos_coin.js +98 -125
- package/build/esm/abi/aptos_coin.js.map +1 -1
- package/build/esm/abi/coin.js +456 -587
- package/build/esm/abi/coin.js.map +1 -1
- package/build/esm/abi/event.js +66 -106
- package/build/esm/abi/event.js.map +1 -1
- package/build/esm/abi/fixed_point64.js +287 -320
- package/build/esm/abi/fixed_point64.js.map +1 -1
- package/build/esm/abi/guid.js +84 -129
- package/build/esm/abi/guid.js.map +1 -1
- package/build/esm/abi/optional_aggregator.js +79 -108
- package/build/esm/abi/optional_aggregator.js.map +1 -1
- package/build/esm/abi/table.js +131 -222
- package/build/esm/abi/table.js.map +1 -1
- package/build/esm/core/Client.js +6 -2
- package/build/esm/core/Client.js.map +1 -1
- package/build/esm/core/createEntryPayload.js.map +1 -1
- package/build/esm/core/index.js +0 -1
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/ensureTypes.js +11 -10
- package/build/esm/ensureTypes.js.map +1 -1
- package/build/esm/hooks/useWalletClient.js +2 -2
- package/build/esm/hooks/useWalletClient.js.map +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/types/abi/aggregator.d.ts.map +1 -1
- package/build/types/abi/aptos_coin.d.ts.map +1 -1
- package/build/types/abi/coin.d.ts.map +1 -1
- package/build/types/abi/event.d.ts.map +1 -1
- package/build/types/abi/fixed_point64.d.ts.map +1 -1
- package/build/types/abi/guid.d.ts.map +1 -1
- package/build/types/abi/optional_aggregator.d.ts.map +1 -1
- package/build/types/abi/table.d.ts.map +1 -1
- package/build/types/core/Client.d.ts.map +1 -1
- package/build/types/core/index.d.ts +0 -1
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/ensureTypes.d.ts.map +1 -1
- package/build/types/hooks/useWalletClient.d.ts +2 -2
- package/build/types/hooks/useWalletClient.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/types/client/abiClient.d.ts +2 -0
- package/build/types/types/client/abiClient.d.ts.map +1 -1
- package/build/types/types/convertor/argsConvertor.d.ts +1 -1
- package/build/types/types/convertor/argsConvertor.d.ts.map +1 -1
- package/build/types/types/convertor/structConvertor.d.ts.map +1 -1
- package/build/types/types/moveTypes.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/abi/aggregator.ts +73 -91
- package/src/abi/aptos_coin.ts +117 -144
- package/src/abi/coin.ts +646 -777
- package/src/abi/event.ts +83 -123
- package/src/abi/fixed_point64.ts +340 -373
- package/src/abi/guid.ts +102 -147
- package/src/abi/optional_aggregator.ts +103 -132
- package/src/abi/table.ts +181 -272
- package/src/core/Client.ts +6 -1
- package/src/core/__tests__/accountResource.test.ts +54 -14
- package/src/core/__tests__/createEntryPayload.test.ts +244 -250
- package/src/core/__tests__/createViewPayload.test.ts +44 -58
- package/src/core/__tests__/option.test.ts +1 -1
- package/src/core/__tests__/useABI.test.ts +72 -63
- package/src/core/__tests__/view.test.ts +76 -60
- package/src/core/createEntryPayload.ts +4 -3
- package/src/core/index.ts +0 -1
- package/src/ensureTypes.ts +31 -28
- package/src/hooks/useWalletClient.ts +2 -2
- package/src/index.ts +8 -8
- package/src/types/client/abiClient.ts +2 -0
- package/src/types/convertor/argsConvertor.ts +1 -1
- package/src/types/convertor/structConvertor.ts +16 -15
- package/src/types/moveTypes.ts +5 -1
|
@@ -4,10 +4,10 @@ import { createViewPayload } from '../createViewPayload';
|
|
|
4
4
|
// TODO: add struct, vector of vector
|
|
5
5
|
describe('createViewPayload', () => {
|
|
6
6
|
// Act before assertions
|
|
7
|
-
beforeAll(async () => {
|
|
7
|
+
beforeAll(async () => {});
|
|
8
8
|
|
|
9
9
|
// Teardown (cleanup) after assertions
|
|
10
|
-
afterAll(() => {
|
|
10
|
+
afterAll(() => {});
|
|
11
11
|
|
|
12
12
|
it('basic type checking', async () => {
|
|
13
13
|
// no need to run, type check only.
|
|
@@ -46,7 +46,7 @@ describe('createViewPayload', () => {
|
|
|
46
46
|
// @ts-expect-error require a type_argument
|
|
47
47
|
type_arguments: [],
|
|
48
48
|
});
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it('basic', async () => {
|
|
@@ -87,7 +87,7 @@ describe('createViewPayload', () => {
|
|
|
87
87
|
],
|
|
88
88
|
type_arguments: [],
|
|
89
89
|
});
|
|
90
|
-
}
|
|
90
|
+
};
|
|
91
91
|
|
|
92
92
|
const payload = createViewPayload(TEST_ABI, {
|
|
93
93
|
function: 'bool_as_input',
|
|
@@ -123,7 +123,7 @@ describe('createViewPayload', () => {
|
|
|
123
123
|
],
|
|
124
124
|
type_arguments: [],
|
|
125
125
|
});
|
|
126
|
-
}
|
|
126
|
+
};
|
|
127
127
|
|
|
128
128
|
const payload = createViewPayload(TEST_ABI, {
|
|
129
129
|
function: 'address_as_input',
|
|
@@ -159,7 +159,7 @@ describe('createViewPayload', () => {
|
|
|
159
159
|
],
|
|
160
160
|
type_arguments: [],
|
|
161
161
|
});
|
|
162
|
-
}
|
|
162
|
+
};
|
|
163
163
|
|
|
164
164
|
const payload = createViewPayload(TEST_ABI, {
|
|
165
165
|
function: 'number_as_input',
|
|
@@ -232,66 +232,52 @@ describe('createViewPayload', () => {
|
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
const TEST_ABI = {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
235
|
+
address: '0x123',
|
|
236
|
+
name: 'test',
|
|
237
|
+
friends: [],
|
|
238
|
+
exposed_functions: [
|
|
239
239
|
{
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
"bool",
|
|
248
|
-
],
|
|
249
|
-
"return": []
|
|
240
|
+
name: 'bool_as_input',
|
|
241
|
+
visibility: 'public',
|
|
242
|
+
is_entry: false,
|
|
243
|
+
is_view: true,
|
|
244
|
+
generic_type_params: [],
|
|
245
|
+
params: ['bool', 'bool'],
|
|
246
|
+
return: [],
|
|
250
247
|
},
|
|
251
248
|
{
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
"u16",
|
|
260
|
-
"u32",
|
|
261
|
-
"u64",
|
|
262
|
-
"u128",
|
|
263
|
-
"u256",
|
|
264
|
-
],
|
|
265
|
-
"return": []
|
|
249
|
+
name: 'number_as_input',
|
|
250
|
+
visibility: 'public',
|
|
251
|
+
is_entry: false,
|
|
252
|
+
is_view: true,
|
|
253
|
+
generic_type_params: [],
|
|
254
|
+
params: ['u8', 'u16', 'u32', 'u64', 'u128', 'u256'],
|
|
255
|
+
return: [],
|
|
266
256
|
},
|
|
267
257
|
{
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
"address",
|
|
276
|
-
],
|
|
277
|
-
"return": []
|
|
258
|
+
name: 'address_as_input',
|
|
259
|
+
visibility: 'public',
|
|
260
|
+
is_entry: false,
|
|
261
|
+
is_view: true,
|
|
262
|
+
generic_type_params: [],
|
|
263
|
+
params: ['address', 'address'],
|
|
264
|
+
return: [],
|
|
278
265
|
},
|
|
279
266
|
{
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
267
|
+
name: 'vector_as_input',
|
|
268
|
+
visibility: 'public',
|
|
269
|
+
is_entry: false,
|
|
270
|
+
is_view: true,
|
|
271
|
+
generic_type_params: [],
|
|
272
|
+
params: [
|
|
273
|
+
'vector<u8>',
|
|
274
|
+
'vector<u16>',
|
|
275
|
+
'vector<u64>',
|
|
276
|
+
'vector<bool>',
|
|
277
|
+
'vector<address>',
|
|
291
278
|
],
|
|
292
|
-
|
|
279
|
+
return: [],
|
|
293
280
|
},
|
|
294
|
-
|
|
295
281
|
],
|
|
296
|
-
|
|
282
|
+
structs: [],
|
|
297
283
|
} as const;
|
|
@@ -25,49 +25,49 @@ describe('useABI', () => {
|
|
|
25
25
|
it('basic type checking', async () => {
|
|
26
26
|
// no need to run, type check only
|
|
27
27
|
() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
28
|
+
// @ts-expect-error cannot call a function not exist
|
|
29
|
+
client.useABI(COIN_ABI).view.not_exist_func({
|
|
30
|
+
arguments: ['0x1'],
|
|
31
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// @ts-expect-error cannot call a entry function from view
|
|
35
|
+
client.useABI(COIN_ABI).view.transfer({
|
|
36
|
+
arguments: ['0x1'],
|
|
37
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// @ts-expect-error cannot call a view function from entry
|
|
41
|
+
client.useABI(COIN_ABI).entry.balance({
|
|
42
|
+
arguments: ['0x1'],
|
|
43
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
client.useABI(TEST_ABI).view.address_as_input({
|
|
47
|
+
// @ts-expect-error require two args
|
|
48
|
+
arguments: ['0x1'],
|
|
49
|
+
type_arguments: [],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
client.useABI(TEST_ABI).view.address_as_input({
|
|
53
|
+
// @ts-expect-error require address
|
|
54
|
+
arguments: ['0x1', 1],
|
|
55
|
+
type_arguments: [],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
client.useABI(COIN_ABI).entry.transfer({
|
|
59
|
+
arguments: ['0x1', 1],
|
|
60
|
+
// @ts-expect-error require a type argument
|
|
61
|
+
type_arguments: [],
|
|
62
|
+
account,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// @ts-expect-error account is required for entry function
|
|
66
|
+
client.useABI(COIN_ABI).entry.transfer({
|
|
67
|
+
arguments: ['0x1', 1],
|
|
68
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it('view', async () => {
|
|
@@ -92,6 +92,19 @@ describe('useABI', () => {
|
|
|
92
92
|
`);
|
|
93
93
|
}, 60000);
|
|
94
94
|
|
|
95
|
+
it('view with ledger version', async () => {
|
|
96
|
+
const result = await client.useABI(COIN_ABI).view.balance({
|
|
97
|
+
arguments: ['0x1'],
|
|
98
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
99
|
+
ledger_version: '562606728',
|
|
100
|
+
});
|
|
101
|
+
expect(result).toMatchInlineSnapshot(`
|
|
102
|
+
[
|
|
103
|
+
50000358n,
|
|
104
|
+
]
|
|
105
|
+
`);
|
|
106
|
+
}, 60000);
|
|
107
|
+
|
|
95
108
|
it('entry', async () => {
|
|
96
109
|
const result = await client.useABI(COIN_ABI).entry.transfer({
|
|
97
110
|
arguments: ['0x1', 1],
|
|
@@ -117,23 +130,19 @@ describe('useABI', () => {
|
|
|
117
130
|
});
|
|
118
131
|
|
|
119
132
|
const TEST_ABI = {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
],
|
|
137
|
-
"structs": []
|
|
138
|
-
} as const;
|
|
139
|
-
|
|
133
|
+
address: '0x123',
|
|
134
|
+
name: 'test',
|
|
135
|
+
friends: [],
|
|
136
|
+
exposed_functions: [
|
|
137
|
+
{
|
|
138
|
+
name: 'address_as_input',
|
|
139
|
+
visibility: 'public',
|
|
140
|
+
is_entry: false,
|
|
141
|
+
is_view: true,
|
|
142
|
+
generic_type_params: [],
|
|
143
|
+
params: ['address', 'address'],
|
|
144
|
+
return: [],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
structs: [],
|
|
148
|
+
} as const;
|
|
@@ -7,84 +7,100 @@ import { createClient } from '../Client';
|
|
|
7
7
|
import { createViewPayload } from '../createViewPayload';
|
|
8
8
|
|
|
9
9
|
describe('call view functions', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const client = createClient({
|
|
11
|
+
nodeUrl: 'https://fullnode.testnet.aptoslabs.com/v1',
|
|
12
|
+
});
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const clientMain = createClient({
|
|
15
|
+
nodeUrl: 'https://fullnode.mainnet.aptoslabs.com/v1',
|
|
16
|
+
});
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// Act before assertions
|
|
19
|
+
beforeAll(async () => {});
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// Teardown (cleanup) after assertions
|
|
22
|
+
afterAll(() => {});
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
it('basic', async () => {
|
|
25
|
+
const viewPayload = createViewPayload(COIN_ABI, {
|
|
26
|
+
function: 'name',
|
|
27
|
+
arguments: [],
|
|
28
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
29
|
+
});
|
|
30
|
+
const result = await client.view(viewPayload);
|
|
31
|
+
expect(result).toMatchInlineSnapshot(`
|
|
32
32
|
[
|
|
33
33
|
"Aptos Coin",
|
|
34
34
|
]
|
|
35
35
|
`);
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
const viewPayload2 = createViewPayload(COIN_ABI, {
|
|
38
|
+
function: 'decimals',
|
|
39
|
+
arguments: [],
|
|
40
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
41
|
+
});
|
|
42
|
+
const result2 = await client.view(viewPayload2);
|
|
43
|
+
expect(result2).toMatchInlineSnapshot(`
|
|
44
44
|
[
|
|
45
45
|
8,
|
|
46
46
|
]
|
|
47
47
|
`);
|
|
48
|
-
|
|
48
|
+
}, 60000);
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
it('ledger version', async () => {
|
|
51
|
+
const viewPayload = createViewPayload(COIN_ABI, {
|
|
52
|
+
function: 'balance',
|
|
53
|
+
arguments: ['0x1'],
|
|
54
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
55
|
+
});
|
|
56
|
+
const result = await client.view(viewPayload, {
|
|
57
|
+
ledger_version: '562606728',
|
|
58
|
+
});
|
|
59
|
+
expect(result).toMatchInlineSnapshot(`
|
|
60
|
+
[
|
|
61
|
+
50000358n,
|
|
62
|
+
]
|
|
63
|
+
`);
|
|
64
|
+
}, 60000);
|
|
65
|
+
|
|
66
|
+
it('return struct', async () => {
|
|
67
|
+
const viewPayload = createViewPayload(TIERED_ORACLE_ABI, {
|
|
68
|
+
function: 'get_last_price',
|
|
69
|
+
arguments: [],
|
|
70
|
+
type_arguments: ['0x1::aptos_coin::AptosCoin'],
|
|
71
|
+
});
|
|
56
72
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
// The declaration in Move:
|
|
74
|
+
// struct FixedPoint64 has copy, drop, store { value: u128 }
|
|
75
|
+
const result = await clientMain.view(viewPayload);
|
|
76
|
+
expect(result.length).toBe(1);
|
|
77
|
+
expect((result[0] as any).v).toBeDefined();
|
|
78
|
+
expect(typeof (result[0] as any).v).toEqual('string');
|
|
79
|
+
}, 60000);
|
|
64
80
|
});
|
|
65
81
|
|
|
66
82
|
const TIERED_ORACLE_ABI = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
address: '0x92e95ed77b5ac815d3fbc2227e76db238339e9ca43ace45031ec2589bea5b8c',
|
|
84
|
+
name: 'tiered_oracle',
|
|
85
|
+
friends: [
|
|
86
|
+
'0x92e95ed77b5ac815d3fbc2227e76db238339e9ca43ace45031ec2589bea5b8c::oracle',
|
|
87
|
+
],
|
|
88
|
+
exposed_functions: [
|
|
89
|
+
{
|
|
90
|
+
name: 'get_last_price',
|
|
91
|
+
visibility: 'public',
|
|
92
|
+
is_entry: false,
|
|
93
|
+
is_view: true,
|
|
94
|
+
generic_type_params: [
|
|
73
95
|
{
|
|
74
|
-
|
|
75
|
-
visibility: 'public',
|
|
76
|
-
is_entry: false,
|
|
77
|
-
is_view: true,
|
|
78
|
-
generic_type_params: [
|
|
79
|
-
{
|
|
80
|
-
constraints: [],
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
params: [],
|
|
84
|
-
return: [
|
|
85
|
-
'0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64::FixedPoint64',
|
|
86
|
-
],
|
|
96
|
+
constraints: [],
|
|
87
97
|
},
|
|
88
|
-
|
|
89
|
-
|
|
98
|
+
],
|
|
99
|
+
params: [],
|
|
100
|
+
return: [
|
|
101
|
+
'0x4dcae85fc5559071906cd5c76b7420fcbb4b0a92f00ab40ffc394aadbbff5ee9::fixed_point64::FixedPoint64',
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
structs: [],
|
|
90
106
|
} as const;
|
|
@@ -139,11 +139,12 @@ function argToBCS(type: string, arg: any, serializer: BCS.Serializer) {
|
|
|
139
139
|
|
|
140
140
|
const optionRegex = /0x1::option::Option<([^]+)>/;
|
|
141
141
|
const optionMatch = type.match(optionRegex);
|
|
142
|
-
if (optionMatch) {
|
|
142
|
+
if (optionMatch) {
|
|
143
|
+
// It's 0x1::option::Option
|
|
143
144
|
const innerType = optionMatch[1]!;
|
|
144
145
|
serializer.serializeU32AsUleb128(arg.length);
|
|
145
|
-
if(!(arg instanceof Array) || arg.length > 1) {
|
|
146
|
-
|
|
146
|
+
if (!(arg instanceof Array) || arg.length > 1) {
|
|
147
|
+
throw new Error('Invalid input value for 0x1::option::Option.');
|
|
147
148
|
}
|
|
148
149
|
arg.forEach((arg) => argToBCS(innerType, arg, serializer));
|
|
149
150
|
return;
|
package/src/core/index.ts
CHANGED
package/src/ensureTypes.ts
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
function assertType(val: any, types: string[] | string, message?: string) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
if (!types?.includes(typeof val)) {
|
|
3
|
+
throw new Error(
|
|
4
|
+
message ||
|
|
5
|
+
`Invalid arg: ${val} type should be ${
|
|
6
|
+
types instanceof Array ? types.join(' or ') : types
|
|
7
|
+
}`,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
export function ensureBoolean(val: boolean | string): boolean {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
assertType(val, ['boolean', 'string']);
|
|
14
|
+
if (typeof val === 'boolean') {
|
|
15
|
+
return val;
|
|
16
|
+
}
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (val === 'true') {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (val === 'false') {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
throw new Error('Invalid boolean string.');
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
export function ensureNumber(val: number | string): number {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
assertType(val, ['number', 'string']);
|
|
30
|
+
if (typeof val === 'number') {
|
|
31
|
+
return val;
|
|
32
|
+
}
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const res = Number.parseInt(val, 10);
|
|
35
|
+
if (Number.isNaN(res)) {
|
|
36
|
+
throw new Error('Invalid number string.');
|
|
37
|
+
}
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
return res;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
export function ensureBigInt(val: number | bigint | string): bigint {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
+
assertType(val, ['number', 'bigint', 'string']);
|
|
44
|
+
return BigInt(val);
|
|
45
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useWallet } from '@aptos-labs/wallet-adapter-react';
|
|
2
|
-
import {
|
|
2
|
+
import { WalletClient } from '../core/WalletClient.js';
|
|
3
3
|
|
|
4
4
|
export const useWalletClient = ({ nodeUrl }: { nodeUrl: string }) => {
|
|
5
5
|
const wallet = useWallet();
|
|
6
6
|
return {
|
|
7
7
|
connected: wallet.connected,
|
|
8
8
|
client: wallet.connected
|
|
9
|
-
? new
|
|
9
|
+
? new WalletClient({ wallet, nodeUrl })
|
|
10
10
|
: undefined,
|
|
11
11
|
};
|
|
12
12
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from
|
|
2
|
+
createViewPayload,
|
|
3
|
+
createEntryPayload,
|
|
4
|
+
createClient,
|
|
5
|
+
} from './core/index.js';
|
|
6
6
|
|
|
7
7
|
export type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from
|
|
8
|
+
EntryPayload,
|
|
9
|
+
ViewPayload,
|
|
10
|
+
DefaultABITable,
|
|
11
|
+
} from './types/index.js';
|
|
@@ -24,6 +24,7 @@ export type ABIViewClient<T extends ABIRoot> = {
|
|
|
24
24
|
[TFuncName in ViewFunctionName<T>]: (payload: {
|
|
25
25
|
type_arguments: ExtractGenericArgsType<T, TFuncName>;
|
|
26
26
|
arguments: ExtractArgsType<T, TFuncName>;
|
|
27
|
+
ledger_version?: string;
|
|
27
28
|
}) => Promise<ExtractReturnType<T, TFuncName>>;
|
|
28
29
|
};
|
|
29
30
|
|
|
@@ -40,6 +41,7 @@ export type ABIResourceClient<TABITable extends ABITable, T extends ABIRoot> = {
|
|
|
40
41
|
[TStructName in ResourceStructName<T>]: (payload: {
|
|
41
42
|
type_arguments: ExtractStructGenericArgsType<T, TStructName>;
|
|
42
43
|
account: `0x${string}`;
|
|
44
|
+
ledger_version?: string;
|
|
43
45
|
}) => Promise<{
|
|
44
46
|
data: ExtractStructType<TABITable, T, TStructName>;
|
|
45
47
|
type: string;
|
|
@@ -55,5 +55,5 @@ type ConvertNonStructArgType<TMoveType extends MoveNonStructTypes> =
|
|
|
55
55
|
: TMoveType extends `0x1::object::Object<${string}>`
|
|
56
56
|
? `0x${string}`
|
|
57
57
|
: TMoveType extends `0x1::option::Option<${infer TInner}>`
|
|
58
|
-
?
|
|
58
|
+
? [ConvertArgType<TInner>] | []
|
|
59
59
|
: UnknownStruct<TMoveType>;
|