Merge branch '0.22'

This commit is contained in:
Simon Warta 2020-08-17 13:59:36 +02:00
commit f5cc67b948
38 changed files with 199 additions and 64 deletions

View File

@ -17,6 +17,13 @@
functions `isBroadcastTxFailure`, `isBroadcastTxSuccess` and
`assertIsBroadcastTxSuccess`.
## 0.22.2 (2020-08-11)
- @cosmjs/faucet: Log errors for failed send transactions.
- @cosmjs/faucet: Add config variable `FAUCET_MEMO`.
- @cosmjs/faucet: Add config variables `FAUCET_FEE` and `FAUCET_GAS`.
- @cosmjs/launchpad: Add `parseCoins` helper.
## 0.22.1 (2020-08-11)
- @cosmjs/cli: Import `encodeAminoPubkey`, `encodeBech32Pubkey`,

View File

@ -1,5 +1,5 @@
{
"version": "0.22.1",
"version": "0.22.2",
"useWorkspaces": true,
"npmClient": "yarn"
}

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/cli",
"version": "0.22.1",
"version": "0.22.2",
"description": "Command line interface",
"contributors": [
"IOV SAS <admin@iov.one>",
@ -40,12 +40,12 @@
"!**/testdata/"
],
"dependencies": {
"@cosmjs/cosmwasm": "^0.22.1",
"@cosmjs/crypto": "^0.22.1",
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/launchpad": "^0.22.1",
"@cosmjs/math": "^0.22.1",
"@cosmjs/utils": "^0.22.1",
"@cosmjs/cosmwasm": "^0.22.2",
"@cosmjs/crypto": "^0.22.2",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/launchpad": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"axios": "^0.19.2",
"babylon": "^6.18.0",
"colors": "^1.3.3",

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/cosmwasm",
"version": "0.22.1",
"version": "0.22.2",
"description": "CosmWasm SDK",
"author": "Ethan Frey <ethanfrey@users.noreply.github.com>",
"license": "Apache-2.0",
@ -40,11 +40,11 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@cosmjs/crypto": "^0.22.1",
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/launchpad": "^0.22.1",
"@cosmjs/math": "^0.22.1",
"@cosmjs/utils": "^0.22.1",
"@cosmjs/crypto": "^0.22.2",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/launchpad": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"axios": "^0.19.0",
"pako": "^1.0.11"
},

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/crypto",
"version": "0.22.1",
"version": "0.22.2",
"description": "Cryptography resources for blockchain projects",
"contributors": [
"IOV SAS <admin@iov.one>",
@ -45,9 +45,9 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/math": "^0.22.1",
"@cosmjs/utils": "^0.22.1",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"bip39": "^3.0.2",
"bn.js": "^4.11.8",
"elliptic": "^6.5.3",

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/encoding",
"version": "0.22.1",
"version": "0.22.2",
"description": "Encoding helpers for blockchain projects",
"contributors": [
"IOV SAS <admin@iov.one>"

View File

@ -46,6 +46,10 @@ Environment variables
FAUCET_CONCURRENCY Number of distributor accounts. Defaults to 5.
FAUCET_PORT Port of the webserver. Defaults to 8000.
FAUCET_MEMO Memo for send transactions. Defaults to unset.
FAUCET_FEE Fee for send transactions as a comma separated list,
e.g. "200ushell,30ureef". Defaults to "2000ucosm".
FAUCET_GAS Gas for send transactions. Defaults to 80000.
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
faucet HD accounts
FAUCET_ADDRESS_PREFIX The bech32 address prefix. Defaults to "cosmos".

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/faucet",
"version": "0.22.1",
"version": "0.22.2",
"description": "The faucet",
"author": "Ethan Frey <ethanfrey@users.noreply.github.com>",
"license": "Apache-2.0",
@ -37,11 +37,11 @@
"start-coralnet": "FAUCET_ADDRESS_PREFIX=coral FAUCET_TOKENS=\"SHELL=10^6ushell, REEF=10^6ureef\" FAUCET_CREDIT_AMOUNT_SHELL=10 FAUCET_CREDIT_AMOUNT_REEF=2 FAUCET_CONCURRENCY=3 FAUCET_MNEMONIC=\"economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone\" ./bin/cosmwasm-faucet start \"https://lcd.coralnet.cosmwasm.com\""
},
"dependencies": {
"@cosmjs/crypto": "^0.22.1",
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/launchpad": "^0.22.1",
"@cosmjs/math": "^0.22.1",
"@cosmjs/utils": "^0.22.1",
"@cosmjs/crypto": "^0.22.2",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/launchpad": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"@koa/cors": "^3.0.0",
"koa": "^2.11.0",
"koa-bodyparser": "^4.2.1"

View File

@ -19,6 +19,10 @@ Environment variables
FAUCET_CONCURRENCY Number of distributor accounts. Defaults to 5.
FAUCET_PORT Port of the webserver. Defaults to 8000.
FAUCET_MEMO Memo for send transactions. Defaults to unset.
FAUCET_FEE Fee for send transactions as a comma separated list,
e.g. "200ushell,30ureef". Defaults to "2000ucosm".
FAUCET_GAS Gas for send transactions. Defaults to 80000.
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
faucet HD accounts
FAUCET_ADDRESS_PREFIX The bech32 address prefix. Defaults to "cosmos".

View File

@ -1,7 +1,12 @@
import { Coin, parseCoins } from "@cosmjs/launchpad";
import { TokenConfiguration } from "./tokenmanager";
import { parseBankTokens } from "./tokens";
export const binaryName = "cosmwasm-faucet";
export const memo: string | undefined = process.env.FAUCET_MEMO;
export const fee: readonly Coin[] = parseCoins(process.env.FAUCET_FEE || "2000ucosm");
export const gas: string = process.env.FAUCET_GAS || "80000";
export const concurrency: number = Number.parseInt(process.env.FAUCET_CONCURRENCY || "", 10) || 5;
export const port: number = Number.parseInt(process.env.FAUCET_PORT || "", 10) || 8000;
export const mnemonic: string | undefined = process.env.FAUCET_MNEMONIC;

View File

@ -1,6 +1,13 @@
import { CosmosClient, OfflineSigner, SigningCosmosClient } from "@cosmjs/launchpad";
import {
assertIsBroadcastTxSuccess,
CosmosClient,
FeeTable,
OfflineSigner,
SigningCosmosClient,
} from "@cosmjs/launchpad";
import { sleep } from "@cosmjs/utils";
import * as constants from "./constants";
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
import { createWallets } from "./profile";
import { TokenConfiguration, TokenManager } from "./tokenmanager";
@ -50,10 +57,17 @@ export class Faucet {
this.holderAddress = wallets[0][0];
this.distributorAddresses = wallets.slice(1).map((pair) => pair[0]);
const fees: Partial<FeeTable> = {
send: {
amount: constants.fee,
gas: constants.gas,
},
};
// we need one client per sender
const clients: { [senderAddress: string]: SigningCosmosClient } = {};
for (const [senderAddress, wallet] of wallets) {
clients[senderAddress] = new SigningCosmosClient(apiUrl, senderAddress, wallet);
clients[senderAddress] = new SigningCosmosClient(apiUrl, senderAddress, wallet, fees);
}
this.clients = clients;
this.logging = logging;
@ -75,9 +89,11 @@ export class Faucet {
/**
* Creates and broadcasts a send transaction. Then waits until the transaction is in a block.
* Throws an error if the transaction failed.
*/
public async send(job: SendJob): Promise<void> {
await this.clients[job.sender].sendTokens(job.recipient, [job.amount], "Make love, not war");
const result = await this.clients[job.sender].sendTokens(job.recipient, [job.amount], constants.memo);
assertIsBroadcastTxSuccess(result);
}
/** Use one of the distributor accounts to send tokend to user */
@ -155,7 +171,12 @@ export class Faucet {
if (jobs.length > 0) {
for (const job of jobs) {
if (this.logging) logSendJob(job, this.tokenConfig);
await this.send(job);
// don't crash faucet when one send fails
try {
await this.send(job);
} catch (error) {
console.error(error);
}
await sleep(75);
}

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/json-rpc",
"version": "0.22.1",
"version": "0.22.2",
"description": "Framework for implementing a JSON-RPC 2.0 API",
"contributors": [
"IOV SAS <admin@iov.one>",
@ -46,7 +46,7 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@cosmjs/stream": "^0.22.1",
"@cosmjs/stream": "^0.22.2",
"xstream": "^11.10.0"
}
}

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/launchpad",
"version": "0.22.1",
"version": "0.22.2",
"description": "A client library for the Cosmos SDK 0.37 (cosmoshub-3), 0.38 and 0.39 (Launchpad)",
"contributors": [
"Ethan Frey <ethanfrey@users.noreply.github.com>",
@ -43,10 +43,10 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@cosmjs/crypto": "^0.22.1",
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/math": "^0.22.1",
"@cosmjs/utils": "^0.22.1",
"@cosmjs/crypto": "^0.22.2",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"axios": "^0.19.0"
},
"devDependencies": {

View File

@ -1,4 +1,4 @@
import { coin, coins } from "./coins";
import { coin, coins, parseCoins } from "./coins";
describe("coins", () => {
describe("coin", () => {
@ -32,4 +32,76 @@ describe("coins", () => {
expect(coins(123, "utoken")).toEqual([{ amount: "123", denom: "utoken" }]);
});
});
describe("parseCoins", () => {
it("works for empty", () => {
expect(parseCoins("")).toEqual([]);
});
it("works for one element", () => {
expect(parseCoins("7643ureef")).toEqual([
{
amount: "7643",
denom: "ureef",
},
]);
});
it("works for two", () => {
expect(parseCoins("819966000ucosm,700000000ustake")).toEqual([
{
amount: "819966000",
denom: "ucosm",
},
{
amount: "700000000",
denom: "ustake",
},
]);
});
it("ignores empty elements", () => {
// start
expect(parseCoins(",819966000ucosm,700000000ustake")).toEqual([
{
amount: "819966000",
denom: "ucosm",
},
{
amount: "700000000",
denom: "ustake",
},
]);
// middle
expect(parseCoins("819966000ucosm,,700000000ustake")).toEqual([
{
amount: "819966000",
denom: "ucosm",
},
{
amount: "700000000",
denom: "ustake",
},
]);
// end
expect(parseCoins("819966000ucosm,700000000ustake,")).toEqual([
{
amount: "819966000",
denom: "ucosm",
},
{
amount: "700000000",
denom: "ustake",
},
]);
});
it("throws for invalid inputs", () => {
// denom missing
expect(() => parseCoins("3456")).toThrowError(/invalid coin string/i);
// amount missing
expect(() => parseCoins("ucosm")).toThrowError(/invalid coin string/i);
});
});
});

View File

@ -1,4 +1,4 @@
import { Uint53 } from "@cosmjs/math";
import { Uint53, Uint64 } from "@cosmjs/math";
export interface Coin {
readonly denom: string;
@ -14,3 +14,21 @@ export function coin(amount: number, denom: string): Coin {
export function coins(amount: number, denom: string): Coin[] {
return [coin(amount, denom)];
}
/**
* Takes a coins list like "819966000ucosm,700000000ustake" and parses it
*/
export function parseCoins(input: string): Coin[] {
return input
.replace(/\s/g, "")
.split(",")
.filter(Boolean)
.map((part) => {
const match = part.match(/^([0-9]+)([a-zA-Z]+)/);
if (!match) throw new Error("Got an invalid coin string");
return {
amount: Uint64.fromString(match[1]).toString(),
denom: match[2],
};
});
}

View File

@ -2,7 +2,7 @@ import * as logs from "./logs";
export { logs };
export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address";
export { Coin, coin, coins } from "./coins";
export { Coin, coin, coins, parseCoins } from "./coins";
export {
Account,

View File

@ -6,3 +6,7 @@ export interface Coin {
export declare function coin(amount: number, denom: string): Coin;
/** Creates a list of coins with one element */
export declare function coins(amount: number, denom: string): Coin[];
/**
* Takes a coins list like "819966000ucosm,700000000ustake" and parses it
*/
export declare function parseCoins(input: string): Coin[];

View File

@ -1,7 +1,7 @@
import * as logs from "./logs";
export { logs };
export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address";
export { Coin, coin, coins } from "./coins";
export { Coin, coin, coins, parseCoins } from "./coins";
export {
Account,
assertIsBroadcastTxSuccess,

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/math",
"version": "0.22.1",
"version": "0.22.2",
"description": "Math helpers for blockchain projects",
"contributors": [
"IOV SAS <admin@iov.one>"

View File

View File

@ -1,7 +1,7 @@
{
"name": "@cosmjs/proto-signing",
"private": true,
"version": "0.22.1",
"version": "0.22.2",
"description": "Utilities for protobuf based signing (Cosmos SDK 0.40+)",
"contributors": [
"Will Clark <willclarktech@users.noreply.github.com>",
@ -49,8 +49,8 @@
"protobufjs": "~6.10.0"
},
"devDependencies": {
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/launchpad": "^0.22.1",
"@cosmjs/utils": "^0.22.1"
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/launchpad": "^0.22.2",
"@cosmjs/utils": "^0.22.2"
}
}

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/socket",
"version": "0.22.1",
"version": "0.22.2",
"description": "Utility functions for working with WebSockets",
"contributors": [
"IOV SAS <admin@iov.one>",
@ -46,7 +46,7 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@cosmjs/stream": "^0.22.1",
"@cosmjs/stream": "^0.22.2",
"isomorphic-ws": "^4.0.1",
"ws": "^6.2.0",
"xstream": "^11.10.0"

View File

@ -1,7 +1,7 @@
{
"name": "@cosmjs/stargate",
"private": true,
"version": "0.22.1",
"version": "0.22.2",
"description": "Utilities for Cosmos SDK 0.40",
"contributors": [
"Simon Warta <webmaster128@users.noreply.github.com>"
@ -45,12 +45,12 @@
"postdefine-proto": "prettier --write \"src/codec/generated/codecimpl.*\""
},
"dependencies": {
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/launchpad": "^0.22.1",
"@cosmjs/math": "^0.22.1",
"@cosmjs/proto-signing": "^0.22.1",
"@cosmjs/tendermint-rpc": "^0.22.1",
"@cosmjs/utils": "^0.22.1",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/launchpad": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/proto-signing": "^0.22.2",
"@cosmjs/tendermint-rpc": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"protobufjs": "~6.10.0"
}
}

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/stream",
"version": "0.22.1",
"version": "0.22.2",
"description": "Utility functions for producing and consuming streams",
"contributors": [
"IOV SAS <admin@iov.one>",

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/tendermint-rpc",
"version": "0.22.1",
"version": "0.22.2",
"description": "Tendermint RPC clients",
"contributors": [
"IOV SAS <admin@iov.one>",
@ -46,18 +46,18 @@
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"
},
"dependencies": {
"@cosmjs/crypto": "^0.22.1",
"@cosmjs/encoding": "^0.22.1",
"@cosmjs/json-rpc": "^0.22.1",
"@cosmjs/math": "^0.22.1",
"@cosmjs/socket": "^0.22.1",
"@cosmjs/stream": "^0.22.1",
"@cosmjs/crypto": "^0.22.2",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/json-rpc": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/socket": "^0.22.2",
"@cosmjs/stream": "^0.22.2",
"axios": "^0.19.0",
"readonly-date": "^1.0.0",
"type-tagger": "^1.0.0",
"xstream": "^11.10.0"
},
"devDependencies": {
"@cosmjs/utils": "^0.22.1"
"@cosmjs/utils": "^0.22.2"
}
}

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/utils",
"version": "0.22.1",
"version": "0.22.2",
"description": "Utility tools, primarily for testing code",
"contributors": [
"IOV SAS <admin@iov.one>"