Skip to content

Commit

Permalink
Merge pull request #426 from nervosnetwork/rc/v0.29.1
Browse files Browse the repository at this point in the history
[ᚬmaster] Rc/v0.29.1
  • Loading branch information
Keith-CY authored Feb 28, 2020
2 parents f36a6b2 + be1036d commit 467f5ca
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 29 deletions.
11 changes: 11 additions & 0 deletions 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.29.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.1) (2020-02-28)


### Bug Fixes

* **core:** fix the calculation of epoch locks in nervos dao operation ([d914007](https://github.com/nervosnetwork/ckb-sdk-js/commit/d914007fd14456217d4f4430ad4e868ca998f65d))





# [0.29.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.0) (2020-02-28)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.29.0"
"version": "0.29.1"
}
11 changes: 11 additions & 0 deletions packages/ckb-sdk-core/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.29.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.1) (2020-02-28)


### Bug Fixes

* **core:** fix the calculation of epoch locks in nervos dao operation ([d914007](https://github.com/nervosnetwork/ckb-sdk-js/commit/d914007fd14456217d4f4430ad4e868ca998f65d))





# [0.29.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.0) (2020-02-28)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core
Expand Down
121 changes: 121 additions & 0 deletions packages/ckb-sdk-core/__tests__/utils/fixtures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"calculateLockEpochs": [
{
"depositEpoch": {
"number": "0",
"index": "0",
"length": "100"
},
"withdrawEpoch": {
"number": "0",
"index": "0",
"length": "100"
},
"expected": "180"
},
{
"depositEpoch": {
"number": "1",
"index": "0",
"length": "100"
},
"withdrawEpoch": {
"number": "1",
"index": "0",
"length": "100"
},
"expected": "180"
},
{
"depositEpoch": {
"number": "0",
"index": "0",
"length": "100"
},
"withdrawEpoch": {
"number": "179",
"index": "0",
"length": "100"
},
"expected": "180"
},
{
"depositEpoch": {
"number": "0",
"index": "0",
"length": "100"
},
"withdrawEpoch": {
"number": "179",
"index": "0",
"length": "100"
},
"expected": "180"
},
{
"depositEpoch": {
"number": "0",
"index": "1",
"length": "100"
},
"withdrawEpoch": {
"number": "179",
"index": "0",
"length": "100"
},
"expected": "180"
},
{
"depositEpoch": {
"number": "0",
"index": "0",
"length": "100"
},
"withdrawEpoch": {
"number": "179",
"index": "1",
"length": "100"
},
"expected": "180"
},
{
"depositEpoch": {
"number": "0",
"index": "0",
"length": "100"
},
"withdrawEpoch": {
"number": "180",
"index": "0",
"length": "100"
},
"expected": "180"
},
{
"depositEpoch": {
"number": "0",
"index": "0",
"length": "100"
},
"withdrawEpoch": {
"number": "180",
"index": "1",
"length": "100"
},
"expected": "360"
},
{
"depositEpoch": {
"number": "1",
"index": "634",
"length": "1800"
},
"withdrawEpoch": {
"number": "4",
"index": "820",
"length": "1800"
},
"expected": "180"
}
]
}
21 changes: 21 additions & 0 deletions packages/ckb-sdk-core/__tests__/utils/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { calculateLockEpochs } = require('../../lib/utils')
const fixtures = require('./fixtures.json')

describe('Test utils', () => {
describe('Test calculate lock epochs', () => {
const fixtureTable = fixtures.calculateLockEpochs.map(({ depositEpoch, withdrawEpoch, expected }) => [
depositEpoch,
withdrawEpoch,
expected,
])

test.each(fixtureTable)(`(%s, %s) => %s`, (depositEpoch, withdrawEpoch, expected) => {
const actual = calculateLockEpochs({
depositEpoch,
withdrawEpoch,
DAO_LOCK_PERIOD_EPOCHS: 180,
})
expect(actual.toString()).toBe(expected)
})
})
})
10 changes: 5 additions & 5 deletions packages/ckb-sdk-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-core",
"version": "0.29.0",
"version": "0.29.1",
"description": "JavaScript SDK for Nervos Network CKB Project",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand Down Expand Up @@ -31,9 +31,9 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-rpc": "0.29.0",
"@nervosnetwork/ckb-sdk-utils": "0.29.0",
"@nervosnetwork/ckb-types": "0.29.0"
"@nervosnetwork/ckb-sdk-rpc": "0.29.1",
"@nervosnetwork/ckb-sdk-utils": "0.29.1",
"@nervosnetwork/ckb-types": "0.29.1"
},
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15"
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500"
}
16 changes: 2 additions & 14 deletions packages/ckb-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import generateRawTransaction, { Cell, RawTransactionParamsBase } from './genera

import loadCells from './loadCells'
import signWitnesses, { isMap } from './signWitnesses'
import {calculateLockEpochs} from './utils'


type Key = string
Expand Down Expand Up @@ -420,20 +421,7 @@ class CKB {
const withdrawBlockHeader = await this.rpc.getBlock(tx.txStatus.blockHash).then(block => block.header)
const withdrawEpoch = this.utils.parseEpoch(withdrawBlockHeader.epoch)

const withdrawFraction = JSBI.multiply(JSBI.BigInt(withdrawEpoch.index), JSBI.BigInt(depositEpoch.length))
const depositFraction = JSBI.multiply(JSBI.BigInt(depositEpoch.index) , JSBI.BigInt(withdrawEpoch.length))
let depositedEpochs = JSBI.subtract(JSBI.BigInt(withdrawEpoch.number) , JSBI.BigInt(depositEpoch.number))
if (JSBI.greaterThan(withdrawFraction, depositFraction)) {
depositedEpochs = JSBI.add(depositedEpochs, JSBI.BigInt(1))
}
const lockEpochs = JSBI.multiply(
JSBI.divide(
JSBI.add(
depositedEpochs, JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS - 1)
),
JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS)
), JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS)
)
const lockEpochs = calculateLockEpochs({withdrawEpoch,depositEpoch,DAO_LOCK_PERIOD_EPOCHS})
const minimalSince = this.absoluteEpochSince({
length: `0x${JSBI.BigInt(depositEpoch.length).toString(16)}`,
index: `0x${JSBI.BigInt(depositEpoch.index).toString(16)}`,
Expand Down
37 changes: 37 additions & 0 deletions packages/ckb-sdk-core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { JSBI } from '@nervosnetwork/ckb-sdk-utils'

interface EpochInfo {
index: string
length: string
number: string
}

export const calculateLockEpochs = ({
withdrawEpoch,
depositEpoch,
DAO_LOCK_PERIOD_EPOCHS,
}: {
withdrawEpoch: EpochInfo
depositEpoch: EpochInfo
DAO_LOCK_PERIOD_EPOCHS: number
}) => {
const withdrawFraction = JSBI.multiply(JSBI.BigInt(withdrawEpoch.index), JSBI.BigInt(depositEpoch.length))
const depositFraction = JSBI.multiply(JSBI.BigInt(depositEpoch.index), JSBI.BigInt(withdrawEpoch.length))
let depositedEpochs = JSBI.subtract(JSBI.BigInt(withdrawEpoch.number), JSBI.BigInt(depositEpoch.number))
if (JSBI.greaterThan(withdrawFraction, depositFraction)) {
depositedEpochs = JSBI.add(depositedEpochs, JSBI.BigInt(1))
}
/* eslint-disable indent */
const lockEpochs = JSBI.lessThan(depositedEpochs, JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS))
? JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS)
: JSBI.multiply(
JSBI.divide(
JSBI.add(depositedEpochs, JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS - 1)),
JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS),
),
JSBI.BigInt(DAO_LOCK_PERIOD_EPOCHS),
)
/* eslint-enable indent */
return lockEpochs
}
export default { calculateLockEpochs }
16 changes: 16 additions & 0 deletions packages/ckb-sdk-rpc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.29.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.1) (2020-02-28)


### Features

* **rpc:** update the action of outputs validator when it is null ([4932c47](https://github.com/nervosnetwork/ckb-sdk-js/commit/4932c479141b6d7a109705c389290b66d67c83a2))


### BREAKING CHANGES

* **rpc:** null outputs validator is equivalent to the passthrough one





# [0.29.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.0) (2020-02-28)


Expand Down
8 changes: 4 additions & 4 deletions packages/ckb-sdk-rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-rpc",
"version": "0.29.0",
"version": "0.29.1",
"description": "RPC module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme",
Expand Down Expand Up @@ -33,12 +33,12 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.29.0",
"@nervosnetwork/ckb-sdk-utils": "0.29.1",
"axios": "0.19.0"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.29.0",
"@nervosnetwork/ckb-types": "0.29.1",
"dotenv": "8.1.0"
},
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15"
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-utils/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.29.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.1) (2020-02-28)

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





# [0.29.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.0) (2020-02-28)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-utils
Expand Down
6 changes: 3 additions & 3 deletions packages/ckb-sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-utils",
"version": "0.29.0",
"version": "0.29.1",
"description": "Utils module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand Down Expand Up @@ -31,7 +31,7 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-types": "0.29.0",
"@nervosnetwork/ckb-types": "0.29.1",
"blake2b-wasm": "2.1.0",
"elliptic": "6.5.2",
"jsbi": "3.1.1"
Expand All @@ -41,5 +41,5 @@
"@types/elliptic": "6.4.8",
"@types/utf8": "2.1.6"
},
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15"
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500"
}
8 changes: 8 additions & 0 deletions packages/ckb-types/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.29.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.1) (2020-02-28)

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





# [0.29.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.28.0...v0.29.0) (2020-02-28)

**Note:** Version bump only for package @nervosnetwork/ckb-types
Expand Down
4 changes: 2 additions & 2 deletions packages/ckb-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-types",
"version": "0.29.0",
"version": "0.29.1",
"description": "Type module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand All @@ -23,5 +23,5 @@
"scripts": {
"doc": "../../node_modules/.bin/typedoc --out docs ./index.d.ts --mode modules --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default --readme README.md"
},
"gitHead": "0907e4ead0d2ff70dab46fd9ba637d9ee9f02a15"
"gitHead": "dacec65239c3683f4ea0e5b1946f9ec74d275500"
}

0 comments on commit 467f5ca

Please sign in to comment.