-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from nervosnetwork/rc/v0.15.0
[ᚬmaster] Rc/v0.15.0
- Loading branch information
Showing
39 changed files
with
2,199 additions
and
1,442 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
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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "0.14.0" | ||
"version": "0.15.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
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,6 +1,6 @@ | ||
{ | ||
"name": "@nervosnetwork/ckb-cli", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"description": "Command line package based on @nervosnetwork/ckb-sdk-core", | ||
"author": "Nervos <[email protected]>", | ||
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", | ||
|
@@ -34,13 +34,16 @@ | |
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" | ||
}, | ||
"dependencies": { | ||
"@nervosnetwork/ckb-sdk-core": "0.14.0", | ||
"@nervosnetwork/ckb-sdk-core": "0.15.0", | ||
"blessed": "0.1.81", | ||
"blessed-contrib": "4.8.16", | ||
"commander": "2.20.0", | ||
"inquirer": "6.2.1" | ||
}, | ||
"devDependencies": { | ||
"@types/blessed": "0.1.11", | ||
"@types/crypto-js": "3.1.43", | ||
"@types/inquirer": "6.0.0" | ||
}, | ||
"gitHead": "4fcb80e6068f9219076005435445a41333c00ea9" | ||
"gitHead": "77e21f208d5ad443801e758dc80c2ded32036c28" | ||
} |
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,169 @@ | ||
import Core from '@nervosnetwork/ckb-sdk-core' | ||
import * as contrib from 'blessed-contrib' | ||
import { screen } from 'blessed' | ||
|
||
const { grid: Grid, table } = contrib | ||
|
||
const MAX_BLOCKS = 50 | ||
const MAX_TRANSACTIONS = 50 | ||
let listener: any | ||
|
||
interface ChainInfo { | ||
url: string | ||
version: string | ||
tipNumber: string | ||
} | ||
type Block = [string, string, number] // [number, hash, tx count] | ||
type Transaction = [string, string, string] // [hash, inputs, outputs] | ||
interface RenderedData { | ||
chainInfo: ChainInfo | ||
blocks: Block[] | ||
transactions: Transaction[] | ||
} | ||
|
||
const data: RenderedData = { | ||
chainInfo: { | ||
url: '', | ||
version: '', | ||
tipNumber: '', | ||
}, | ||
blocks: [], | ||
transactions: [], | ||
} | ||
|
||
const dashboard = (core: Core) => { | ||
const MainScreen = screen({ | ||
smartCSR: true, | ||
cursor: { | ||
artificial: true, | ||
shape: 'underline', | ||
blink: false, | ||
color: 'white', | ||
}, | ||
}) | ||
|
||
MainScreen.key(['escape', 'C-c'], () => process.exit(0)) | ||
|
||
const Layout = new Grid({ | ||
rows: 12, | ||
cols: 12, | ||
screen: MainScreen, | ||
}) | ||
|
||
const chainInfo = Layout.set(0, 0, 2, 12, table, { | ||
label: 'Chain Infomation', | ||
fg: 'white', | ||
columnSpacing: 10, | ||
columnWidth: [30, 60, 30], | ||
interactive: false, | ||
data: { | ||
headers: [], | ||
data: [], | ||
}, | ||
}) | ||
|
||
const updateChainInfo = (info: ChainInfo) => { | ||
chainInfo.setData({ | ||
headers: Object.keys(info).map(() => ''), | ||
data: Object.entries(info), | ||
}) | ||
MainScreen.render() | ||
} | ||
|
||
const blocks = Layout.set(2, 0, 3, 12, table, { | ||
label: 'Block List', | ||
fg: 'white', | ||
columnSpacing: 10, | ||
columnWidth: [15, 66, 10], | ||
interactive: false, | ||
scrollable: true, | ||
data: { | ||
headers: [], | ||
data: [], | ||
}, | ||
}) | ||
|
||
const updateBlocks = (info: Block[]) => { | ||
blocks.setData({ | ||
headers: ['block number', 'hash', 'tx count'], | ||
data: info, | ||
}) | ||
MainScreen.render() | ||
} | ||
|
||
const transactions = Layout.set(5, 0, 7, 12, table, { | ||
label: 'Transaction List', | ||
fg: 'white', | ||
columnSpacing: 10, | ||
columnWidth: [66, 30, 60], | ||
interactive: false, | ||
scrollable: true, | ||
data: { | ||
headers: [], | ||
data: [], | ||
}, | ||
}) | ||
|
||
const updateTransactions = (info: Transaction[]) => { | ||
transactions.setData({ | ||
headers: ['hash', 'inputs', 'outputs'], | ||
data: info, | ||
}) | ||
MainScreen.render() | ||
} | ||
|
||
const fetchAndUpdateChainInfo = async () => { | ||
const [nodeInfo, tipNumber] = await Promise.all([core.rpc.localNodeInfo(), core.rpc.getTipBlockNumber()]) | ||
data.chainInfo = { | ||
url: core.node.url, | ||
version: nodeInfo.version, | ||
tipNumber, | ||
} | ||
updateChainInfo(data.chainInfo) | ||
} | ||
|
||
const fetchAndUpdateBlock = async () => { | ||
const block = await core.rpc.getBlockByNumber(data.chainInfo.tipNumber) | ||
data.blocks = [ | ||
[block.header.number, block.header.hash, block.transactions.length], | ||
...data.blocks.slice(0, MAX_BLOCKS - 1), | ||
] | ||
const { transactions: txs } = block | ||
if (txs.length) { | ||
const newTxs: Transaction[] = txs.map(tx => [ | ||
tx.hash, | ||
JSON.stringify(tx.inputs.map(input => input.previousOutput.cell)), | ||
JSON.stringify(tx.outputs.map(output => `${output.lock.args[0]}-${output.capacity}`)), | ||
]) | ||
data.transactions = [...newTxs, ...data.transactions].slice(0, MAX_TRANSACTIONS) | ||
} | ||
updateBlocks(data.blocks) | ||
updateTransactions(data.transactions) | ||
} | ||
|
||
const stop = () => { | ||
clearInterval(listener) | ||
MainScreen.destroy() | ||
} | ||
|
||
const start = () => { | ||
listener = setInterval(async () => { | ||
try { | ||
const currentTipNumber = data.chainInfo.tipNumber | ||
await fetchAndUpdateChainInfo() | ||
if (+data.chainInfo.tipNumber > +currentTipNumber) { | ||
fetchAndUpdateBlock() | ||
} | ||
} catch (err) { | ||
stop() | ||
console.error(err.message) | ||
} | ||
}, 500) | ||
} | ||
return { | ||
start, | ||
stop, | ||
} | ||
} | ||
|
||
export default dashboard |
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
Oops, something went wrong.