@ckb-lumos/config-manager
Advanced tools
Comparing version 0.0.0-canary-a49c050-20230723075710 to 0.0.0-canary-ad483d9-20240125131247
export * from "./types"; | ||
export { initializeConfig, getConfig, validateConfig } from "./manager"; | ||
/** | ||
* @deprecated use the {@link nameOfScript} and {@link findConfigByScript} function instead | ||
*/ | ||
export * as helpers from "./helpers"; | ||
export { nameOfScript, findConfigByScript } from "./helpers"; | ||
export { predefined, createConfig } from "./predefined"; | ||
export { generateGenesisScriptConfigs } from "./genesis"; | ||
export { refreshScriptConfigs, createRpcResolver, createLatestTypeIdResolver, } from "./refresh"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -10,5 +10,11 @@ "use strict"; | ||
validateConfig: true, | ||
nameOfScript: true, | ||
findConfigByScript: true, | ||
helpers: true, | ||
predefined: true, | ||
createConfig: true | ||
createConfig: true, | ||
generateGenesisScriptConfigs: true, | ||
refreshScriptConfigs: true, | ||
createRpcResolver: true, | ||
createLatestTypeIdResolver: true | ||
}; | ||
@@ -21,2 +27,26 @@ Object.defineProperty(exports, "createConfig", { | ||
}); | ||
Object.defineProperty(exports, "createLatestTypeIdResolver", { | ||
enumerable: true, | ||
get: function () { | ||
return _refresh.createLatestTypeIdResolver; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createRpcResolver", { | ||
enumerable: true, | ||
get: function () { | ||
return _refresh.createRpcResolver; | ||
} | ||
}); | ||
Object.defineProperty(exports, "findConfigByScript", { | ||
enumerable: true, | ||
get: function () { | ||
return _helpers.findConfigByScript; | ||
} | ||
}); | ||
Object.defineProperty(exports, "generateGenesisScriptConfigs", { | ||
enumerable: true, | ||
get: function () { | ||
return _genesis.generateGenesisScriptConfigs; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getConfig", { | ||
@@ -35,2 +65,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "nameOfScript", { | ||
enumerable: true, | ||
get: function () { | ||
return _helpers.nameOfScript; | ||
} | ||
}); | ||
Object.defineProperty(exports, "predefined", { | ||
@@ -42,2 +78,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "refreshScriptConfigs", { | ||
enumerable: true, | ||
get: function () { | ||
return _refresh.refreshScriptConfigs; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateConfig", { | ||
@@ -65,4 +107,6 @@ enumerable: true, | ||
var _predefined = require("./predefined"); | ||
var _genesis = require("./genesis"); | ||
var _refresh = require("./refresh"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
//# sourceMappingURL=index.js.map |
import { Config } from "./types"; | ||
export declare function assertHashType(debugPath: string, hashType: string): void; | ||
export declare function validateConfig(config: Config): void; | ||
@@ -3,0 +4,0 @@ export declare function getConfig(): Config; |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.assertHashType = assertHashType; | ||
exports.getConfig = getConfig; | ||
@@ -22,3 +23,3 @@ exports.initializeConfig = initializeConfig; | ||
if (hash.length != 66) { | ||
throw new Error(`${debugPath} must be a hex string of 66 bytes long!`); | ||
throw new Error(`${debugPath} must be a hex string of 66 characters long!`); | ||
} | ||
@@ -34,2 +35,7 @@ } | ||
} | ||
function assertHashType(debugPath, hashType) { | ||
if (hashType !== "type" && hashType !== "data" && hashType !== "data1" && hashType !== "data2") { | ||
throw new Error(`${debugPath} must one of type, data, data1, data2!`); | ||
} | ||
} | ||
function assert(condition, debugPath = "variable") { | ||
@@ -44,6 +50,3 @@ if (!condition) throw new Error(`${debugPath} is not valid`); | ||
assertHash(`SCRIPTS.${scriptName}.CODE_HASH`, scriptConfig.CODE_HASH); | ||
const hashType = scriptConfig.HASH_TYPE; | ||
if (hashType !== "type" && hashType !== "data" && hashType !== "data1") { | ||
throw new Error(`SCRIPTS.${scriptName}.HASH_TYPE must be type, data or data1!`); | ||
} | ||
assertHashType(`SCRIPTS.${scriptName}.HASH_TYPE`, scriptConfig.HASH_TYPE); | ||
assertHash(`SCRIPTS.${scriptName}.TX_HASH`, scriptConfig.TX_HASH); | ||
@@ -50,0 +53,0 @@ assertInteger(`SCRIPTS.${scriptName}.INDEX`, scriptConfig.INDEX); |
@@ -61,3 +61,3 @@ "use strict"; | ||
HASH_TYPE: "type", | ||
TX_HASH: "0xdfdb40f5d229536915f2d5403c66047e162e25dedd70a79ef5164356e1facdc8", | ||
TX_HASH: "0xc76edf469816aa22f416503c38d0b533d2a018e253e379f134c3985b3472c842", | ||
INDEX: "0x0", | ||
@@ -112,3 +112,3 @@ DEP_TYPE: "code" | ||
HASH_TYPE: "type", | ||
TX_HASH: "0x27b62d8be8ed80b9f56ee0fe41355becdb6f6a40aeba82d3900434f43b1c8b60", | ||
TX_HASH: "0x3d4296df1bd2cc2bd3f483f61ab7ebeac462a2f336f2b944168fe6ba5d81c014", | ||
INDEX: "0x0", | ||
@@ -115,0 +115,0 @@ DEP_TYPE: "code" |
@@ -0,5 +1,6 @@ | ||
import { HashType } from "@ckb-lumos/base"; | ||
/** Deployed script on chain */ | ||
export interface ScriptConfig { | ||
CODE_HASH: string; | ||
HASH_TYPE: "type" | "data" | "data1"; | ||
HASH_TYPE: HashType; | ||
TX_HASH: string; | ||
@@ -6,0 +7,0 @@ INDEX: string; |
{ | ||
"name": "@ckb-lumos/config-manager", | ||
"version": "0.0.0-canary-a49c050-20230723075710", | ||
"version": "0.0.0-canary-ad483d9-20240125131247", | ||
"description": "Config manager for lumos", | ||
@@ -28,5 +28,6 @@ "author": "Xuejie Xiao <xxuejie@gmail.com>", | ||
"dependencies": { | ||
"@ckb-lumos/base": "0.0.0-canary-a49c050-20230723075710", | ||
"@ckb-lumos/bi": "0.0.0-canary-a49c050-20230723075710", | ||
"@ckb-lumos/codec": "0.0.0-canary-a49c050-20230723075710", | ||
"@ckb-lumos/base": "0.0.0-canary-ad483d9-20240125131247", | ||
"@ckb-lumos/bi": "0.0.0-canary-ad483d9-20240125131247", | ||
"@ckb-lumos/codec": "0.0.0-canary-ad483d9-20240125131247", | ||
"@ckb-lumos/rpc": "0.0.0-canary-ad483d9-20240125131247", | ||
"@types/deep-freeze-strict": "^1.1.0", | ||
@@ -38,6 +39,15 @@ "deep-freeze-strict": "^1.1.1" | ||
}, | ||
"ava": { | ||
"extensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
] | ||
}, | ||
"scripts": { | ||
"fmt": "prettier --write \"{src,tests}/**/*.ts\" package.json", | ||
"lint": "eslint -c ../../.eslintrc.js \"{src,tests}/**/*.ts\"", | ||
"test": "ava --timeout=2m", | ||
"test": "ava **/*.test.{js,ts} --timeout=2m", | ||
"build": "pnpm run build:types && pnpm run build:js", | ||
@@ -44,0 +54,0 @@ "build:types": "tsc --declaration --emitDeclarationOnly", |
@@ -6,11 +6,28 @@ # @ckb-lumos/config-manager | ||
```ts | ||
import { initializeConfig, predefined } from '@ckb-lumos/config'; | ||
import { generateAddress } from '@ckb-lumos/helper' | ||
import { initializeConfig, predefined } from "@ckb-lumos/config-manager" | ||
// or import from the entry package | ||
import { initializeConfig, predefined } from "@ckb-lumos/lumos/config" | ||
import { encodeToAddress } from '@ckb-lumos/helper' | ||
initializeConfig(predefined.AGGRON); | ||
generateAddress({...}) // ckt1... | ||
encodeToAddress({...}) // ckt1... | ||
initializeConfig(predefined.LINA); | ||
generateAddress({...}) // ckb1... | ||
encodeToAddress({...}) // ckb1... | ||
``` | ||
## Refreshing Config | ||
```ts | ||
import { refreshScriptConfigs } from "@ckb-lumos/config-manager" | ||
// or import from the entry package | ||
import { refreshScriptConfigs } from "@ckb-lumos/lumos/config" | ||
import { RPC } from "@ckb-lumos/rpc"; | ||
const rpc = new RPC("http://localhost:8114"); | ||
const refreshed = await refreshScriptConfigs(predefined.AGGRON4.SCRIPTS, { | ||
resolve: createRpcResolver(rpc), | ||
}); | ||
``` |
export * from "./types"; | ||
export { initializeConfig, getConfig, validateConfig } from "./manager"; | ||
/** | ||
* @deprecated use the {@link nameOfScript} and {@link findConfigByScript} function instead | ||
*/ | ||
export * as helpers from "./helpers"; | ||
export { nameOfScript, findConfigByScript } from "./helpers"; | ||
export { predefined, createConfig } from "./predefined"; | ||
export { generateGenesisScriptConfigs } from "./genesis"; | ||
export { | ||
refreshScriptConfigs, | ||
createRpcResolver, | ||
createLatestTypeIdResolver, | ||
} from "./refresh"; |
@@ -15,3 +15,3 @@ import deepFreeze from "deep-freeze-strict"; | ||
if (hash.length != 66) { | ||
throw new Error(`${debugPath} must be a hex string of 66 bytes long!`); | ||
throw new Error(`${debugPath} must be a hex string of 66 characters long!`); | ||
} | ||
@@ -29,2 +29,13 @@ } | ||
export function assertHashType(debugPath: string, hashType: string): void { | ||
if ( | ||
hashType !== "type" && | ||
hashType !== "data" && | ||
hashType !== "data1" && | ||
hashType !== "data2" | ||
) { | ||
throw new Error(`${debugPath} must one of type, data, data1, data2!`); | ||
} | ||
} | ||
function assert(condition: unknown, debugPath = "variable"): asserts condition { | ||
@@ -46,8 +57,3 @@ if (!condition) throw new Error(`${debugPath} is not valid`); | ||
assertHash(`SCRIPTS.${scriptName}.CODE_HASH`, scriptConfig.CODE_HASH); | ||
const hashType = scriptConfig.HASH_TYPE; | ||
if (hashType !== "type" && hashType !== "data" && hashType !== "data1") { | ||
throw new Error( | ||
`SCRIPTS.${scriptName}.HASH_TYPE must be type, data or data1!` | ||
); | ||
} | ||
assertHashType(`SCRIPTS.${scriptName}.HASH_TYPE`, scriptConfig.HASH_TYPE); | ||
assertHash(`SCRIPTS.${scriptName}.TX_HASH`, scriptConfig.TX_HASH); | ||
@@ -54,0 +60,0 @@ assertInteger(`SCRIPTS.${scriptName}.INDEX`, scriptConfig.INDEX); |
@@ -73,3 +73,3 @@ import deepFreeze from "deep-freeze-strict"; | ||
TX_HASH: | ||
"0xdfdb40f5d229536915f2d5403c66047e162e25dedd70a79ef5164356e1facdc8", | ||
"0xc76edf469816aa22f416503c38d0b533d2a018e253e379f134c3985b3472c842", | ||
INDEX: "0x0", | ||
@@ -137,3 +137,3 @@ DEP_TYPE: "code", | ||
TX_HASH: | ||
"0x27b62d8be8ed80b9f56ee0fe41355becdb6f6a40aeba82d3900434f43b1c8b60", | ||
"0x3d4296df1bd2cc2bd3f483f61ab7ebeac462a2f336f2b944168fe6ba5d81c014", | ||
INDEX: "0x0", | ||
@@ -140,0 +140,0 @@ DEP_TYPE: "code", |
@@ -0,5 +1,7 @@ | ||
import { HashType } from "@ckb-lumos/base"; | ||
/** Deployed script on chain */ | ||
export interface ScriptConfig { | ||
CODE_HASH: string; | ||
HASH_TYPE: "type" | "data" | "data1"; | ||
HASH_TYPE: HashType; | ||
TX_HASH: string; | ||
@@ -6,0 +8,0 @@ INDEX: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
93426
38
1371
33
6
+ Added@ckb-lumos/base@0.0.0-canary-ad483d9-20240125131247(transitive)
+ Added@ckb-lumos/bi@0.0.0-canary-ad483d9-20240125131247(transitive)
+ Added@ckb-lumos/codec@0.0.0-canary-ad483d9-20240125131247(transitive)
+ Added@ckb-lumos/rpc@0.0.0-canary-ad483d9-20240125131247(transitive)
+ Added@ckb-lumos/toolkit@0.0.0-canary-ad483d9-20240125131247(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
- Removed@ckb-lumos/base@0.0.0-canary-a49c050-20230723075710(transitive)
- Removed@ckb-lumos/bi@0.0.0-canary-a49c050-20230723075710(transitive)
- Removed@ckb-lumos/codec@0.0.0-canary-a49c050-20230723075710(transitive)
- Removed@ckb-lumos/toolkit@0.0.0-canary-a49c050-20230723075710(transitive)