Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deprecate config/helpers and fix website address conversion #606

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/wild-dodos-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ckb-lumos/config-manager": minor
"@ckb-lumos/lumos": minor
---

feat: **deprecated** the `helpers` in `config-manager` to avoid confused with `@ckb-lumos/helpers`
4 changes: 4 additions & 0 deletions packages/config-manager/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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";
9 changes: 9 additions & 0 deletions packages/lumos/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ export {
validateConfig,
initializeConfig,
getConfig,
/**
* @deprecated use the {@link nameOfScript} and {@link findConfigByScript} function instead
*/
helpers,
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
} from "@ckb-lumos/config-manager";

export {
nameOfScript,
findConfigByScript,
} from "@ckb-lumos/config-manager/lib/helpers";
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@ckb-lumos/lumos": "canary",
"@ckb-lumos/helpers": "canary",
"@ckb-lumos/molecule": "canary",
"@docusaurus/core": "^3.0.0",
"@docusaurus/preset-classic": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
import { config as lumosConfig, helpers, Script } from "@ckb-lumos/lumos";
import { Err, MultiVersionAddress } from "@site/src/types";
import { config as lumosConfig, Script } from "@ckb-lumos/lumos"
import * as helpers from "@ckb-lumos/helpers"
import { Err, MultiVersionAddress } from "@site/src/types"

export type ParseResult = MultiVersionAddress | Err;
export type ParseResult = MultiVersionAddress | Err

export function parseMultiVersionAddress(
script: Script,
config: lumosConfig.Config
): ParseResult {
export function parseMultiVersionAddress(script: Script, config: lumosConfig.Config): ParseResult {
try {
const name = lumosConfig.helpers.nameOfScript(script, config.SCRIPTS) as
| string
| undefined;
const ckb2021 = helpers.encodeToAddress(script, { config });
const name = lumosConfig.helpers.nameOfScript(script, config.SCRIPTS) as string | undefined
const ckb2021 = helpers.encodeToAddress(script, { config })

if (script.hashType === "data1" || script.hashType === 'data2') {
if (script.hashType === "data1" || script.hashType === "data2") {
return {
name,
script,
ckb2019FullFormat: undefined,
ckb2019ShortFormat: undefined,
ckb2021FullFormat: ckb2021,
};
}
}

const ckb2019Full = helpers.generateAddress(script, {
config: { SCRIPTS: {}, PREFIX: config.PREFIX },
});
const ckb2019Short = helpers.generateAddress(script, { config });
})
const ckb2019Short = helpers.generateAddress(script, { config })

return {
script,
name,
ckb2019FullFormat: ckb2019Full,
ckb2019ShortFormat:
ckb2019Short === ckb2019Full ? undefined : ckb2019Short,
ckb2019ShortFormat: ckb2019Short === ckb2019Full ? undefined : ckb2019Short,
ckb2021FullFormat: helpers.encodeToAddress(script, { config }),
};
}
} catch {
return { error: "Invalid script" };
return { error: "Invalid script" }
}
}
Loading