Skip to content

Commit

Permalink
Merge feae337 into 9cdd37f
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Jun 26, 2018
2 parents 9cdd37f + feae337 commit 55e1d2c
Show file tree
Hide file tree
Showing 351 changed files with 3,524 additions and 3,927 deletions.
1 change: 1 addition & 0 deletions .babelrc.js
@@ -0,0 +1 @@
module.exports = require('./babel.config.js');
16 changes: 0 additions & 16 deletions .flowconfig

This file was deleted.

2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -10,5 +10,5 @@
"packages": [
"packages/*"
],
"version": "0.11.8"
"version": "0.12.0"
}
11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -9,17 +9,18 @@
"packages/*"
],
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "eslint packages && flow check",
"build": "polkadot-dev-build-ts",
"check": "tsc --noEmit",
"clean": "polkadot-dev-clean-build",
"postinstall": "polkadot-dev-yarn-only",
"test": "jest --coverage",
"start": "node packages/client/scripts/polkadot.js --db-path ./tmp/start-1",
"start2": "node packages/client/scripts/polkadot.js --db-path ./tmp/start-2 --p2p-nodes /ip4/127.0.0.1/tcp/39933/ipfs/QmfUiXCYtrKotHgDbP4Kc74NUi2LxckEiAdkK1SMSosLaz --p2p-port 39934 --rpc-port 9934",
"start-rust": "node packages/client/scripts/polkadot.js --db-path ./tmp/start-rust --p2p-nodes /ip4/127.0.0.1/tcp/30333/ipfs/QmWLtV5gpCzJCh9Eo7SxkrT3ZTApovHM1WpCY2Lp3XkaqF /ip4/127.0.0.1/tcp/39933/ipfs/QmfUiXCYtrKotHgDbP4Kc74NUi2LxckEiAdkK1SMSosLaz --p2p-port 39935 --rpc-port 9935",
"test": "jest --coverage"
"start-rust": "node packages/client/scripts/polkadot.js --db-path ./tmp/start-rust --p2p-nodes /ip4/127.0.0.1/tcp/30333/ipfs/QmWLtV5gpCzJCh9Eo7SxkrT3ZTApovHM1WpCY2Lp3XkaqF /ip4/127.0.0.1/tcp/39933/ipfs/QmfUiXCYtrKotHgDbP4Kc74NUi2LxckEiAdkK1SMSosLaz --p2p-port 39935 --rpc-port 9935"
},
"devDependencies": {
"@polkadot/dev": "^0.19.25",
"@polkadot/dev": "^0.20.5",
"@polkadot/ts": "^0.1.3",
"lerna": "^2.11.0"
}
}
30 changes: 15 additions & 15 deletions packages/client-chains/package.json
@@ -1,6 +1,6 @@
{
"name": "@polkadot/client-chains",
"version": "0.11.8",
"version": "0.12.0",
"description": "Node configuration definitions for specific chains",
"main": "index.js",
"keywords": [
Expand Down Expand Up @@ -33,21 +33,21 @@
"test": "echo \"Tests only available from root wrapper\""
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.47",
"@polkadot/client-db-chain": "^0.11.8",
"@polkadot/client-runtime": "^0.11.8",
"@polkadot/client-wasm": "^0.11.8",
"@polkadot/storage": "^0.17.24",
"@polkadot/util": "^0.22.9",
"@polkadot/util-crypto": "^0.22.9",
"@polkadot/util-keyring": "^0.22.9"
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/client-db-chain": "^0.12.0",
"@polkadot/client-runtime": "^0.12.0",
"@polkadot/client-wasm": "^0.12.0",
"@polkadot/storage": "^0.20.2",
"@polkadot/util": "^0.24.7",
"@polkadot/util-crypto": "^0.24.7",
"@polkadot/util-keyring": "^0.24.7"
},
"devDependencies": {
"@polkadot/client": "^0.11.8",
"@polkadot/client-db": "^0.11.8",
"@polkadot/extrinsics-codec": "^0.17.24",
"@polkadot/primitives-builder": "^0.17.24",
"@polkadot/primitives-codec": "^0.17.24",
"@polkadot/storage": "^0.17.24"
"@polkadot/client": "^0.12.0",
"@polkadot/client-db": "^0.12.0",
"@polkadot/extrinsics-codec": "^0.20.2",
"@polkadot/primitives-builder": "^0.20.2",
"@polkadot/primitives-codec": "^0.20.2",
"@polkadot/storage": "^0.20.2"
}
}
87 changes: 47 additions & 40 deletions packages/client-chains/src/chains/chain-dev.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/client-chains/src/chains/chain-dev.spec.js
Expand Up @@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const memDb = require('@polkadot/util-triedb/temp');
import memDb from '@polkadot/util-triedb/temp';

const init = require('../index');
import init from '../index';

describe('genesis', () => {
let genesis;
Expand All @@ -21,7 +21,7 @@ describe('genesis', () => {
genesis.header.stateRoot
).toEqual(
new Uint8Array([
183, 79, 108, 134, 124, 245, 189, 86, 29, 84, 33, 80, 31, 234, 186, 201, 226, 21, 241, 214, 43, 76, 90, 92, 146, 31, 182, 6, 147, 161, 56, 103
232, 3, 212, 239, 20, 49, 65, 77, 86, 68, 197, 212, 177, 241, 76, 178, 26, 142, 255, 94, 53, 233, 250, 34, 213, 124, 35, 178, 189, 131, 41, 79
])
);
});
Expand All @@ -41,7 +41,7 @@ describe('genesis', () => {
genesis.headerHash
).toEqual(
new Uint8Array([
168, 135, 224, 93, 140, 222, 226, 83, 13, 116, 138, 197, 164, 6, 48, 190, 101, 18, 221, 166, 40, 179, 158, 112, 133, 154, 215, 198, 177, 76, 212, 228
27, 232, 237, 33, 3, 51, 112, 44, 133, 33, 8, 49, 146, 238, 217, 114, 216, 28, 16, 255, 124, 53, 209, 85, 192, 157, 181, 247, 78, 101, 19, 96
])
);
});
Expand Down
13 changes: 0 additions & 13 deletions packages/client-chains/src/chains/index.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/client-chains/src/chains/index.ts
@@ -0,0 +1,11 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import { ChainGenesisState } from '../types';

const dev = (require('./chain-dev.json') as ChainGenesisState);

export default ({
dev
} as { [index: string]: ChainGenesisState });
@@ -1,14 +1,13 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

import type { ChainName } from './types';
import { ChainName } from './types';

const MAIN: ChainName = 'dev';
const TEST: ChainName = 'dev';

module.exports = {
export default {
MAIN,
TEST
};
@@ -1,21 +1,20 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

import type { ChainState, ChainGenesis } from '../types';
import { ChainState, ChainGenesis } from '../types';

const createBlock = require('@polkadot/primitives-builder/block');
const encodeBlock = require('@polkadot/primitives-codec/block/encode');
const encodeHeader = require('@polkadot/primitives-codec/header/encode');
const storage = require('@polkadot/storage');
const key = require('@polkadot/storage/key');
const blake2Asu8a = require('@polkadot/util-crypto/blake2/asU8a');
const trieRoot = require('@polkadot/util-triehash/root');
import createBlock from '@polkadot/primitives-builder/block';
import encodeBlock from '@polkadot/primitives-codec/block/encode';
import encodeHeader from '@polkadot/primitives-codec/header/encode';
import storage from '@polkadot/storage';
import key from '@polkadot/storage/key';
import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a';
import trieRoot from '@polkadot/util-triehash/root';

const CODE_KEY = key(storage.consensus.public.code)();

module.exports = function genesisBlock ({ stateDb: { db }, chain }: ChainState): ChainGenesis {
export default function genesisBlock ({ stateDb: { db } }: ChainState): ChainGenesis {
const code = db.get(CODE_KEY);

if (code === null) {
Expand All @@ -39,4 +38,4 @@ module.exports = function genesisBlock ({ stateDb: { db }, chain }: ChainState):
header: block.header,
headerHash
};
};
}
@@ -1,14 +1,13 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

import type { ChainState, ChainGenesis, ChainGenesisState } from '../types';
import { ChainState, ChainGenesis, ChainGenesisState } from '../types';

const initBlock = require('./block');
const initState = require('./state');
import initBlock from './block';
import initState from './state';

module.exports = function initGenesis (self: ChainState, initialState: ChainGenesisState): ChainGenesis {
export default function initGenesis (self: ChainState, initialState: ChainGenesisState): ChainGenesis {
initState(self, initialState);

const genesis = initBlock(self);
Expand All @@ -21,4 +20,4 @@ module.exports = function initGenesis (self: ChainState, initialState: ChainGene
self.stateDb.db.commit();

return genesis;
};
}
@@ -1,16 +1,15 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

import type { ChainState, ChainGenesisState } from '../types';
import { ChainState, ChainGenesisState } from '../types';

const hexToU8a = require('@polkadot/util/hex/toU8a');
import hexToU8a from '@polkadot/util/hex/toU8a';

module.exports = function genesisState ({ stateDb: { db } }: ChainState, initial: ChainGenesisState): void {
export default function genesisState ({ stateDb: { db } }: ChainState, initial: ChainGenesisState): void {
Object.keys(initial).forEach((key) =>
db.set(hexToU8a(key), hexToU8a(initial[key]))
);

db.commit();
};
}
4 changes: 2 additions & 2 deletions packages/client-chains/src/index.spec.js
Expand Up @@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const memoryDb = require('@polkadot/util-triedb/temp');
import memoryDb from '@polkadot/util-triedb/temp';

const createChain = require('./index');
import createChain from './index';

describe('client-chains', () => {
let config;
Expand Down
@@ -1,19 +1,18 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

import type { Config } from '@polkadot/client/types';
import type { TrieDb } from '@polkadot/util-triedb/types';
import type { ChainInterface } from './types';
import { Config } from '@polkadot/client/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { ChainInterface } from './types';

const createExecutor = require('@polkadot/client-wasm');
import createExecutor from '@polkadot/client-wasm/index';

const loadChain = require('./load');
const createGenesis = require('./genesis');
const createState = require('./state');
import loadChain from './load';
import createGenesis from './genesis';
import createState from './state';

module.exports = function chains (config: Config, baseStateDb: TrieDb, baseBlockDb: TrieDb): ChainInterface {
export default function chains (config: Config, baseStateDb: TrieDb, baseBlockDb: TrieDb): ChainInterface {
const initial = loadChain(config.chain);
const self = createState(config, baseStateDb, baseBlockDb);
const genesis = createGenesis(self, initial);
Expand All @@ -25,4 +24,4 @@ module.exports = function chains (config: Config, baseStateDb: TrieDb, baseBlock
genesis,
state: self.stateDb
};
};
}
2 changes: 1 addition & 1 deletion packages/client-chains/src/load.spec.js
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const loadChain = require('./load');
import loadChain from './load';

describe('loadChain', () => {
it('loads a chain from chains/*', () => {
Expand Down
@@ -1,21 +1,19 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

import type { ChainGenesisState, ChainName } from './types';
import { ChainGenesisState } from './types';

const assert = require('@polkadot/util/assert');
import assert from '@polkadot/util/assert';

const chains = require('./chains');
import chains from './chains';

// TODO We should load chains from json files as well

module.exports = function load (name: string): ChainGenesisState {
// flowlint-next-line unclear-type:off
const chain = chains[((name: any): ChainName)];
export default function load (name: string): ChainGenesisState {
const chain = chains[name];

assert(chain, `Unable to find builtin chain '${name}'`);

return chain;
};
}
28 changes: 0 additions & 28 deletions packages/client-chains/src/state.js

This file was deleted.

27 changes: 27 additions & 0 deletions packages/client-chains/src/state.ts
@@ -0,0 +1,27 @@
// Copyright 2017-2018 @polkadot/client-chains authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import { Config } from '@polkadot/client/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { ChainState } from './types';

import createBlockDb from '@polkadot/client-db-chain/block';
import createStateDb from '@polkadot/client-db-chain/state';
import createRuntime from '@polkadot/client-runtime/index';
import logger from '@polkadot/util/logger';

export default function state (config: Config, baseStateDb: TrieDb, baseBlockDb: TrieDb): ChainState {
const l = logger(`chain-${config.chain}`);
const runtime = createRuntime(baseStateDb);
const blockDb = createBlockDb(baseBlockDb);
const stateDb = createStateDb(runtime.environment.db);

return {
blockDb,
config,
l,
runtime,
stateDb
};
}

0 comments on commit 55e1d2c

Please sign in to comment.