@sentio/cli 4.2.1 → 4.2.2-rc.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 +61 -0
- package/package.json +1 -1
- package/src/abi.ts +114 -0
- package/src/commands/build.ts +7 -1
package/dist/index.js
CHANGED
|
@@ -130888,6 +130888,66 @@ function normalizedModulesToAbi(modules) {
|
|
|
130888
130888
|
module: normalizedModule(n, m)
|
|
130889
130889
|
}));
|
|
130890
130890
|
}
|
|
130891
|
+
function isLegacyNormalizedModules(parsed) {
|
|
130892
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
130893
|
+
const map = parsed.result ?? parsed;
|
|
130894
|
+
if (!map || typeof map !== "object" || Array.isArray(map)) return false;
|
|
130895
|
+
return Object.values(map).some((m) => m && typeof m === "object" && ("exposedFunctions" in m || "structs" in m));
|
|
130896
|
+
}
|
|
130897
|
+
function legacySuiPackageAddress(file, parsed) {
|
|
130898
|
+
const base = path$1.basename(file, ".json");
|
|
130899
|
+
if (base.startsWith("0x")) return base;
|
|
130900
|
+
const map = parsed?.result ?? parsed;
|
|
130901
|
+
for (const module of Object.values(map ?? {})) {
|
|
130902
|
+
const address = module?.address;
|
|
130903
|
+
if (typeof address === "string" && address.startsWith("0x")) return address;
|
|
130904
|
+
}
|
|
130905
|
+
}
|
|
130906
|
+
function collectLegacySuiAbis(baseDir) {
|
|
130907
|
+
const result = [];
|
|
130908
|
+
const walk = (dir) => {
|
|
130909
|
+
if (!import_lib$1.default.existsSync(dir)) return;
|
|
130910
|
+
for (const entry of import_lib$1.default.readdirSync(dir, { withFileTypes: true })) {
|
|
130911
|
+
const fullPath = path$1.join(dir, entry.name);
|
|
130912
|
+
if (entry.isDirectory()) {
|
|
130913
|
+
walk(fullPath);
|
|
130914
|
+
continue;
|
|
130915
|
+
}
|
|
130916
|
+
if (!entry.name.endsWith(".json")) continue;
|
|
130917
|
+
let parsed;
|
|
130918
|
+
try {
|
|
130919
|
+
parsed = JSON.parse(import_lib$1.default.readFileSync(fullPath, "utf8"));
|
|
130920
|
+
} catch {
|
|
130921
|
+
continue;
|
|
130922
|
+
}
|
|
130923
|
+
if (!isLegacyNormalizedModules(parsed)) continue;
|
|
130924
|
+
const address = legacySuiPackageAddress(fullPath, parsed);
|
|
130925
|
+
if (!address) {
|
|
130926
|
+
console.log(chalk.yellow(`Skipping legacy Sui ABI ${fullPath}: cannot resolve package address, re-download it manually`));
|
|
130927
|
+
continue;
|
|
130928
|
+
}
|
|
130929
|
+
const isTestnet = path$1.relative(baseDir, fullPath).split(path$1.sep).includes("testnet");
|
|
130930
|
+
result.push({
|
|
130931
|
+
file: fullPath,
|
|
130932
|
+
address,
|
|
130933
|
+
chain: isTestnet ? import_dist.SuiChainId.SUI_TESTNET : import_dist.SuiChainId.SUI_MAINNET
|
|
130934
|
+
});
|
|
130935
|
+
}
|
|
130936
|
+
};
|
|
130937
|
+
walk(baseDir);
|
|
130938
|
+
return result;
|
|
130939
|
+
}
|
|
130940
|
+
async function redownloadLegacySuiAbis(baseDir = path$1.resolve("abis", "sui")) {
|
|
130941
|
+
const legacy = collectLegacySuiAbis(baseDir);
|
|
130942
|
+
if (legacy.length === 0) return;
|
|
130943
|
+
console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), re-downloading in the current format`));
|
|
130944
|
+
let previousChain = "";
|
|
130945
|
+
for (const { file, chain, address } of legacy) {
|
|
130946
|
+
if (chain === previousChain) await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
130947
|
+
else previousChain = chain;
|
|
130948
|
+
writeABIFile((await getABI(chain, address, path$1.basename(file, ".json"))).abi, file);
|
|
130949
|
+
}
|
|
130950
|
+
}
|
|
130891
130951
|
async function getABI(chain, address, name, credentials) {
|
|
130892
130952
|
const baseErrMsg = chalk.red(`Failed to automatic download contract ${address} from ${chain}, please manually download abi and put it into abis/eth directory`);
|
|
130893
130953
|
try {
|
|
@@ -131135,6 +131195,7 @@ async function codegen(genExample) {
|
|
|
131135
131195
|
writeABIFile((await getABI(contract.chain, contract.address, contract.name)).abi, outputPath);
|
|
131136
131196
|
}
|
|
131137
131197
|
const outputBase = path$1.resolve("src", "types");
|
|
131198
|
+
await redownloadLegacySuiAbis(path$1.resolve("abis", "sui"));
|
|
131138
131199
|
for (const gen of CHAIN_TYPES) try {
|
|
131139
131200
|
const codegen = await import(`@sentio/sdk/${gen}/codegen`);
|
|
131140
131201
|
try {
|
package/package.json
CHANGED
package/src/abi.ts
CHANGED
|
@@ -146,6 +146,120 @@ export function normalizedModulesToAbi(modules: any): Array<{ address: string; m
|
|
|
146
146
|
return entries.map(([n, m]) => ({ address: m.address, module: normalizedModule(n, m) }))
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
// A Sui ABI downloaded by an older CLI is the raw JSON-RPC
|
|
150
|
+
// `getNormalizedMoveModulesByPackage` result: a `{ moduleName: { structs,
|
|
151
|
+
// exposedFunctions, ... } }` map. The v2 codegen (see comment at top of file)
|
|
152
|
+
// instead consumes the gRPC array shape produced by `normalizedModulesToAbi`.
|
|
153
|
+
// Feeding a legacy-shaped file straight to codegen throws
|
|
154
|
+
// (`modules.map is not a function`), so `sentio add`/`build`/`gen` fail whenever
|
|
155
|
+
// a stale Sui ABI is already sitting in `abis/sui`. Detect that legacy shape.
|
|
156
|
+
function isLegacyNormalizedModules(parsed: any): boolean {
|
|
157
|
+
// The gRPC shape is an array; the legacy JSON-RPC shape is a plain object map.
|
|
158
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
159
|
+
return false
|
|
160
|
+
}
|
|
161
|
+
const map = parsed.result ?? parsed
|
|
162
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) {
|
|
163
|
+
return false
|
|
164
|
+
}
|
|
165
|
+
return Object.values(map).some((m: any) => m && typeof m === 'object' && ('exposedFunctions' in m || 'structs' in m))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// A legacy-shaped Sui ABI file on disk, together with the package address and
|
|
169
|
+
// network recovered from its name/content so it can be re-downloaded.
|
|
170
|
+
export interface LegacySuiAbi {
|
|
171
|
+
file: string
|
|
172
|
+
address: string
|
|
173
|
+
chain: SuiChainId.SUI_MAINNET | SuiChainId.SUI_TESTNET
|
|
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
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Recursively collect every legacy-shaped Sui ABI under `baseDir`, resolving the
|
|
195
|
+
// package address and network (testnet ABIs live under `<baseDir>/testnet`, see
|
|
196
|
+
// getABIFilePath) for each. Pure/offline — the download happens in
|
|
197
|
+
// `redownloadLegacySuiAbis`. Iota still consumes the legacy shape, so this must
|
|
198
|
+
// only ever be pointed at the Sui directory.
|
|
199
|
+
export function collectLegacySuiAbis(baseDir: string): LegacySuiAbi[] {
|
|
200
|
+
const result: LegacySuiAbi[] = []
|
|
201
|
+
const walk = (dir: string) => {
|
|
202
|
+
if (!fs.existsSync(dir)) {
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
206
|
+
const fullPath = path.join(dir, entry.name)
|
|
207
|
+
if (entry.isDirectory()) {
|
|
208
|
+
walk(fullPath)
|
|
209
|
+
continue
|
|
210
|
+
}
|
|
211
|
+
if (!entry.name.endsWith('.json')) {
|
|
212
|
+
continue
|
|
213
|
+
}
|
|
214
|
+
let parsed: any
|
|
215
|
+
try {
|
|
216
|
+
parsed = JSON.parse(fs.readFileSync(fullPath, 'utf8'))
|
|
217
|
+
} catch {
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
if (!isLegacyNormalizedModules(parsed)) {
|
|
221
|
+
continue
|
|
222
|
+
}
|
|
223
|
+
const address = legacySuiPackageAddress(fullPath, parsed)
|
|
224
|
+
if (!address) {
|
|
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 })
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
walk(baseDir)
|
|
235
|
+
return result
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Sui ABIs downloaded by an older CLI are stored in the legacy JSON-RPC map
|
|
239
|
+
// shape, which the current gRPC codegen can't read (`modules.map is not a
|
|
240
|
+
// function`), so a stale Sui ABI left in `abis/sui` makes `sentio add`/`build`/
|
|
241
|
+
// `gen` fail for the whole project. Collect every such file, then re-download it
|
|
242
|
+
// through getABI so it lands in the current shape with fresh on-chain data.
|
|
243
|
+
// Fetched sequentially with a delay between same-network requests to stay under
|
|
244
|
+
// Sui public-RPC rate limits, matching the "download missing ABI" loop.
|
|
245
|
+
export async function redownloadLegacySuiAbis(baseDir = path.resolve('abis', 'sui')): Promise<void> {
|
|
246
|
+
const legacy = collectLegacySuiAbis(baseDir)
|
|
247
|
+
if (legacy.length === 0) {
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), re-downloading in the current format`))
|
|
251
|
+
let previousChain = ''
|
|
252
|
+
for (const { file, chain, address } of legacy) {
|
|
253
|
+
if (chain === previousChain) {
|
|
254
|
+
await new Promise((resolve) => setTimeout(resolve, 5000))
|
|
255
|
+
} else {
|
|
256
|
+
previousChain = chain
|
|
257
|
+
}
|
|
258
|
+
const res = await getABI(chain, address, path.basename(file, '.json'))
|
|
259
|
+
writeABIFile(res.abi, file)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
149
263
|
export async function getABI(
|
|
150
264
|
chain: ChainId,
|
|
151
265
|
address: string,
|
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 } from '../abi.js'
|
|
7
|
+
import { getABIFilePath, getABI, writeABIFile, redownloadLegacySuiAbis } from '../abi.js'
|
|
8
8
|
import { execStep, execPackageManager } from '../execution.js'
|
|
9
9
|
import { CommandOptionsType } from './types.js'
|
|
10
10
|
|
|
@@ -112,6 +112,12 @@ export async function codegen(genExample: boolean) {
|
|
|
112
112
|
|
|
113
113
|
const outputBase = path.resolve('src', 'types')
|
|
114
114
|
|
|
115
|
+
// Re-download any Sui ABIs saved by an older CLI in the legacy JSON-RPC map
|
|
116
|
+
// shape; the current codegen only reads the gRPC array shape, so a stale file
|
|
117
|
+
// left in abis/sui would otherwise make the Sui codegen throw for the whole
|
|
118
|
+
// project.
|
|
119
|
+
await redownloadLegacySuiAbis(path.resolve('abis', 'sui'))
|
|
120
|
+
|
|
115
121
|
for (const gen of CHAIN_TYPES) {
|
|
116
122
|
try {
|
|
117
123
|
const codegen = await import(`@sentio/sdk/${gen}/codegen`)
|