Merge pull request #90 from confio/upgrade-iov-core

Upgrade IOV Core to 2.0.2
This commit is contained in:
Simon Warta 2020-02-14 22:46:05 +01:00 committed by GitHub
commit 9aed3e1ac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 85 additions and 88 deletions

View File

@ -39,11 +39,11 @@
},
"dependencies": {
"@cosmwasm/sdk": "^0.0.3",
"@iov/bcp": "^2.0.0-alpha.7",
"@iov/crypto": "^2.0.0-alpha.7",
"@iov/encoding": "^2.0.0-alpha.7",
"@iov/stream": "^2.0.0-alpha.7",
"@iov/utils": "^2.0.0-alpha.7",
"@iov/bcp": "^2.0.2",
"@iov/crypto": "^2.0.2",
"@iov/encoding": "^2.0.2",
"@iov/stream": "^2.0.2",
"@iov/utils": "^2.0.2",
"@types/bn.js": "^4.11.6",
"bn.js": "^5.1.1",
"fast-deep-equal": "^3.1.1",
@ -51,6 +51,6 @@
"xstream": "^11.11.0"
},
"devDependencies": {
"@iov/keycontrol": "^2.0.0-alpha.7"
"@iov/keycontrol": "^2.0.2"
}
}

View File

@ -17,7 +17,6 @@ import { Bech32, Encoding } from "@iov/encoding";
import { HdPaths, Secp256k1HdWallet, UserProfile } from "@iov/keycontrol";
import { assert } from "@iov/utils";
import { CosmWasmCodec } from "./cosmwasmcodec";
import { CosmWasmConnection, TokenConfiguration } from "./cosmwasmconnection";
import * as testdata from "./testdata.spec";
@ -121,8 +120,7 @@ describe("CosmWasmConnection", () => {
it("displays the chain ID", async () => {
pendingWithoutCosmos();
const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig);
const chainId = connection.chainId();
expect(chainId).toEqual(defaultChainId);
expect(connection.chainId).toEqual(defaultChainId);
connection.disconnect();
});
});
@ -282,12 +280,11 @@ describe("CosmWasmConnection", () => {
describe("integration tests", () => {
it("can post and get a transaction", async () => {
pendingWithoutCosmos();
const codec = new CosmWasmCodec(defaultPrefix, defaultConfig.bankTokens);
const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig);
const profile = new UserProfile();
const wallet = profile.addWallet(Secp256k1HdWallet.fromMnemonic(faucetMnemonic));
const faucet = await profile.createIdentity(wallet.id, defaultChainId, faucetPath);
const faucetAddress = codec.identityToAddress(faucet);
const faucetAddress = connection.codec.identityToAddress(faucet);
const unsigned = await connection.withDefaultFee<SendTransaction>({
kind: "bcp/send",
@ -302,8 +299,8 @@ describe("CosmWasmConnection", () => {
},
});
const nonce = await connection.getNonce({ address: faucetAddress });
const signed = await profile.signTransaction(faucet, unsigned, codec, nonce);
const postableBytes = codec.bytesToPost(signed);
const signed = await profile.signTransaction(faucet, unsigned, connection.codec, nonce);
const postableBytes = connection.codec.bytesToPost(signed);
const response = await connection.postTx(postableBytes);
const { transactionId } = response;
const blockInfo = await response.blockInfo.waitFor(info => !isBlockInfoPending(info));
@ -335,12 +332,11 @@ describe("CosmWasmConnection", () => {
it("can post and search for a transaction", async () => {
pendingWithoutCosmos();
const codec = new CosmWasmCodec(defaultPrefix, defaultConfig.bankTokens);
const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig);
const profile = new UserProfile();
const wallet = profile.addWallet(Secp256k1HdWallet.fromMnemonic(faucetMnemonic));
const faucet = await profile.createIdentity(wallet.id, defaultChainId, faucetPath);
const faucetAddress = codec.identityToAddress(faucet);
const faucetAddress = connection.codec.identityToAddress(faucet);
const unsigned = await connection.withDefaultFee<SendTransaction>({
kind: "bcp/send",
@ -355,8 +351,8 @@ describe("CosmWasmConnection", () => {
},
});
const nonce = await connection.getNonce({ address: faucetAddress });
const signed = await profile.signTransaction(faucet, unsigned, codec, nonce);
const postableBytes = codec.bytesToPost(signed);
const signed = await profile.signTransaction(faucet, unsigned, connection.codec, nonce);
const postableBytes = connection.codec.bytesToPost(signed);
const response = await connection.postTx(postableBytes);
const { transactionId } = response;
const blockInfo = await response.blockInfo.waitFor(info => !isBlockInfoPending(info));
@ -426,12 +422,11 @@ describe("CosmWasmConnection", () => {
it("can send ERC20 tokens", async () => {
pendingWithoutCosmos();
const codec = new CosmWasmCodec(defaultPrefix, defaultConfig.bankTokens, defaultConfig.erc20Tokens);
const connection = await CosmWasmConnection.establish(httpUrl, defaultPrefix, defaultConfig);
const profile = new UserProfile();
const wallet = profile.addWallet(Secp256k1HdWallet.fromMnemonic(faucetMnemonic));
const faucet = await profile.createIdentity(wallet.id, defaultChainId, faucetPath);
const faucetAddress = codec.identityToAddress(faucet);
const faucetAddress = connection.codec.identityToAddress(faucet);
const recipient = makeRandomAddress();
const unsigned = await connection.withDefaultFee<SendTransaction>({
@ -447,8 +442,8 @@ describe("CosmWasmConnection", () => {
},
});
const nonce = await connection.getNonce({ address: faucetAddress });
const signed = await profile.signTransaction(faucet, unsigned, codec, nonce);
const postableBytes = codec.bytesToPost(signed);
const signed = await profile.signTransaction(faucet, unsigned, connection.codec, nonce);
const postableBytes = connection.codec.bytesToPost(signed);
const response = await connection.postTx(postableBytes);
const blockInfo = await response.blockInfo.waitFor(info => !isBlockInfoPending(info));
expect(blockInfo.state).toEqual(TransactionState.Succeeded);

View File

@ -27,6 +27,7 @@ import {
TransactionId,
TransactionQuery,
TransactionState,
TxCodec,
UnsignedTransaction,
} from "@iov/bcp";
import { Encoding, Uint53 } from "@iov/encoding";
@ -38,16 +39,13 @@ import { Stream } from "xstream";
import { decodeCosmosPubkey, pubkeyToAddress } from "./address";
import { Caip5 } from "./caip5";
import { CosmWasmCodec } from "./cosmwasmcodec";
import { decodeAmount, parseTxsResponseSigned, parseTxsResponseUnsigned } from "./decode";
import { buildSignedTx } from "./encode";
import { accountToNonce, BankToken, Erc20Token } from "./types";
const { fromAscii } = Encoding;
interface ChainData {
readonly chainId: ChainId;
}
// poll every 0.5 seconds (block time 1s)
const defaultPollInterval = 500;
@ -75,15 +73,17 @@ export class CosmWasmConnection implements BlockchainConnection {
return new CosmWasmConnection(restClient, cosmWasmClient, chainData, addressPrefix, tokens);
}
private static async initialize(cosmWasmClient: CosmWasmClient): Promise<ChainData> {
private static async initialize(cosmWasmClient: CosmWasmClient): Promise<ChainId> {
const rawChainId = await cosmWasmClient.chainId();
return { chainId: Caip5.encode(rawChainId) };
return Caip5.encode(rawChainId);
}
public readonly chainId: ChainId;
public readonly codec: TxCodec;
/** @deprecated everything we use from RestClient should be available in CosmWasmClient */
private readonly restClient: RestClient;
private readonly cosmWasmClient: CosmWasmClient;
private readonly chainData: ChainData;
private readonly addressPrefix: CosmosAddressBech32Prefix;
private readonly bankTokens: readonly BankToken[];
private readonly erc20Tokens: readonly Erc20Token[];
@ -95,14 +95,15 @@ export class CosmWasmConnection implements BlockchainConnection {
private constructor(
restClient: RestClient,
cosmWasmClient: CosmWasmClient,
chainData: ChainData,
chainId: ChainId,
addressPrefix: CosmosAddressBech32Prefix,
tokens: TokenConfiguration,
) {
// tslint:disable-next-line: deprecation
this.restClient = restClient;
this.cosmWasmClient = cosmWasmClient;
this.chainData = chainData;
this.chainId = chainId;
this.codec = new CosmWasmCodec(addressPrefix, tokens.bankTokens, tokens.erc20Tokens);
this.addressPrefix = addressPrefix;
this.bankTokens = tokens.bankTokens;
this.feeToken = this.bankTokens.find(() => true);
@ -121,10 +122,6 @@ export class CosmWasmConnection implements BlockchainConnection {
return;
}
public chainId(): ChainId {
return this.chainData.chainId;
}
public async height(): Promise<number> {
// tslint:disable-next-line: deprecation
const { block } = await this.restClient.blocksLatest();
@ -357,8 +354,7 @@ export class CosmWasmConnection implements BlockchainConnection {
private parseAndPopulateTxResponseUnsigned(
response: TxsResponse,
): ConfirmedTransaction<UnsignedTransaction> | FailedTransaction {
const chainId = this.chainId();
return parseTxsResponseUnsigned(chainId, parseInt(response.height, 10), response, this.bankTokens);
return parseTxsResponseUnsigned(this.chainId, parseInt(response.height, 10), response, this.bankTokens);
}
private async parseAndPopulateTxResponseSigned(
@ -369,7 +365,12 @@ export class CosmWasmConnection implements BlockchainConnection {
// TODO: fix
const nonce = -1 as Nonce;
const chainId = this.chainId();
return parseTxsResponseSigned(chainId, parseInt(response.height, 10), nonce, response, this.bankTokens);
return parseTxsResponseSigned(
this.chainId,
parseInt(response.height, 10),
nonce,
response,
this.bankTokens,
);
}
}

View File

@ -19,6 +19,7 @@ import {
TokenTicker,
TransactionId,
TransactionQuery,
TxCodec,
UnsignedTransaction,
} from "@iov/bcp";
import { Stream } from "xstream";
@ -44,10 +45,11 @@ export declare class CosmWasmConnection implements BlockchainConnection {
tokens: TokenConfiguration,
): Promise<CosmWasmConnection>;
private static initialize;
readonly chainId: ChainId;
readonly codec: TxCodec;
/** @deprecated everything we use from RestClient should be available in CosmWasmClient */
private readonly restClient;
private readonly cosmWasmClient;
private readonly chainData;
private readonly addressPrefix;
private readonly bankTokens;
private readonly erc20Tokens;
@ -55,7 +57,6 @@ export declare class CosmWasmConnection implements BlockchainConnection {
private readonly supportedTokens;
private constructor();
disconnect(): void;
chainId(): ChainId;
height(): Promise<number>;
getToken(searchTicker: TokenTicker): Promise<Token | undefined>;
getAllTokens(): Promise<readonly Token[]>;

View File

@ -34,9 +34,9 @@
],
"dependencies": {
"@cosmwasm/sdk": "^0.0.3",
"@iov/crypto": "^2.0.0-alpha.7",
"@iov/encoding": "^2.0.0-alpha.7",
"@iov/utils": "^2.0.0-alpha.7",
"@iov/crypto": "^2.0.2",
"@iov/encoding": "^2.0.2",
"@iov/utils": "^2.0.2",
"argparse": "^1.0.10",
"babylon": "^6.18.0",
"colors": "^1.3.3",

View File

@ -36,11 +36,11 @@
},
"dependencies": {
"@cosmwasm/bcp": "^0.0.3",
"@iov/bcp": "^2.0.0-alpha.7",
"@iov/crypto": "^2.0.0-alpha.7",
"@iov/encoding": "^2.0.0-alpha.7",
"@iov/keycontrol": "^2.0.0-alpha.7",
"@iov/utils": "^2.0.0-alpha.7",
"@iov/bcp": "^2.0.2",
"@iov/crypto": "^2.0.2",
"@iov/encoding": "^2.0.2",
"@iov/keycontrol": "^2.0.2",
"@iov/utils": "^2.0.2",
"@koa/cors": "^3.0.0",
"axios": "^0.19.0",
"fast-deep-equal": "^3.1.1",

View File

@ -23,13 +23,13 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
);
console.info(`Connecting to blockchain ${blockchainBaseUrl} ...`);
const connection = await connector.establishConnection();
console.info(`Connected to network: ${connection.chainId()}`);
console.info(`Connected to network: ${connection.chainId}`);
// Profile
if (!constants.mnemonic) throw new Error("The FAUCET_MNEMONIC environment variable is not set");
const [profile] = await createUserProfile(
constants.mnemonic,
connection.chainId(),
connection.chainId,
constants.concurrency,
true,
);
@ -52,6 +52,6 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
setInterval(async () => faucet.refill(), 60_000); // ever 60 seconds
console.info("Creating webserver ...");
const server = new Webserver(faucet, { nodeUrl: blockchainBaseUrl, chainId: connection.chainId() });
const server = new Webserver(faucet, { nodeUrl: blockchainBaseUrl, chainId: connection.chainId });
server.start(constants.port);
}

View File

@ -54,7 +54,7 @@ export class Faucet {
public async send(job: SendJob): Promise<void> {
const sendWithFee = await this.connection.withDefaultFee<SendTransaction>({
kind: "bcp/send",
chainId: this.connection.chainId(),
chainId: this.connection.chainId,
sender: this.codec.identityToAddress(job.sender),
senderPubkey: job.sender.pubkey,
recipient: job.recipient,
@ -113,7 +113,7 @@ export class Faucet {
public async refill(): Promise<void> {
if (this.logging) {
console.info(`Connected to network: ${this.connection.chainId()}`);
console.info(`Connected to network: ${this.connection.chainId}`);
console.info(`Tokens on network: ${(await this.loadTokenTickers()).join(", ")}`);
}

View File

@ -38,9 +38,9 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@iov/crypto": "^2.0.0-alpha.7",
"@iov/encoding": "^2.0.0-alpha.7",
"@iov/utils": "^2.0.0-alpha.7",
"@iov/crypto": "^2.0.2",
"@iov/encoding": "^2.0.2",
"@iov/utils": "^2.0.2",
"axios": "^0.19.0"
},
"devDependencies": {

View File

@ -92,23 +92,23 @@
unique-filename "^1.1.1"
which "^1.3.1"
"@iov/bcp@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/bcp/-/bcp-2.0.0-alpha.7.tgz#37c0d54d270ee78429f3fecb94e19001fea15c5b"
integrity sha512-/cR+yOjpuru6LudlrxsUf1RkekNgRmYBQ5ft43XAcYBWzwLdIukAFgIJ9xMiO5bl3ZaDACV/xx699WOeTXI+rA==
"@iov/bcp@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@iov/bcp/-/bcp-2.0.2.tgz#d63a996e0c2c7eff218f3dfca44dbcfaaf80ed0b"
integrity sha512-7uvDXh74CbU+xpIcLQDS0qNbvD1YDQXI+YlVMWMLQdnltAxGetKPA9vDI/rcl4rjYXkGbXWjXvFYBxftj5S5QQ==
dependencies:
"@iov/crypto" "^2.0.0-alpha.7"
"@iov/encoding" "^2.0.0-alpha.7"
"@iov/stream" "^2.0.0-alpha.7"
"@iov/crypto" "^2.0.2"
"@iov/encoding" "^2.0.2"
"@iov/stream" "^2.0.2"
type-tagger "^1.0.0"
xstream "^11.10.0"
"@iov/crypto@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/crypto/-/crypto-2.0.0-alpha.7.tgz#5cb24dbc3cdd344bf782039f1fe6d55975d171f6"
integrity sha512-xBnRNZhIi1czBg0iMRQAJRYrPvAzUJtQBW7HjWR8JnEWHNtK6cG2Z0FExngWPa1i4AeSXTUd46mdAWWToOpojw==
"@iov/crypto@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@iov/crypto/-/crypto-2.0.2.tgz#22da5ca5c76e2f8e1a8e592195aa754584e1c1d6"
integrity sha512-UeBleADtU4RMPGjo5RmF+vAW0krV+TZtJetbY6i05J/cRWElKx/FxLvChRO4HciyE7KBKMTZmt+erKzpr/D9ZA==
dependencies:
"@iov/encoding" "^2.0.0-alpha.7"
"@iov/encoding" "^2.0.2"
bip39 "^3.0.2"
bn.js "^4.11.8"
elliptic "^6.4.0"
@ -120,25 +120,25 @@
type-tagger "^1.0.0"
unorm "^1.5.0"
"@iov/encoding@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/encoding/-/encoding-2.0.0-alpha.7.tgz#a8c50facbb4203df8fa06c6915aeb5fd5d55c98d"
integrity sha512-iUvqYQo63mr7jfLA1KGOimHA7cZFFv0Eba5ruDomvDRHcYHvtpZWDsFZsdvPlNWThhMyQV/ZT26qpJmk71VA6Q==
"@iov/encoding@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@iov/encoding/-/encoding-2.0.2.tgz#e83330aa8dcf0de422a1599a6d08653f74275f8e"
integrity sha512-IlqBGZz4iOz6QjYJB0rCVCiaZojOJpSjapT8575M8BZ7K40jLVe1DaSxGFF0G8orY9I9Kc/7fGMvr0a2wR3HAw==
dependencies:
base64-js "^1.3.0"
bech32 "^1.1.3"
bn.js "^4.11.8"
readonly-date "^1.0.0"
"@iov/keycontrol@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/keycontrol/-/keycontrol-2.0.0-alpha.7.tgz#d115a1b536664afb64b40a6db87aaf19f8d07afd"
integrity sha512-gIps4yXw9QD7Gp8H8SV9AA1MDs5m8lnWZJ1rz2pQsuCuFfziDJP6MJ90SdlzYDbVUFA+RXJBn502aEgfO1qJcA==
"@iov/keycontrol@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@iov/keycontrol/-/keycontrol-2.0.2.tgz#10113d5d8223912f6325f1fc68746852fd1dec23"
integrity sha512-XubfYpNFr/xwGQC7e0VFc9oug4S5/muzIgQJRDxGcGNyE1YhQbfAzYLfxC7Th0Dq5rRui3MKWhLehYydqNxvvw==
dependencies:
"@iov/bcp" "^2.0.0-alpha.7"
"@iov/crypto" "^2.0.0-alpha.7"
"@iov/encoding" "^2.0.0-alpha.7"
"@iov/stream" "^2.0.0-alpha.7"
"@iov/bcp" "^2.0.2"
"@iov/crypto" "^2.0.2"
"@iov/encoding" "^2.0.2"
"@iov/stream" "^2.0.2"
"@types/abstract-leveldown" "^5.0.1"
"@types/levelup" "^3.1.0"
"@types/node" "^10.12.18"
@ -150,17 +150,17 @@
type-tagger "^1.0.0"
xstream "^11.10.0"
"@iov/stream@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/stream/-/stream-2.0.0-alpha.7.tgz#212c3f684f592ec04ac43e166183d946a49b895c"
integrity sha512-3hzbSCTE7hGqdmKkmiWYBH71bzANYMyo4NJCBwBUVxyeEbts7AibaBRivD78n6TOC04KolgqZpCMichRI1Hylw==
"@iov/stream@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@iov/stream/-/stream-2.0.2.tgz#270805d0c03fb05664910384ad94b1e4d8d1d08e"
integrity sha512-XooKTuWIc1E3weYT77a4dd/hsO7Yo3roQtBj8VSkqRg3TZnhy+SBBCWu77nlUnAYZ/KzXHKCRg0iUgazuy8Y4w==
dependencies:
xstream "^11.10.0"
"@iov/utils@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/utils/-/utils-2.0.0-alpha.7.tgz#af9aebcb9e221e53cf62c5511f007c65d95f5c0c"
integrity sha512-myWATqmlCFZ/jSrsBQlyn+6D2ViAscZVAqBAw38kbIfv3TiKTjWb2RqhlNDnlVgt3uD0ZtQFyY9hkRMCwfIk+w==
"@iov/utils@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@iov/utils/-/utils-2.0.2.tgz#3527f376d26100e07ac823bf87bebd0f24680d1c"
integrity sha512-4D8MEvTcFc/DVy5q25vHxRItmgJyeX85dixMH+MxdKr+yy71h3sYk+sVBEIn70uqGP7VqAJkGOPNFs08/XYELw==
"@koa/cors@^3.0.0":
version "3.0.0"