-
Notifications
You must be signed in to change notification settings - Fork 92
Refactor: remove ckb-sdk-utils and repalce with lumos #2734
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
Changes from all commits
63aac4a
69bef32
8e89627
892d274
7ffd05c
dd6a4de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,6 @@ import fs from 'fs' | |||||||||||||||||||||
| import path from 'path' | ||||||||||||||||||||||
| import { dialog, BrowserWindow } from 'electron' | ||||||||||||||||||||||
| import { t } from 'i18next' | ||||||||||||||||||||||
| import { addressToScript, scriptToAddress, scriptToHash } from '@nervosnetwork/ckb-sdk-utils' | ||||||||||||||||||||||
| import { ResponseCode } from '../utils/const' | ||||||||||||||||||||||
| import MultisigConfig from '../database/chain/entities/multisig-config' | ||||||||||||||||||||||
| import MultisigConfigModel from '../models/multisig-config' | ||||||||||||||||||||||
|
|
@@ -12,6 +11,7 @@ import OfflineSignService from '../services/offline-sign' | |||||||||||||||||||||
| import Multisig from '../models/multisig' | ||||||||||||||||||||||
| import SystemScriptInfo from '../models/system-script-info' | ||||||||||||||||||||||
| import NetworksService from '../services/networks' | ||||||||||||||||||||||
| import { config as lumosConig, helpers, utils, config } from '@ckb-lumos/lumos' | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setting
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't get it, BTW,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. neuron/packages/neuron-wallet/src/controllers/multisig.ts Lines 110 to 117 in b4f7de2
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| interface MultisigConfigOutput { | ||||||||||||||||||||||
| multisig_configs: Record< | ||||||||||||||||||||||
|
|
@@ -122,7 +122,13 @@ export default class MultisigController { | |||||||||||||||||||||
| r: +config.require_first_n, | ||||||||||||||||||||||
| m: +config.threshold, | ||||||||||||||||||||||
| n: config.sighash_addresses.length, | ||||||||||||||||||||||
| blake160s: config.sighash_addresses.map(v => addressToScript(v).args), | ||||||||||||||||||||||
| blake160s: config.sighash_addresses.map(v => { | ||||||||||||||||||||||
| const isMainnet = v.startsWith('ckb') | ||||||||||||||||||||||
| const lumosOptions = isMainnet | ||||||||||||||||||||||
| ? { config: lumosConig.predefined.LINA } | ||||||||||||||||||||||
| : { config: lumosConig.predefined.AGGRON4 } | ||||||||||||||||||||||
| return helpers.addressToScript(v, lumosOptions).args | ||||||||||||||||||||||
| }), | ||||||||||||||||||||||
| walletId, | ||||||||||||||||||||||
| alias: config.alias, | ||||||||||||||||||||||
| })) | ||||||||||||||||||||||
|
|
@@ -170,11 +176,13 @@ export default class MultisigController { | |||||||||||||||||||||
| return | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| const isMainnet = NetworksService.getInstance().isMainnet() | ||||||||||||||||||||||
| const lumosOptions = isMainnet ? { config: lumosConig.predefined.LINA } : { config: lumosConig.predefined.AGGRON4 } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const output: MultisigConfigOutput = { multisig_configs: {} } | ||||||||||||||||||||||
| configs.forEach(v => { | ||||||||||||||||||||||
| output.multisig_configs[Multisig.hash(v.blake160s, v.r, v.m, v.n)] = { | ||||||||||||||||||||||
| sighash_addresses: v.blake160s.map(args => | ||||||||||||||||||||||
| scriptToAddress(SystemScriptInfo.generateSecpScript(args), isMainnet) | ||||||||||||||||||||||
| helpers.encodeToAddress(SystemScriptInfo.generateSecpScript(args), lumosOptions) | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| require_first_n: v.r, | ||||||||||||||||||||||
| threshold: v.m, | ||||||||||||||||||||||
|
|
@@ -214,7 +222,9 @@ export default class MultisigController { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| const tx = result.json | ||||||||||||||||||||||
| const lockHash = scriptToHash(addressToScript(fullPayload)) | ||||||||||||||||||||||
| const isMainnet = fullPayload.startsWith('ckb') | ||||||||||||||||||||||
| const lumosOptions = isMainnet ? { config: config.predefined.LINA } : { config: config.predefined.AGGRON4 } | ||||||||||||||||||||||
| const lockHash = utils.computeScriptHash(helpers.addressToScript(fullPayload, lumosOptions)) | ||||||||||||||||||||||
| if (tx.transaction.inputs.every(v => v.lockHash !== lockHash)) { | ||||||||||||||||||||||
| dialog.showErrorBox(t('common.error'), t('messages.multisig-lock-hash-mismatch')) | ||||||||||||||||||||||
| return { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a migration that has already been released should not be refactored, which may pose some risks |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,22 @@ | ||
| import { MigrationInterface, QueryRunner } from "typeorm" | ||
| import { addressToScript } from "@nervosnetwork/ckb-sdk-utils" | ||
| import MultisigConfig from "../entities/multisig-config" | ||
| import { MigrationInterface, QueryRunner } from 'typeorm' | ||
| import MultisigConfig from '../entities/multisig-config' | ||
| import { helpers } from '@ckb-lumos/lumos' | ||
|
|
||
| export class RemoveAddressesMultisigConfig1651820157100 implements MigrationInterface { | ||
| name = 'RemoveAddressesMultisigConfig1651820157100' | ||
| name = 'RemoveAddressesMultisigConfig1651820157100' | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.renameColumn('multisig_config', 'addresses', 'blake160s') | ||
| await queryRunner.dropColumn('multisig_config', 'fullpayload') | ||
| const configList = await queryRunner.manager.find(MultisigConfig) | ||
| const updated = configList.map(v => { | ||
| v.blake160s = v.blake160s.map(v => addressToScript(v).args) | ||
| return v | ||
| }) | ||
| await queryRunner.manager.save(updated) | ||
| } | ||
|
|
||
| public async down(): Promise<void> { | ||
| // do nothing | ||
| } | ||
| public async up(queryRunner: QueryRunner): Promise<any> { | ||
| await queryRunner.renameColumn('multisig_config', 'addresses', 'blake160s') | ||
| await queryRunner.dropColumn('multisig_config', 'fullpayload') | ||
| const configList = await queryRunner.manager.find(MultisigConfig) | ||
| const updated = configList.map(v => { | ||
| v.blake160s = v.blake160s.map(v => helpers.addressToScript(v).args) | ||
| return v | ||
| }) | ||
| await queryRunner.manager.save(updated) | ||
| } | ||
|
|
||
| public async down(): Promise<void> { | ||
| // do nothing | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are so many
isMainnet ? LINA : AGGRON4in the PR, such a refactoring would only increase the complexity, maybe it is better to extract a helper to cover the caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, we can init the config after ckb node starts and change the config when the network changes.