-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove address and script convertion from ckb-sdk-js (#2801)
* refactor: remove address <--> script convertion of ckb-sdk-js * chore: prettier * Update packages/neuron-wallet/src/services/cells.ts Co-authored-by: WhiteMind <WhiteMind@qq.com> * Update packages/neuron-wallet/src/services/transaction-sender.ts Co-authored-by: WhiteMind <WhiteMind@qq.com> --------- Co-authored-by: WhiteMind <WhiteMind@qq.com>
- Loading branch information
1 parent
2652061
commit 9d585fe
Showing
19 changed files
with
193 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/neuron-wallet/src/block-sync-renderer/sync/tx-address-finder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ges/neuron-wallet/src/database/chain/migrations/1650984779265-UpdateAddressDescription.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Script } from '@ckb-lumos/base' | ||
import { predefined } from '@ckb-lumos/config-manager' | ||
import { encodeToAddress, parseAddress } from '@ckb-lumos/helpers' | ||
|
||
export const scriptToAddress = (script: CKBComponents.Script, isMainnet = true): string => { | ||
const lumosConfig = !isMainnet ? predefined.AGGRON4 : predefined.LINA | ||
return encodeToAddress( | ||
// omit keys other than codeHash, args and hashType | ||
{ | ||
codeHash: script.codeHash, | ||
args: script.args, | ||
hashType: script.hashType, | ||
}, | ||
{ config: lumosConfig } | ||
) | ||
} | ||
|
||
export const addressToScript = (address: string): Script => { | ||
const prefix = address.slice(0, 3) | ||
if (prefix !== 'ckt' && prefix !== 'ckb') { | ||
throw new Error('Invalid address prefix') | ||
} | ||
const lumosConfig = prefix === 'ckt' ? predefined.AGGRON4 : predefined.LINA | ||
return parseAddress(address, { config: lumosConfig }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/neuron-wallet/tests/models/keys/hd-public-key-info.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
9d585fe
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.
Packaging for test is done in 5961427528
9d585fe
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.
Packaging for test is done in 5961429378