@sentio/cli 4.3.0 → 4.3.1
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/index.js +30 -33
- package/package.json +1 -1
- package/src/abi.ts +62 -71
- package/src/commands/build.ts +5 -5
package/dist/index.js
CHANGED
|
@@ -130816,27 +130816,24 @@ function normalizedModule(name, m) {
|
|
|
130816
130816
|
functions: Object.entries(m.exposedFunctions ?? {}).map(([k, f]) => normalizedFunction(k, f))
|
|
130817
130817
|
};
|
|
130818
130818
|
}
|
|
130819
|
-
function normalizedModulesToAbi(modules) {
|
|
130819
|
+
function normalizedModulesToAbi(modules, fallbackAddress) {
|
|
130820
130820
|
const map = modules?.result ?? modules;
|
|
130821
|
-
return (Array.isArray(map) ? map.map((m) => [m.name, m]) : Object.entries(map ?? {})).map(([n, m]) =>
|
|
130822
|
-
address
|
|
130823
|
-
|
|
130824
|
-
|
|
130821
|
+
return (Array.isArray(map) ? map.map((m) => [m.name, m]) : Object.entries(map ?? {})).map(([n, m]) => {
|
|
130822
|
+
const address = m.address ?? fallbackAddress;
|
|
130823
|
+
if (typeof address !== "string" || address === "") throw Error(`cannot resolve package address of module ${m.name ?? n}`);
|
|
130824
|
+
return {
|
|
130825
|
+
address,
|
|
130826
|
+
module: normalizedModule(n, m)
|
|
130827
|
+
};
|
|
130828
|
+
});
|
|
130829
|
+
}
|
|
130830
|
+
function isLegacyNormalizedModule(m) {
|
|
130831
|
+
return !!m && typeof m === "object" && !Array.isArray(m) && ("exposedFunctions" in m || "structs" in m);
|
|
130825
130832
|
}
|
|
130826
130833
|
function isLegacyNormalizedModules(parsed) {
|
|
130827
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
130828
|
-
const map = parsed.result ?? parsed;
|
|
130829
|
-
if (!map || typeof map !== "object" || Array.isArray(map)) return false;
|
|
130830
|
-
return Object.values(map).some((m) => m && typeof m === "object" && ("exposedFunctions" in m || "structs" in m));
|
|
130831
|
-
}
|
|
130832
|
-
function legacySuiPackageAddress(file, parsed) {
|
|
130833
|
-
const base = path$1.basename(file, ".json");
|
|
130834
|
-
if (base.startsWith("0x")) return base;
|
|
130835
130834
|
const map = parsed?.result ?? parsed;
|
|
130836
|
-
|
|
130837
|
-
|
|
130838
|
-
if (typeof address === "string" && address.startsWith("0x")) return address;
|
|
130839
|
-
}
|
|
130835
|
+
if (!map || typeof map !== "object") return false;
|
|
130836
|
+
return (Array.isArray(map) ? map : Object.values(map)).some(isLegacyNormalizedModule);
|
|
130840
130837
|
}
|
|
130841
130838
|
function collectLegacySuiAbis(baseDir) {
|
|
130842
130839
|
const result = [];
|
|
@@ -130856,31 +130853,31 @@ function collectLegacySuiAbis(baseDir) {
|
|
|
130856
130853
|
continue;
|
|
130857
130854
|
}
|
|
130858
130855
|
if (!isLegacyNormalizedModules(parsed)) continue;
|
|
130859
|
-
const
|
|
130860
|
-
if (!address) {
|
|
130861
|
-
console.log(chalk.yellow(`Skipping legacy Sui ABI ${fullPath}: cannot resolve package address, re-download it manually`));
|
|
130862
|
-
continue;
|
|
130863
|
-
}
|
|
130864
|
-
const isTestnet = path$1.relative(baseDir, fullPath).split(path$1.sep).includes("testnet");
|
|
130856
|
+
const base = path$1.basename(fullPath, ".json");
|
|
130865
130857
|
result.push({
|
|
130866
130858
|
file: fullPath,
|
|
130867
|
-
|
|
130868
|
-
|
|
130859
|
+
modules: parsed,
|
|
130860
|
+
fallbackAddress: base.startsWith("0x") ? base : void 0
|
|
130869
130861
|
});
|
|
130870
130862
|
}
|
|
130871
130863
|
};
|
|
130872
130864
|
walk(baseDir);
|
|
130873
130865
|
return result;
|
|
130874
130866
|
}
|
|
130875
|
-
|
|
130867
|
+
function convertLegacySuiAbis(baseDir = path$1.resolve("abis", "sui")) {
|
|
130876
130868
|
const legacy = collectLegacySuiAbis(baseDir);
|
|
130877
130869
|
if (legacy.length === 0) return;
|
|
130878
|
-
console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s),
|
|
130879
|
-
|
|
130880
|
-
|
|
130881
|
-
|
|
130882
|
-
|
|
130883
|
-
|
|
130870
|
+
console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), converting to the current format`));
|
|
130871
|
+
for (const { file, modules, fallbackAddress } of legacy) {
|
|
130872
|
+
let abi;
|
|
130873
|
+
try {
|
|
130874
|
+
abi = normalizedModulesToAbi(modules, fallbackAddress);
|
|
130875
|
+
} catch (e) {
|
|
130876
|
+
console.log(chalk.yellow(`Skipping legacy Sui ABI ${file}: ${e?.message ?? e}, re-download it with \`sentio add\``));
|
|
130877
|
+
continue;
|
|
130878
|
+
}
|
|
130879
|
+
import_lib$1.default.writeFileSync(file, JSON.stringify(abi, null, 2));
|
|
130880
|
+
console.log(chalk.green("Converted legacy Sui ABI", file));
|
|
130884
130881
|
}
|
|
130885
130882
|
}
|
|
130886
130883
|
async function getABI(chain, address, name, credentials) {
|
|
@@ -131130,7 +131127,7 @@ async function codegen(genExample) {
|
|
|
131130
131127
|
writeABIFile((await getABI(contract.chain, contract.address, contract.name)).abi, outputPath);
|
|
131131
131128
|
}
|
|
131132
131129
|
const outputBase = path$1.resolve("src", "types");
|
|
131133
|
-
|
|
131130
|
+
convertLegacySuiAbis(path$1.resolve("abis", "sui"));
|
|
131134
131131
|
for (const gen of CHAIN_TYPES) try {
|
|
131135
131132
|
const codegen = await import(`@sentio/sdk/${gen}/codegen`);
|
|
131136
131133
|
try {
|
package/package.json
CHANGED
package/src/abi.ts
CHANGED
|
@@ -137,65 +137,60 @@ function normalizedModule(name: string, m: any): any {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// Convert the JSON-RPC normalized-modules shape (a `{ name: module }` map or an
|
|
140
|
-
// array of modules) into the gRPC ABI array
|
|
141
|
-
|
|
140
|
+
// array of modules, optionally wrapped in `{ result }`) into the gRPC ABI array
|
|
141
|
+
// consumed by the v2 codegen. `fallbackAddress` fills in the package address of
|
|
142
|
+
// modules that don't carry one; modules that do keep their own.
|
|
143
|
+
export function normalizedModulesToAbi(
|
|
144
|
+
modules: any,
|
|
145
|
+
fallbackAddress?: string
|
|
146
|
+
): Array<{ address: string; module: any }> {
|
|
142
147
|
const map = modules?.result ?? modules
|
|
143
148
|
const entries: Array<[string, any]> = Array.isArray(map)
|
|
144
149
|
? map.map((m: any) => [m.name, m])
|
|
145
150
|
: Object.entries(map ?? {})
|
|
146
|
-
return entries.map(([n, m]) =>
|
|
151
|
+
return entries.map(([n, m]) => {
|
|
152
|
+
const address = m.address ?? fallbackAddress
|
|
153
|
+
if (typeof address !== 'string' || address === '') {
|
|
154
|
+
throw Error(`cannot resolve package address of module ${m.name ?? n}`)
|
|
155
|
+
}
|
|
156
|
+
return { address, module: normalizedModule(n, m) }
|
|
157
|
+
})
|
|
147
158
|
}
|
|
148
159
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
function isLegacyNormalizedModule(m: any): boolean {
|
|
161
|
+
return !!m && typeof m === 'object' && !Array.isArray(m) && ('exposedFunctions' in m || 'structs' in m)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// A Sui ABI saved by an older CLI (or by hand from a JSON-RPC response) is the
|
|
165
|
+
// raw `getNormalizedMoveModulesByPackage` result: a `{ moduleName: { structs,
|
|
166
|
+
// exposedFunctions, ... } }` map or an array of such modules (the pre-gRPC
|
|
167
|
+
// codegen read both through Object.values), optionally wrapped in `{ result }`.
|
|
168
|
+
// The v2 codegen (see comment at top of file) instead consumes the gRPC array
|
|
169
|
+
// shape (`[{ address, module }]`) produced by `normalizedModulesToAbi`. Feeding
|
|
170
|
+
// a legacy-shaped file straight to codegen throws (`modules.map is not a
|
|
171
|
+
// function` for the map, `Cannot read properties of undefined` for the array),
|
|
172
|
+
// so `sentio add`/`build`/`gen` fail whenever a stale Sui ABI is already
|
|
173
|
+
// sitting in `abis/sui`. Detect every legacy variant.
|
|
174
|
+
export function isLegacyNormalizedModules(parsed: any): boolean {
|
|
175
|
+
const map = parsed?.result ?? parsed
|
|
176
|
+
if (!map || typeof map !== 'object') {
|
|
163
177
|
return false
|
|
164
178
|
}
|
|
165
|
-
return
|
|
179
|
+
return (Array.isArray(map) ? map : Object.values(map)).some(isLegacyNormalizedModule)
|
|
166
180
|
}
|
|
167
181
|
|
|
168
|
-
// A legacy-shaped Sui ABI file on disk
|
|
169
|
-
//
|
|
182
|
+
// A legacy-shaped Sui ABI file on disk together with its parsed content and the
|
|
183
|
+
// package address recovered from the 0x-prefixed file name (what `sentio add`
|
|
184
|
+
// uses by default), used for modules that don't carry their own address.
|
|
170
185
|
export interface LegacySuiAbi {
|
|
171
186
|
file: string
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Recover the package address of a legacy Sui ABI: prefer the 0x-prefixed file
|
|
177
|
-
// name (what `sentio add` uses by default), otherwise fall back to the `address`
|
|
178
|
-
// carried by the normalized modules (covers files saved under a custom --name).
|
|
179
|
-
function legacySuiPackageAddress(file: string, parsed: any): string | undefined {
|
|
180
|
-
const base = path.basename(file, '.json')
|
|
181
|
-
if (base.startsWith('0x')) {
|
|
182
|
-
return base
|
|
183
|
-
}
|
|
184
|
-
const map = parsed?.result ?? parsed
|
|
185
|
-
for (const module of Object.values(map ?? {})) {
|
|
186
|
-
const address = (module as any)?.address
|
|
187
|
-
if (typeof address === 'string' && address.startsWith('0x')) {
|
|
188
|
-
return address
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return undefined
|
|
187
|
+
modules: any
|
|
188
|
+
fallbackAddress?: string
|
|
192
189
|
}
|
|
193
190
|
|
|
194
|
-
// Recursively collect every legacy-shaped Sui ABI under `baseDir
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
// `redownloadLegacySuiAbis`. Iota still consumes the legacy shape, so this must
|
|
198
|
-
// only ever be pointed at the Sui directory.
|
|
191
|
+
// Recursively collect every legacy-shaped Sui ABI under `baseDir`. Pure/offline;
|
|
192
|
+
// the conversion happens in `convertLegacySuiAbis`. Iota still consumes the
|
|
193
|
+
// legacy shape, so this must only ever be pointed at the Sui directory.
|
|
199
194
|
export function collectLegacySuiAbis(baseDir: string): LegacySuiAbi[] {
|
|
200
195
|
const result: LegacySuiAbi[] = []
|
|
201
196
|
const walk = (dir: string) => {
|
|
@@ -220,43 +215,39 @@ export function collectLegacySuiAbis(baseDir: string): LegacySuiAbi[] {
|
|
|
220
215
|
if (!isLegacyNormalizedModules(parsed)) {
|
|
221
216
|
continue
|
|
222
217
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
console.log(
|
|
226
|
-
chalk.yellow(`Skipping legacy Sui ABI ${fullPath}: cannot resolve package address, re-download it manually`)
|
|
227
|
-
)
|
|
228
|
-
continue
|
|
229
|
-
}
|
|
230
|
-
const isTestnet = path.relative(baseDir, fullPath).split(path.sep).includes('testnet')
|
|
231
|
-
result.push({ file: fullPath, address, chain: isTestnet ? SuiChainId.SUI_TESTNET : SuiChainId.SUI_MAINNET })
|
|
218
|
+
const base = path.basename(fullPath, '.json')
|
|
219
|
+
result.push({ file: fullPath, modules: parsed, fallbackAddress: base.startsWith('0x') ? base : undefined })
|
|
232
220
|
}
|
|
233
221
|
}
|
|
234
222
|
walk(baseDir)
|
|
235
223
|
return result
|
|
236
224
|
}
|
|
237
225
|
|
|
238
|
-
// Sui ABIs
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
export
|
|
226
|
+
// Sui ABIs saved by an older CLI are stored in the legacy JSON-RPC shape, which
|
|
227
|
+
// the current gRPC codegen can't read, so a stale Sui ABI left in `abis/sui`
|
|
228
|
+
// makes `sentio add`/`build`/`gen` fail for the whole project. Rewrite every
|
|
229
|
+
// such file in place through `normalizedModulesToAbi`. The legacy file already
|
|
230
|
+
// holds the full module ABI, so this is a pure local conversion: no network, no
|
|
231
|
+
// dependence on a hard-coded fullnode URL, and it also covers packages saved
|
|
232
|
+
// from networks the CLI can't re-download from.
|
|
233
|
+
export function convertLegacySuiAbis(baseDir = path.resolve('abis', 'sui')): void {
|
|
246
234
|
const legacy = collectLegacySuiAbis(baseDir)
|
|
247
235
|
if (legacy.length === 0) {
|
|
248
236
|
return
|
|
249
237
|
}
|
|
250
|
-
console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s),
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
238
|
+
console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), converting to the current format`))
|
|
239
|
+
for (const { file, modules, fallbackAddress } of legacy) {
|
|
240
|
+
let abi: ReturnType<typeof normalizedModulesToAbi>
|
|
241
|
+
try {
|
|
242
|
+
abi = normalizedModulesToAbi(modules, fallbackAddress)
|
|
243
|
+
} catch (e: any) {
|
|
244
|
+
console.log(
|
|
245
|
+
chalk.yellow(`Skipping legacy Sui ABI ${file}: ${e?.message ?? e}, re-download it with \`sentio add\``)
|
|
246
|
+
)
|
|
247
|
+
continue
|
|
257
248
|
}
|
|
258
|
-
|
|
259
|
-
|
|
249
|
+
fs.writeFileSync(file, JSON.stringify(abi, null, 2))
|
|
250
|
+
console.log(chalk.green('Converted legacy Sui ABI', file))
|
|
260
251
|
}
|
|
261
252
|
}
|
|
262
253
|
|
package/src/commands/build.ts
CHANGED
|
@@ -4,7 +4,7 @@ import fs from 'fs-extra'
|
|
|
4
4
|
import { checkSdkCompatibility, getPackageRoot } from '../utils.js'
|
|
5
5
|
import { Command } from '@commander-js/extra-typings'
|
|
6
6
|
import { CHAIN_TYPES, loadProcessorConfig } from '../config.js'
|
|
7
|
-
import { getABIFilePath, getABI, writeABIFile,
|
|
7
|
+
import { getABIFilePath, getABI, writeABIFile, convertLegacySuiAbis } from '../abi.js'
|
|
8
8
|
import { execStep, execPackageManager } from '../execution.js'
|
|
9
9
|
import { CommandOptionsType } from './types.js'
|
|
10
10
|
|
|
@@ -112,11 +112,11 @@ export async function codegen(genExample: boolean) {
|
|
|
112
112
|
|
|
113
113
|
const outputBase = path.resolve('src', 'types')
|
|
114
114
|
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
115
|
+
// Convert any Sui ABIs saved by an older CLI in the legacy JSON-RPC shape;
|
|
116
|
+
// the current codegen only reads the gRPC array shape, so a stale file left
|
|
117
|
+
// in abis/sui would otherwise make the Sui codegen throw for the whole
|
|
118
118
|
// project.
|
|
119
|
-
|
|
119
|
+
convertLegacySuiAbis(path.resolve('abis', 'sui'))
|
|
120
120
|
|
|
121
121
|
for (const gen of CHAIN_TYPES) {
|
|
122
122
|
try {
|