Skip to content

Commit

Permalink
Merge pull request #271 from nervosnetwork/rc/v0.15.0
Browse files Browse the repository at this point in the history
[ᚬmaster] Rc/v0.15.0
  • Loading branch information
Keith-CY authored Jun 29, 2019
2 parents 8372c9f + 5981b1c commit e2aa259
Show file tree
Hide file tree
Showing 39 changed files with 2,199 additions and 1,442 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.15.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.14.0...v0.15.0) (2019-06-29)


### Bug Fixes

* **rpc:** binding the node of method instances to the one of rpc instance. ([f0b486a](https://github.com/nervosnetwork/ckb-sdk-js/commit/f0b486a))


### Features

* **cli:** add dashboard mode of ckb-cli ([9accdeb](https://github.com/nervosnetwork/ckb-sdk-js/commit/9accdeb))
* **rpc:** add index related rpc ([cf8931b](https://github.com/nervosnetwork/ckb-sdk-js/commit/cf8931b))
* **rpc:** add index related rpc ([2a7d403](https://github.com/nervosnetwork/ckb-sdk-js/commit/2a7d403))
* **rpc:** update get blockchain info rpc ([7382458](https://github.com/nervosnetwork/ckb-sdk-js/commit/7382458))
* **rpc:** update the type of epoch ([509a79b](https://github.com/nervosnetwork/ckb-sdk-js/commit/509a79b))
* **utils:** add signRecoverable method to the ECPair class ([3c1f334](https://github.com/nervosnetwork/ckb-sdk-js/commit/3c1f334))


### BREAKING CHANGES

* **rpc:** update the type of epoch, remove block_reward, last_block_hash_in_previous_epoch,
remainder_reward fields, add epoch_reward field.
* **rpc:** replace warnings field with alerts field in the response of get blockchain info rpc
* **utils:** use signRecoverable instead of sign method to sign the transactions.





# [0.14.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.13.0...v0.14.0) (2019-06-15)


Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
| Coverage | [![Codecov](https://codecov.io/gh/nervosnetwork/ckb-sdk-js/branch/master/graph/badge.svg)](https://codecov.io/gh/nervosnetwork/ckb-sdk-js/branch/master) | [![Codecov](https://codecov.io/gh/nervosnetwork/ckb-sdk-js/branch/develop/graph/badge.svg)](https://codecov.io/gh/nervosnetwork/ckb-sdk-js/branch/develop) |

[![NPM](https://img.shields.io/npm/v/@nervosnetwork/ckb-sdk-core/latest.svg)](https://www.npmjs.com/package/@nervosnetwork/ckb-sdk-core)
[![Package Quality](https://npm.packagequality.com/shield/%40nervosnetwork%2Fckb-sdk-core.svg)](https://packagequality.com/#?package=@nervosnetwork/ckb-sdk-core)
[![License](https://img.shields.io/npm/l/@nervosnetwork/ckb-sdk-core.svg)](./LICENSE)
[![Telegram Group](https://cdn.rawgit.com/Patrolavia/telegram-badge/8fe3382b/chat.svg)](https://t.me/nervos_ckb_dev)
![License](https://img.shields.io/npm/l/@nervosnetwork/ckb-sdk-core.svg)

JavaScript SDK for Nervos [CKB](https://github.com/nervosnetwork/ckb).

Expand Down Expand Up @@ -168,9 +169,9 @@ The rpc module will throw an error when the result contains an error field, you
This project used [lerna](https://github.com/lerna/lerna/) for packages management, which needs to be bootstrapped by the following steps:

```sh
$ yarn install # to install the lerna package in this project, could be skipped if the lerna has been installed globally
$ lerna bootstrap # install the depedencies and link the packages in the project
$ npm run tsc # build packages with tsc command
$ yarn add lerna --exact --ignore-workspace-root-check # to install the lerna package in this project, could be skipped if the lerna has been installed globally
$ npx lerna bootstrap # install the depedencies and link the packages in the project
$ yarn run tsc # build packages with tsc command
```

After the second step, namely the bootstrap, all module packages are linked together, and used as in one package.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "0.14.0"
"version": "0.15.0"
}
11 changes: 11 additions & 0 deletions packages/ckb-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.15.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.14.0...v0.15.0) (2019-06-29)


### Features

* **cli:** add dashboard mode of ckb-cli ([9accdeb](https://github.com/nervosnetwork/ckb-sdk-js/commit/9accdeb))





# [0.14.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.13.0...v0.14.0) (2019-06-15)

**Note:** Version bump only for package @nervosnetwork/ckb-cli
Expand Down
10 changes: 9 additions & 1 deletion packages/ckb-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ $ npm install -g @nervosnetwork/ckb-cli

## Usage

### REPL

```sh
$ @nervosnetwork/ckb-cli <url to the node>
$ ckb-cli i <url to the node>
ckb => connected to <url to the node>
ckb => await core.rpc.getTipBlockNumber()
'6905'
Expand Down Expand Up @@ -63,3 +65,9 @@ ckb => await core.rpc.getBlock('0x89de946313839a8a77749b6218d4d7ab3513910c5ed860
proposals: [] }
ckb =>
```
### Dashboard
```sh
$ ckb-cli d <url to the node>
```
9 changes: 6 additions & 3 deletions packages/ckb-cli/package.json
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",
Expand Down Expand Up @@ -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"
}
169 changes: 169 additions & 0 deletions packages/ckb-cli/src/dashboard/index.ts
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
14 changes: 13 additions & 1 deletion packages/ckb-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import repl from 'repl'
import Core from '@nervosnetwork/ckb-sdk-core'
import commander from 'commander'
import { prompt } from 'inquirer'
// import questions from './rpc' // { rpcMethods }
import dashboard from './dashboard'

const RPC_URL = 'http://localhost:8114'

Expand Down Expand Up @@ -70,8 +70,20 @@ commander
const core = new Core(remote)
replServer.context.core = core
replServer.context.rpc = {}
replServer.context.dashboard = () => dashboard(core)
Object.keys(core.rpc).forEach(key => {
replServer.context.rpc[key] = (core.rpc as any)[key]
})
})

commander
.command('dashboard [remote]')
.alias('d')
.description('dashboard')
.action(async (remote = RPC_URL) => {
console.info('boosting the dashboard')
const core = new Core(remote)
dashboard(core).start()
})

commander.parse(process.argv)
8 changes: 8 additions & 0 deletions packages/ckb-sdk-address/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.15.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.14.0...v0.15.0) (2019-06-29)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address





# [0.14.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.13.0...v0.14.0) (2019-06-15)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address
Expand Down
8 changes: 4 additions & 4 deletions packages/ckb-sdk-address/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-address",
"version": "0.14.0",
"version": "0.15.0",
"description": "Address module of @nervosnetwork/ckb-sdk-core",
"keywords": [
"CKB",
Expand Down Expand Up @@ -33,8 +33,8 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.14.0",
"@nervosnetwork/ckb-types": "0.14.0"
"@nervosnetwork/ckb-sdk-utils": "0.15.0",
"@nervosnetwork/ckb-types": "0.15.0"
},
"gitHead": "4fcb80e6068f9219076005435445a41333c00ea9"
"gitHead": "77e21f208d5ad443801e758dc80c2ded32036c28"
}
21 changes: 21 additions & 0 deletions packages/ckb-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.15.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.14.0...v0.15.0) (2019-06-29)


### Bug Fixes

* **rpc:** binding the node of method instances to the one of rpc instance. ([f0b486a](https://github.com/nervosnetwork/ckb-sdk-js/commit/f0b486a))


### Features

* **utils:** add signRecoverable method to the ECPair class ([3c1f334](https://github.com/nervosnetwork/ckb-sdk-js/commit/3c1f334))


### BREAKING CHANGES

* **utils:** use signRecoverable instead of sign method to sign the transactions.





# [0.14.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.13.0...v0.14.0) (2019-06-15)

* **core:** add signWitnesses and signTransaction methods in the core module ([c20d36c](https://github.com/nervosnetwork/ckb-sdk-js/commit/c20d36c))
Expand Down
Loading

0 comments on commit e2aa259

Please sign in to comment.