Skip to content

Commit

Permalink
Merge pull request #49 from iov-one/48-core-0.17
Browse files Browse the repository at this point in the history
Update IOV-Core to v0.17
  • Loading branch information
merge-when-green[bot] authored Aug 22, 2019
2 parents c5f9251 + 82f2ca0 commit 0135e34
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 127 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"iov-faucet": "bin/iov-faucet"
},
"dependencies": {
"@iov/bns": "^0.16.0-alpha.3",
"@iov/ethereum": "^0.16.0-alpha.3",
"@iov/keycontrol": "^0.16.0-alpha.3",
"@iov/lisk": "^0.16.0-alpha.3",
"@iov/multichain": "^0.16.0-alpha.3",
"@iov/bns": "^0.17",
"@iov/ethereum": "^0.17",
"@iov/keycontrol": "^0.17",
"@iov/lisk": "^0.17",
"@iov/multichain": "^0.17",
"@koa/cors": "^2.2.2",
"@types/koa-bodyparser": "^4.2.1",
"bn.js": "^4.11.8",
Expand Down
2 changes: 1 addition & 1 deletion scripts/bnsd/bnsd_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
APP_STATE=$(<"$SCRIPT_DIR/genesis_app_state.json")
# shellcheck disable=SC2002
cat "${BNSD_DIR}/config/genesis.json.orig" \
| jq '.chain_id = "local-bns-devnet"' \
| jq '.chain_id = "local-iov-devnet"' \
| jq ". + {\"app_state\" : $APP_STATE}" \
> "${BNSD_DIR}/config/genesis.json"

Expand Down
126 changes: 126 additions & 0 deletions scripts/bnsd/deploy_proposals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { isBlockInfoPending, isBlockInfoSucceeded } = require("@iov/bcp");
const { bnsCodec, BnsConnection, VoteOption } = require("@iov/bns");
const { /* committeeIds, guaranteeFundEscrowIds, */ Governor, ProposalType } = require("@iov/bns-governance");
const { Ed25519HdWallet, HdPaths, UserProfile } = require("@iov/keycontrol");

// Dev admin
// path: m/44'/234'/0'
// pubkey: 418f88ff4876d33a3d6e2a17d0fe0e78dc3cb5e4b42c6c156ed1b8bfce5d46d1
// IOV address: tiov15nuhg3l8ma2mdmcdvgy7hme20v3xy5mkxcezea
// This account has money in the genesis file (see scripts/bnsd/README.md).
const adminMnemonic = "degree tackle suggest window test behind mesh extra cover prepare oak script";
const adminPath = HdPaths.iov(0);
const committeeId = 2;
const electionRuleId = process.env.ELECTION_RULE_ID ? parseInt(process.env.ELECTION_RULE_ID, 10) : 3;
const bnsdUrl = "ws://localhost:23456";
const connectionPromise = BnsConnection.establish(bnsdUrl);

function createSignAndPoster(connection, profile) {
return async function signAndPost(tx) {
const nonce = await connection.getNonce({ pubkey: tx.creator.pubkey });
const signed = await profile.signTransaction(tx, bnsCodec, nonce);
const txBytes = bnsCodec.bytesToPost(signed);
const post = await connection.postTx(txBytes);
const blockInfo = await post.blockInfo.waitFor(info => !isBlockInfoPending(info));
if (!isBlockInfoSucceeded(blockInfo)) {
throw new Error("Transaction failed", tx);
}
};
}

async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async function main() {
const connection = await connectionPromise;
const chainId = await connection.chainId();
const profile = new UserProfile();
const wallet = profile.addWallet(Ed25519HdWallet.fromMnemonic(adminMnemonic));
const identity = await profile.createIdentity(wallet.id, chainId, adminPath);
const signAndPost = createSignAndPoster(connection, profile);

const governorOptions = {
connection: connection,
identity: identity,
};
const governor = new Governor(governorOptions);

const proposalOptions = [
{
type: ProposalType.AddCommitteeMember,
title: "Add committee member",
description: "Add a committee member in more detail",
electionRuleId: electionRuleId,
committee: committeeId,
address: "tiov12shyht3pvvacvyee36w5844jkfh5s0mf4gszp9",
weight: 3,
},
{
type: ProposalType.AmendElectionRuleThreshold,
title: "Amend election rule threshold",
description: "Amend the election rule threshold in more detail",
electionRuleId: electionRuleId,
targetElectionRuleId: electionRuleId,
threshold: {
numerator: 3,
denominator: 4,
},
},
{
type: ProposalType.AmendElectionRuleQuorum,
title: "Amend election rule quorum",
description: "Amend the election rule quorum in more detail",
electionRuleId: electionRuleId,
targetElectionRuleId: electionRuleId,
quorum: {
numerator: 4,
denominator: 7,
},
},
{
type: ProposalType.AddValidator,
title: "Add validator",
description: "Add a validator in more detail",
electionRuleId: electionRuleId,
pubkey: identity.pubkey,
power: 2,
},
{
type: ProposalType.AmendProtocol,
title: "Amend protocol",
description: "Amend the protocol in more detail",
electionRuleId: electionRuleId,
text: "Give IOV devs master keys to all accounts",
},
];

for (let i = 0; i < proposalOptions.length; ++i) {
const createProposalTx = await governor.buildCreateProposalTx({
...proposalOptions[i],
startTime: new Date(Date.now() + 1000),
});
await signAndPost(createProposalTx);

await sleep(7000);

// Vote on 2/3 of the proposals
if (i % 3) {
const proposals = await governor.getProposals();
const voteTx = await governor.buildVoteTx(
proposals[proposals.length - 1].id,
// Vote Yes 1/2 of the time, No for the other 1/2
i % 2 ? VoteOption.Yes : VoteOption.No,
);
await signAndPost(voteTx);
}
}
}

main()
.catch(console.error)
.finally(async () => {
(await connectionPromise).disconnect();
process.exit(0);
});
52 changes: 45 additions & 7 deletions scripts/bnsd/genesis_app_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"governance": {
"electorate": [
{
"admin": "bech32:tiov15nuhg3l8ma2mdmcdvgy7hme20v3xy5mkxcezea",
"admin": "cond:gov/rule/0000000000000001",
"title": "Default electorate",
"electors": [
{
Expand All @@ -52,19 +52,19 @@
]
},
{
"admin": "bech32:tiov15nuhg3l8ma2mdmcdvgy7hme20v3xy5mkxcezea",
"admin": "cond:gov/rule/0000000000000002",
"title": "Dictatorship",
"electors": [
{
"weight": 1,
"weight": 10,
"address": "bech32:tiov15nuhg3l8ma2mdmcdvgy7hme20v3xy5mkxcezea"
}
]
}
],
"rules": [
{
"admin": "cond:foo/bar/0000000000000002",
"admin": "cond:gov/rule/0000000000000001",
"title": "fooo",
"voting_period": "1h",
"threshold": {
Expand All @@ -74,9 +74,23 @@
"electorate_id": 1
},
{
"admin": "4444444444444444444444444444444444444444",
"admin": "cond:gov/rule/0000000000000002",
"title": "barr",
"voting_period": "5s",
"voting_period": "10s",
"threshold": {
"numerator": 1,
"denominator": 2
},
"quorum": {
"numerator": 2,
"denominator": 3
},
"electorate_id": 2
},
{
"admin": "cond:gov/rule/0000000000000002",
"title": "frontend",
"voting_period": "10h",
"threshold": {
"numerator": 1,
"denominator": 2
Expand All @@ -89,18 +103,42 @@
}
]
},
"update_validators": {
"addresses": ["cond:gov/rule/0000000000000002"]
},
"escrow": [
{
"//name": "Guarantee Fund",
"amount": [
{
"ticker": "CASH",
"whole": 100000000000000
}
],
"arbiter": "cond:gov/rule/0000000000000002",
"//destination-name": "Reward Fund",
"destination": "cond:gov/rule/0000000000000002",
"source": "0000000000000000000000000000000000000000",
"timeout": "2999-12-31T00:00:00Z"
}
],
"conf": {
"cash": {
"minimal_fee": "0.01 CASH",
"collector_address": "0000000000000000000000000000000000000000"
},
"migration": {
"admin": "cond:multisig/usage/0000000000000001"
},
"username": {
"owner": "cond:gov/rule/0000000000000002",
"valid_username_name": "^[a-z0-9\\-_.]{3,64}$",
"valid_username_label": "^iov$"
}
},
"msgfee": [
{
"msg_path": "nft/username/issue",
"msg_path": "username/register_token",
"fee": "5 CASH"
}
],
Expand Down
13 changes: 13 additions & 0 deletions scripts/bnsd/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
command -v shellcheck > /dev/null && shellcheck "$0"

# get this files directory regardless of pwd when we run it
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ -n "${INIT_PROPOSALS:-}" ]; then
sleep 3
echo "Deploying proposals..."
node "${SCRIPT_DIR}/deploy_proposals.js"
echo "Done."
fi
4 changes: 3 additions & 1 deletion scripts/bnsd/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ command -v shellcheck > /dev/null && shellcheck "$0"
# Choose from https://hub.docker.com/r/iov1/tendermint/tags/
export BNSD_TM_VERSION=v0.31.5
# Choose from https://hub.docker.com/r/iov1/bnsd/tags/
export BNSD_VERSION=v0.19.0
export BNSD_VERSION=v0.21.0

# get this files directory regardless of pwd when we run it
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Expand All @@ -25,3 +25,5 @@ sleep 3
# for debug output
cat "$LOGS_FILE_TM"
cat "$LOGS_FILE_APP"

"${SCRIPT_DIR}"/init.sh
4 changes: 2 additions & 2 deletions src/actions/start/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { MultiChainSigner } from "@iov/multichain";

import { creditAmount, gasLimit, gasPrice, setFractionalDigits } from "../../cashflow";
import {
chainConnector,
codecDefaultFractionalDigits,
codecFromString,
codecImplementation,
createChainConnector,
} from "../../codec";
import * as constants from "../../constants";
import { logAccountsState, logSendJob } from "../../debugging";
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
}
const signer = new MultiChainSigner(profile);
console.log(`Connecting to blockchain ${blockchainBaseUrl} ...`);
const connection = (await signer.addChain(chainConnector(codec, blockchainBaseUrl))).connection;
const connection = (await signer.addChain(createChainConnector(codec, blockchainBaseUrl))).connection;

const connectedChainId = connection.chainId();
console.log(`Connected to network: ${connectedChainId}`);
Expand Down
16 changes: 8 additions & 8 deletions src/codec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainConnector, TxCodec } from "@iov/bcp";
import { bnsCodec, bnsConnector } from "@iov/bns";
import { ethereumCodec, ethereumConnector } from "@iov/ethereum";
import { liskCodec, liskConnector } from "@iov/lisk";
import { bnsCodec, createBnsConnector } from "@iov/bns";
import { createEthereumConnector, ethereumCodec } from "@iov/ethereum";
import { createLiskConnector, liskCodec } from "@iov/lisk";

export const enum Codec {
Bns,
Expand Down Expand Up @@ -31,18 +31,18 @@ export function codecImplementation(codec: Codec): TxCodec {
case Codec.Ethereum:
return ethereumCodec;
default:
throw new Error("No codec imlementation for this codec found");
throw new Error("No codec implementation for this codec found");
}
}

export function chainConnector(codec: Codec, url: string): ChainConnector {
export function createChainConnector(codec: Codec, url: string): ChainConnector {
switch (codec) {
case Codec.Bns:
return bnsConnector(url);
return createBnsConnector(url);
case Codec.Lisk:
return liskConnector(url);
return createLiskConnector(url);
case Codec.Ethereum:
return ethereumConnector(url, {});
return createEthereumConnector(url, {});
default:
throw new Error("No connector for this codec found");
}
Expand Down
Loading

0 comments on commit 0135e34

Please sign in to comment.