@mysten/sui 1.24.0 → 1.26.0
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/CHANGELOG.md +12 -0
- package/dist/cjs/client/client.d.ts +12 -2
- package/dist/cjs/client/client.js +16 -4
- package/dist/cjs/client/client.js.map +2 -2
- package/dist/cjs/experimental/client.d.ts +8 -0
- package/dist/cjs/experimental/client.js +43 -0
- package/dist/cjs/experimental/client.js.map +7 -0
- package/dist/cjs/experimental/core.d.ts +14 -0
- package/dist/cjs/experimental/core.js +31 -0
- package/dist/cjs/experimental/core.js.map +7 -0
- package/dist/cjs/experimental/errors.d.ts +8 -0
- package/dist/cjs/experimental/errors.js +54 -0
- package/dist/cjs/experimental/errors.js.map +7 -0
- package/dist/cjs/experimental/transports/jsonRPC.d.ts +62 -0
- package/dist/cjs/experimental/transports/jsonRPC.js +255 -0
- package/dist/cjs/experimental/transports/jsonRPC.js.map +7 -0
- package/dist/cjs/experimental/types.d.ts +211 -0
- package/dist/cjs/experimental/types.js +17 -0
- package/dist/cjs/experimental/types.js.map +7 -0
- package/dist/cjs/transactions/Arguments.d.ts +2 -2
- package/dist/cjs/transactions/Transaction.d.ts +4 -4
- package/dist/cjs/transactions/TransactionData.d.ts +2 -2
- package/dist/cjs/transactions/data/v1.d.ts +4 -4
- package/dist/cjs/transactions/data/v2.d.ts +4 -4
- package/dist/cjs/transactions/executor/parallel.d.ts +1 -1
- package/dist/cjs/transactions/executor/parallel.js +4 -4
- package/dist/cjs/transactions/executor/parallel.js.map +2 -2
- package/dist/cjs/transactions/executor/serial.d.ts +1 -1
- package/dist/cjs/transactions/executor/serial.js +2 -2
- package/dist/cjs/transactions/executor/serial.js.map +2 -2
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +84 -43
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/cjs/transactions/plugins/utils.d.ts +10 -6
- package/dist/cjs/transactions/plugins/utils.js +64 -37
- package/dist/cjs/transactions/plugins/utils.js.map +2 -2
- package/dist/cjs/utils/sui-types.d.ts +1 -2
- package/dist/cjs/utils/sui-types.js +3 -1
- package/dist/cjs/utils/sui-types.js.map +2 -2
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +2 -2
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/client/client.d.ts +12 -2
- package/dist/esm/client/client.js +16 -4
- package/dist/esm/client/client.js.map +2 -2
- package/dist/esm/experimental/client.d.ts +8 -0
- package/dist/esm/experimental/client.js +23 -0
- package/dist/esm/experimental/client.js.map +7 -0
- package/dist/esm/experimental/core.d.ts +14 -0
- package/dist/esm/experimental/core.js +11 -0
- package/dist/esm/experimental/core.js.map +7 -0
- package/dist/esm/experimental/errors.d.ts +8 -0
- package/dist/esm/experimental/errors.js +34 -0
- package/dist/esm/experimental/errors.js.map +7 -0
- package/dist/esm/experimental/transports/jsonRPC.d.ts +62 -0
- package/dist/esm/experimental/transports/jsonRPC.js +235 -0
- package/dist/esm/experimental/transports/jsonRPC.js.map +7 -0
- package/dist/esm/experimental/types.d.ts +211 -0
- package/dist/esm/experimental/types.js +1 -0
- package/dist/esm/experimental/types.js.map +7 -0
- package/dist/esm/transactions/Arguments.d.ts +2 -2
- package/dist/esm/transactions/Transaction.d.ts +4 -4
- package/dist/esm/transactions/TransactionData.d.ts +2 -2
- package/dist/esm/transactions/data/v1.d.ts +4 -4
- package/dist/esm/transactions/data/v2.d.ts +4 -4
- package/dist/esm/transactions/executor/parallel.d.ts +1 -1
- package/dist/esm/transactions/executor/parallel.js +4 -4
- package/dist/esm/transactions/executor/parallel.js.map +2 -2
- package/dist/esm/transactions/executor/serial.d.ts +1 -1
- package/dist/esm/transactions/executor/serial.js +2 -2
- package/dist/esm/transactions/executor/serial.js.map +2 -2
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +91 -44
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/esm/transactions/plugins/utils.d.ts +10 -6
- package/dist/esm/transactions/plugins/utils.js +64 -37
- package/dist/esm/transactions/plugins/utils.js.map +2 -2
- package/dist/esm/utils/sui-types.d.ts +1 -2
- package/dist/esm/utils/sui-types.js +3 -1
- package/dist/esm/utils/sui-types.js.map +2 -2
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +2 -2
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/client/client.ts +21 -2
- package/src/experimental/client.ts +61 -0
- package/src/experimental/core.ts +46 -0
- package/src/experimental/errors.ts +37 -0
- package/src/experimental/transports/jsonRPC.ts +263 -0
- package/src/experimental/types.ts +293 -0
- package/src/transactions/executor/parallel.ts +8 -3
- package/src/transactions/executor/serial.ts +2 -1
- package/src/transactions/plugins/NamedPackagesPlugin.ts +118 -62
- package/src/transactions/plugins/utils.ts +115 -47
- package/src/utils/sui-types.ts +6 -2
- package/src/version.ts +2 -2
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';
|
|
5
|
+
import { normalizeStructTag, parseStructTag } from '../../utils/sui-types.js';
|
|
6
|
+
import type { StructTag } from '../../utils/sui-types.js';
|
|
5
7
|
import type { TransactionDataBuilder } from '../TransactionData.js';
|
|
6
8
|
|
|
7
9
|
export type NamedPackagesPluginCache = {
|
|
@@ -21,9 +23,10 @@ export type NameResolutionRequest = {
|
|
|
21
23
|
* Looks up all `.move` names in a transaction block.
|
|
22
24
|
* Returns a list of all the names found.
|
|
23
25
|
*/
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
export function findNamesInTransaction(builder: TransactionDataBuilder): {
|
|
27
|
+
packages: string[];
|
|
28
|
+
types: string[];
|
|
29
|
+
} {
|
|
27
30
|
const packages: Set<string> = new Set();
|
|
28
31
|
const types: Set<string> = new Set();
|
|
29
32
|
|
|
@@ -40,7 +43,7 @@ export const findTransactionBlockNames = (
|
|
|
40
43
|
if (!tx) continue;
|
|
41
44
|
|
|
42
45
|
const pkg = tx.package.split('::')[0];
|
|
43
|
-
if (pkg
|
|
46
|
+
if (hasMvrName(pkg)) {
|
|
44
47
|
if (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);
|
|
45
48
|
packages.add(pkg);
|
|
46
49
|
}
|
|
@@ -54,32 +57,90 @@ export const findTransactionBlockNames = (
|
|
|
54
57
|
packages: [...packages],
|
|
55
58
|
types: [...types],
|
|
56
59
|
};
|
|
57
|
-
}
|
|
60
|
+
}
|
|
58
61
|
|
|
59
62
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
* Extracts all first-level types from a list of types.
|
|
64
|
+
* E.g. for the input `['@mvr/demo::a::A<@mvr/demo::b::B>']`,
|
|
65
|
+
* the output will be `['@mvr/demo::a::A', '@mvr/demo::b::B']`.
|
|
66
|
+
*/
|
|
67
|
+
export function getFirstLevelNamedTypes(types: string[]) {
|
|
68
|
+
const results: Set<string> = new Set();
|
|
69
|
+
|
|
65
70
|
for (const type of types) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
findMvrNames(type).forEach((name) => results.add(name));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return results;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Extracts all named types from a given type.
|
|
79
|
+
*/
|
|
80
|
+
function findMvrNames(type: string | StructTag) {
|
|
81
|
+
const types: Set<string> = new Set();
|
|
82
|
+
|
|
83
|
+
if (typeof type === 'string' && !hasMvrName(type)) return types;
|
|
84
|
+
|
|
85
|
+
let tag = isStructTag(type) ? type : parseStructTag(type);
|
|
86
|
+
|
|
87
|
+
if (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);
|
|
88
|
+
|
|
89
|
+
for (const param of tag.typeParams) {
|
|
90
|
+
findMvrNames(param).forEach((name) => types.add(name));
|
|
70
91
|
}
|
|
71
|
-
|
|
92
|
+
|
|
93
|
+
return types;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// /**
|
|
97
|
+
// * Allows partial replacements of known types with their resolved equivalents.
|
|
98
|
+
// * E.g. `@mvr/demo::a::A<@mvr/demo::b::B>` can be resolved, if we already have
|
|
99
|
+
// * the address for `@mvr/demo::b::B` and the address for `@mvr/demo::a::A`,
|
|
100
|
+
// * without the need to have the full type in the cache.
|
|
101
|
+
// *
|
|
102
|
+
// * Returns the fully composed resolved types (if any) in a `named-type -> normalized-type` map.
|
|
103
|
+
// */
|
|
104
|
+
export function populateNamedTypesFromCache(types: string[], typeCache: Record<string, string>) {
|
|
105
|
+
const composedTypes: Record<string, string> = {};
|
|
106
|
+
|
|
107
|
+
types.forEach((type) => {
|
|
108
|
+
const normalized = normalizeStructTag(findAndReplaceCachedTypes(type, typeCache));
|
|
109
|
+
composedTypes[type] = normalized;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return composedTypes;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Traverses a type, and replaces any found names with their resolved equivalents,
|
|
117
|
+
* based on the supplied type cache.
|
|
118
|
+
*/
|
|
119
|
+
function findAndReplaceCachedTypes(
|
|
120
|
+
tag: string | StructTag,
|
|
121
|
+
typeCache: Record<string, string>,
|
|
122
|
+
): StructTag {
|
|
123
|
+
const type = isStructTag(tag) ? tag : parseStructTag(tag);
|
|
124
|
+
|
|
125
|
+
let typeTag = `${type.address}::${type.module}::${type.name}`;
|
|
126
|
+
const cacheHit = typeCache[typeTag];
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
...type,
|
|
130
|
+
address: cacheHit ? cacheHit.split('::')[0] : type.address,
|
|
131
|
+
typeParams: type.typeParams.map((param) => findAndReplaceCachedTypes(param, typeCache)),
|
|
132
|
+
};
|
|
72
133
|
}
|
|
73
134
|
|
|
74
135
|
/**
|
|
75
136
|
* Replace all names & types in a transaction block
|
|
76
137
|
* with their resolved names/types.
|
|
77
138
|
*/
|
|
78
|
-
export
|
|
139
|
+
export function replaceNames(builder: TransactionDataBuilder, cache: NamedPackagesPluginCache) {
|
|
79
140
|
for (const command of builder.commands) {
|
|
80
141
|
// Replacements for `MakeMoveVec` commands (that can include types)
|
|
81
142
|
if (command.MakeMoveVec?.type) {
|
|
82
|
-
if (!command.MakeMoveVec.type
|
|
143
|
+
if (!hasMvrName(command.MakeMoveVec.type)) continue;
|
|
83
144
|
if (!cache.types[command.MakeMoveVec.type])
|
|
84
145
|
throw new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);
|
|
85
146
|
command.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];
|
|
@@ -91,11 +152,11 @@ export const replaceNames = (builder: TransactionDataBuilder, cache: NamedPackag
|
|
|
91
152
|
const nameParts = tx.package.split('::');
|
|
92
153
|
const name = nameParts[0];
|
|
93
154
|
|
|
94
|
-
if (name
|
|
155
|
+
if (hasMvrName(name) && !cache.packages[name])
|
|
95
156
|
throw new Error(`No address found for package: ${name}`);
|
|
96
157
|
|
|
97
158
|
// Replace package name with address.
|
|
98
|
-
if (name
|
|
159
|
+
if (hasMvrName(name)) {
|
|
99
160
|
nameParts[0] = cache.packages[name];
|
|
100
161
|
tx.package = nameParts.join('::');
|
|
101
162
|
}
|
|
@@ -104,7 +165,7 @@ export const replaceNames = (builder: TransactionDataBuilder, cache: NamedPackag
|
|
|
104
165
|
if (!types) continue;
|
|
105
166
|
|
|
106
167
|
for (let i = 0; i < types.length; i++) {
|
|
107
|
-
if (!types[i]
|
|
168
|
+
if (!hasMvrName(types[i])) continue;
|
|
108
169
|
|
|
109
170
|
if (!cache.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);
|
|
110
171
|
types[i] = cache.types[types[i]];
|
|
@@ -112,36 +173,43 @@ export const replaceNames = (builder: TransactionDataBuilder, cache: NamedPackag
|
|
|
112
173
|
|
|
113
174
|
tx.typeArguments = types;
|
|
114
175
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export const listToRequests = (
|
|
118
|
-
names: { packages: string[]; types: string[] },
|
|
119
|
-
batchSize: number,
|
|
120
|
-
): NameResolutionRequest[][] => {
|
|
121
|
-
const results: NameResolutionRequest[] = [];
|
|
122
|
-
const uniqueNames = deduplicate(names.packages);
|
|
123
|
-
const uniqueTypes = deduplicate(names.types);
|
|
124
|
-
|
|
125
|
-
for (const [idx, name] of uniqueNames.entries()) {
|
|
126
|
-
results.push({ id: idx, type: 'package', name } as NameResolutionRequest);
|
|
127
|
-
}
|
|
128
|
-
for (const [idx, type] of uniqueTypes.entries()) {
|
|
129
|
-
results.push({
|
|
130
|
-
id: idx + uniqueNames.length,
|
|
131
|
-
type: 'moveType',
|
|
132
|
-
name: type,
|
|
133
|
-
} as NameResolutionRequest);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return batch(results, batchSize);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const deduplicate = <T>(arr: T[]): T[] => [...new Set(arr)];
|
|
176
|
+
}
|
|
140
177
|
|
|
141
|
-
|
|
178
|
+
export function batch<T>(arr: T[], size: number): T[][] {
|
|
142
179
|
const batches = [];
|
|
143
180
|
for (let i = 0; i < arr.length; i += size) {
|
|
144
181
|
batches.push(arr.slice(i, i + size));
|
|
145
182
|
}
|
|
146
183
|
return batches;
|
|
147
|
-
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns a list of unique types that include a name
|
|
188
|
+
* from the given list. This list is retrieved from the Transaction Data.
|
|
189
|
+
*/
|
|
190
|
+
function getNamesFromTypeList(types: string[]) {
|
|
191
|
+
const names = new Set<string>();
|
|
192
|
+
for (const type of types) {
|
|
193
|
+
if (hasMvrName(type)) {
|
|
194
|
+
if (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);
|
|
195
|
+
names.add(type);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return names;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function hasMvrName(nameOrType: string) {
|
|
202
|
+
return (
|
|
203
|
+
nameOrType.includes(NAME_SEPARATOR) || nameOrType.includes('@') || nameOrType.includes('.sui')
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function isStructTag(type: string | StructTag): type is StructTag {
|
|
208
|
+
return (
|
|
209
|
+
typeof type === 'object' &&
|
|
210
|
+
'address' in type &&
|
|
211
|
+
'module' in type &&
|
|
212
|
+
'name' in type &&
|
|
213
|
+
'typeParams' in type
|
|
214
|
+
);
|
|
215
|
+
}
|
package/src/utils/sui-types.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import { fromBase58, splitGenericParameters } from '@mysten/bcs';
|
|
5
5
|
|
|
6
|
+
import { isValidNamedPackage } from './move-registry.js';
|
|
7
|
+
|
|
6
8
|
const TX_DIGEST_LENGTH = 32;
|
|
7
9
|
|
|
8
10
|
/** Returns whether the tx digest is valid based on the serialization format */
|
|
@@ -30,7 +32,7 @@ export function isValidSuiObjectId(value: string): boolean {
|
|
|
30
32
|
return isValidSuiAddress(value);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
type StructTag = {
|
|
35
|
+
export type StructTag = {
|
|
34
36
|
address: string;
|
|
35
37
|
module: string;
|
|
36
38
|
name: string;
|
|
@@ -46,6 +48,8 @@ function parseTypeTag(type: string): string | StructTag {
|
|
|
46
48
|
export function parseStructTag(type: string): StructTag {
|
|
47
49
|
const [address, module] = type.split('::');
|
|
48
50
|
|
|
51
|
+
const isMvrPackage = isValidNamedPackage(address);
|
|
52
|
+
|
|
49
53
|
const rest = type.slice(address.length + module.length + 4);
|
|
50
54
|
const name = rest.includes('<') ? rest.slice(0, rest.indexOf('<')) : rest;
|
|
51
55
|
const typeParams = rest.includes('<')
|
|
@@ -55,7 +59,7 @@ export function parseStructTag(type: string): StructTag {
|
|
|
55
59
|
: [];
|
|
56
60
|
|
|
57
61
|
return {
|
|
58
|
-
address: normalizeSuiAddress(address),
|
|
62
|
+
address: isMvrPackage ? address : normalizeSuiAddress(address),
|
|
59
63
|
module,
|
|
60
64
|
name,
|
|
61
65
|
typeParams,
|
package/src/version.ts
CHANGED