forked from ckb-devrel/offckb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple templates for init cmd (ckb-devrel#22)
* feat: support multiple templates for init cmd * chore: fmt * fix: ts-config * fix: rm package-lock * fix: update yarn.lock * chore: ignore .vscode * refactor: init cmd with common files and different templates * fix: genKey code hash * refactor: rm the update-config-json.ts on the template * fix: templates typo in package.json * docs: update development and readme
- Loading branch information
Showing
30 changed files
with
3,289 additions
and
388 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ ckb/devnet/data/ | |
.DS_Store | ||
data/ | ||
dist/ | ||
.vscode |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name = "ckb_dev" | ||
name = "offckb" | ||
|
||
[genesis] | ||
version = 0 | ||
|
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,26 @@ | ||
## Development | ||
|
||
### Update built-in scripts | ||
|
||
update submodule inside `ckb` and then run | ||
```sh | ||
make all | ||
``` | ||
|
||
### Update chain config | ||
|
||
edit the things in `ckb/devnet` | ||
|
||
whenever the devnet genesis block's tx hashes changed, you need to update the devnet lumos config file, which is `templates/config.json`. | ||
|
||
first start the node: | ||
|
||
```sh | ||
yarn start node | ||
``` | ||
|
||
second, generate lumos config file: | ||
|
||
```sh | ||
NODE_ENV=development yarn start build-lumos-config | ||
``` |
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,21 @@ | ||
import select from '@inquirer/select'; | ||
|
||
export async function selectTemplate() { | ||
const answer = await select({ | ||
message: 'Select a dapp template', | ||
choices: [ | ||
{ | ||
name: 'Transfer CKB', | ||
value: 'transfer', | ||
description: 'a simple dapp to check CKB balance and transfer CKB from address to address', | ||
}, | ||
{ | ||
name: 'Issue Coin With XUDT scripts', | ||
value: 'xudt', | ||
description: 'a simple dapp to issue your own token with XUDT scripts', | ||
}, | ||
], | ||
}); | ||
|
||
return answer; | ||
} |
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 |
---|---|---|
@@ -1,79 +1,89 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { dappTemplatePath } from '../cfg/const'; | ||
import { RPC } from '@ckb-lumos/lumos'; | ||
|
||
const genesisTxHash = '0x920bb4250dc6216c08ee0713f86b3fcb01bf444027b08b7d92db0ed1c0fb9214'; | ||
const depGroupTxHash = '0x37f2b7799b199491f4732c572c086afdace0bf92992faf0b90bae44cdd119f9e'; | ||
|
||
export const devnetConfig = { | ||
PREFIX: 'ckt', | ||
SCRIPTS: { | ||
SECP256K1_BLAKE160: { | ||
CODE_HASH: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', | ||
HASH_TYPE: 'type', | ||
TX_HASH: depGroupTxHash, | ||
INDEX: '0x0', | ||
DEP_TYPE: 'depGroup', | ||
SHORT_ID: 1, | ||
}, | ||
SECP256K1_BLAKE160_MULTISIG: { | ||
CODE_HASH: '0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8', | ||
HASH_TYPE: 'type', | ||
TX_HASH: depGroupTxHash, | ||
INDEX: '0x1', | ||
DEP_TYPE: 'depGroup', | ||
}, | ||
DAO: { | ||
CODE_HASH: '0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e', | ||
HASH_TYPE: 'type', | ||
TX_HASH: genesisTxHash, | ||
INDEX: '0x2', | ||
DEP_TYPE: 'code', | ||
SHORT_ID: 2, | ||
}, | ||
SUDT: { | ||
CODE_HASH: '0x6283a479a3cf5d4276cd93594de9f1827ab9b55c7b05b3d28e4c2e0a696cfefd', | ||
HASH_TYPE: 'type', | ||
TX_HASH: genesisTxHash, | ||
INDEX: '0x5', | ||
DEP_TYPE: 'code', | ||
}, | ||
XUDT: { | ||
CODE_HASH: '0x1a1e4fef34f5982906f745b048fe7b1089647e82346074e0f32c2ece26cf6b1e', | ||
HASH_TYPE: 'type', | ||
TX_HASH: genesisTxHash, | ||
INDEX: '0x6', | ||
DEP_TYPE: 'code', | ||
export function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock: string, secondTxHashInGenesisBlock: string) { | ||
const devnetConfig = { | ||
PREFIX: 'ckt', | ||
SCRIPTS: { | ||
SECP256K1_BLAKE160: { | ||
CODE_HASH: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8', | ||
HASH_TYPE: 'type', | ||
TX_HASH: secondTxHashInGenesisBlock, | ||
INDEX: '0x0', | ||
DEP_TYPE: 'depGroup', | ||
SHORT_ID: 1, | ||
}, | ||
SECP256K1_BLAKE160_MULTISIG: { | ||
CODE_HASH: '0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8', | ||
HASH_TYPE: 'type', | ||
TX_HASH: secondTxHashInGenesisBlock, | ||
INDEX: '0x1', | ||
DEP_TYPE: 'depGroup', | ||
}, | ||
DAO: { | ||
CODE_HASH: '0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e', | ||
HASH_TYPE: 'type', | ||
TX_HASH: cellBaseTxHashInGenesisBlock, | ||
INDEX: '0x2', | ||
DEP_TYPE: 'code', | ||
SHORT_ID: 2, | ||
}, | ||
SUDT: { | ||
CODE_HASH: '0x6283a479a3cf5d4276cd93594de9f1827ab9b55c7b05b3d28e4c2e0a696cfefd', | ||
HASH_TYPE: 'type', | ||
TX_HASH: cellBaseTxHashInGenesisBlock, | ||
INDEX: '0x5', | ||
DEP_TYPE: 'code', | ||
}, | ||
XUDT: { | ||
CODE_HASH: '0x1a1e4fef34f5982906f745b048fe7b1089647e82346074e0f32c2ece26cf6b1e', | ||
HASH_TYPE: 'type', | ||
TX_HASH: cellBaseTxHashInGenesisBlock, | ||
INDEX: '0x6', | ||
DEP_TYPE: 'code', | ||
}, | ||
OMNILOCK: { | ||
CODE_HASH: '0x9c6933d977360f115a3e9cd5a2e0e475853681b80d775d93ad0f8969da343e56', | ||
HASH_TYPE: 'type', | ||
TX_HASH: cellBaseTxHashInGenesisBlock, | ||
INDEX: '0x7', | ||
DEP_TYPE: 'code', | ||
}, | ||
ANYONE_CAN_PAY: { | ||
CODE_HASH: '0xe09352af0066f3162287763ce4ddba9af6bfaeab198dc7ab37f8c71c9e68bb5b', | ||
HASH_TYPE: 'type', | ||
TX_HASH: cellBaseTxHashInGenesisBlock, | ||
INDEX: '0x8', | ||
DEP_TYPE: 'code', | ||
}, | ||
ALWAYS_SUCCESS: { | ||
CODE_HASH: '0xbb4469004225b39e983929db71fe2253cba1d49a76223e9e1d212cdca1f79f28', | ||
HASH_TYPE: 'type', | ||
TX_HASH: cellBaseTxHashInGenesisBlock, | ||
INDEX: '0x9', | ||
DEP_TYPE: 'code', | ||
}, | ||
}, | ||
OMNILOCK: { | ||
CODE_HASH: '0x9c6933d977360f115a3e9cd5a2e0e475853681b80d775d93ad0f8969da343e56', | ||
HASH_TYPE: 'type', | ||
TX_HASH: genesisTxHash, | ||
INDEX: '0x7', | ||
DEP_TYPE: 'code', | ||
}, | ||
ANYONE_CAN_PAY: { | ||
CODE_HASH: '0xe09352af0066f3162287763ce4ddba9af6bfaeab198dc7ab37f8c71c9e68bb5b', | ||
HASH_TYPE: 'type', | ||
TX_HASH: genesisTxHash, | ||
INDEX: '0x8', | ||
DEP_TYPE: 'code', | ||
}, | ||
ALWAYS_SUCCESS: { | ||
CODE_HASH: '0xbb4469004225b39e983929db71fe2253cba1d49a76223e9e1d212cdca1f79f28', | ||
HASH_TYPE: 'type', | ||
TX_HASH: genesisTxHash, | ||
INDEX: '0x9', | ||
DEP_TYPE: 'code', | ||
}, | ||
}, | ||
}; | ||
}; | ||
return devnetConfig; | ||
} | ||
|
||
export function buildLumosConfig() { | ||
const filePath = path.resolve(dappTemplatePath, 'config.json'); | ||
fs.writeFile(filePath, JSON.stringify(devnetConfig, null, 2), 'utf8', (err) => { | ||
if (err) { | ||
return console.error('Error writing file:', err); | ||
} | ||
}); | ||
export async function buildLumosConfig() { | ||
const rpcUrl = 'http://127.0.0.1:8114'; | ||
const rpc = new RPC(rpcUrl); | ||
const chainInfo = await rpc.getBlockchainInfo(); | ||
const genesisBlock = await rpc.getBlockByNumber('0x0'); | ||
const cellBaseTxHashInGenesisBlock = genesisBlock.transactions[0].hash; | ||
const secondTxHashInGenesisBlock = genesisBlock.transactions[1].hash; | ||
if (chainInfo.chain === 'offckb') { | ||
const config = devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock, secondTxHashInGenesisBlock); | ||
const filePath = path.resolve(dappTemplatePath, 'config.json'); | ||
fs.writeFile(filePath, JSON.stringify(config, null, 2), 'utf8', (err) => { | ||
if (err) { | ||
return console.error('Error writing file:', err); | ||
} | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { currentExecPath, dappTemplatePath } from '../cfg/const'; | ||
import path from 'path'; | ||
import { copyFolderSync } from '../util'; | ||
import { copyFileSync, copyFolderSync } from '../util'; | ||
|
||
export function init(name: string) { | ||
export function init(name: string, template: string) { | ||
const targetPath = path.resolve(currentExecPath, name); | ||
copyFolderSync(dappTemplatePath, targetPath); | ||
console.log(`init CKB dapp project with lumos: ${targetPath}`); | ||
const sourcePath = path.resolve(dappTemplatePath, template); | ||
copyFolderSync(sourcePath, targetPath); | ||
|
||
// add some common code files | ||
const ckbDotTs = path.resolve(dappTemplatePath, 'ckb.ts'); | ||
const configJson = path.resolve(dappTemplatePath, 'config.json'); | ||
copyFileSync(ckbDotTs, targetPath); | ||
copyFileSync(configJson, targetPath); | ||
|
||
console.log(`init CKB dapp project: ${targetPath}`); | ||
} |
Oops, something went wrong.