Merge branch '0.22'

This commit is contained in:
Simon Warta 2020-09-17 15:07:15 +02:00
commit c7e828bb79
33 changed files with 130 additions and 58 deletions

View File

@ -55,6 +55,10 @@
- @cosmjs/utils: Add `assertDefined`.
- @cosmjs/faucet: Rename binary from `cosmwasm-faucet` to `cosmos-faucet`.
## 0.22.3 (2020-09-15)
- @cosmjs/math: Add `Decimal.minus`.
## 0.22.2 (2020-08-11)
- @cosmjs/faucet: Log errors for failed send transactions.

View File

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

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/cli",
"version": "0.22.2",
"version": "0.22.3",
"description": "Command line interface",
"contributors": [
"IOV SAS <admin@iov.one>",
@ -40,12 +40,12 @@
"!**/testdata/"
],
"dependencies": {
"@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",
"@cosmjs/cosmwasm": "^0.22.3",
"@cosmjs/crypto": "^0.22.3",
"@cosmjs/encoding": "^0.22.3",
"@cosmjs/launchpad": "^0.22.3",
"@cosmjs/math": "^0.22.3",
"@cosmjs/utils": "^0.22.3",
"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.2",
"version": "0.22.3",
"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.2",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/launchpad": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"@cosmjs/crypto": "^0.22.3",
"@cosmjs/encoding": "^0.22.3",
"@cosmjs/launchpad": "^0.22.3",
"@cosmjs/math": "^0.22.3",
"@cosmjs/utils": "^0.22.3",
"axios": "^0.19.0",
"pako": "^1.0.11"
},

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/crypto",
"version": "0.22.2",
"version": "0.22.3",
"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.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"@cosmjs/encoding": "^0.22.3",
"@cosmjs/math": "^0.22.3",
"@cosmjs/utils": "^0.22.3",
"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.2",
"version": "0.22.3",
"description": "Encoding helpers for blockchain projects",
"contributors": [
"IOV SAS <admin@iov.one>"

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/faucet",
"version": "0.22.2",
"version": "0.22.3",
"description": "The faucet",
"contributors": [
"Ethan Frey <ethanfrey@users.noreply.github.com>",
@ -40,11 +40,11 @@
"start-coralnet": "FAUCET_ADDRESS_PREFIX=coral FAUCET_TOKENS=\"SHELL=10^6ushell, REEF=10^6ureef\" FAUCET_CREDIT_AMOUNT_USHELL=10000000 FAUCET_CREDIT_AMOUNT_UREEF=2000000 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/cosmos-faucet start \"https://lcd.coralnet.cosmwasm.com\""
},
"dependencies": {
"@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",
"@cosmjs/crypto": "^0.22.3",
"@cosmjs/encoding": "^0.22.3",
"@cosmjs/launchpad": "^0.22.3",
"@cosmjs/math": "^0.22.3",
"@cosmjs/utils": "^0.22.3",
"@koa/cors": "^3.0.0",
"koa": "^2.11.0",
"koa-bodyparser": "^4.2.1"

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/json-rpc",
"version": "0.22.2",
"version": "0.22.3",
"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.2",
"@cosmjs/stream": "^0.22.3",
"xstream": "^11.10.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/launchpad-ledger",
"version": "0.22.2",
"version": "0.22.3",
"description": "A library for interacting with the Cosmos Launchpad Ledger Nano App",
"contributors": [
"Will Clark <willclarktech@users.noreply.github.com>"

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/launchpad",
"version": "0.22.2",
"version": "0.22.3",
"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.2",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"@cosmjs/crypto": "^0.22.3",
"@cosmjs/encoding": "^0.22.3",
"@cosmjs/math": "^0.22.3",
"@cosmjs/utils": "^0.22.3",
"axios": "^0.19.0"
},
"devDependencies": {

View File

View File

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

View File

@ -212,6 +212,54 @@ describe("Decimal", () => {
});
});
describe("minus", () => {
it("returns correct values", () => {
const zero = Decimal.fromUserInput("0", 5);
expect(Decimal.fromUserInput("0", 5).minus(zero).toString()).toEqual("0");
expect(Decimal.fromUserInput("1", 5).minus(zero).toString()).toEqual("1");
expect(Decimal.fromUserInput("2", 5).minus(zero).toString()).toEqual("2");
expect(Decimal.fromUserInput("2.8", 5).minus(zero).toString()).toEqual("2.8");
expect(Decimal.fromUserInput("0.12345", 5).minus(zero).toString()).toEqual("0.12345");
const one = Decimal.fromUserInput("1", 5);
expect(Decimal.fromUserInput("1", 5).minus(one).toString()).toEqual("0");
expect(Decimal.fromUserInput("2", 5).minus(one).toString()).toEqual("1");
expect(Decimal.fromUserInput("3", 5).minus(one).toString()).toEqual("2");
expect(Decimal.fromUserInput("3.8", 5).minus(one).toString()).toEqual("2.8");
expect(Decimal.fromUserInput("1.12345", 5).minus(one).toString()).toEqual("0.12345");
const oneDotFive = Decimal.fromUserInput("1.5", 5);
expect(Decimal.fromUserInput("1.5", 5).minus(oneDotFive).toString()).toEqual("0");
expect(Decimal.fromUserInput("2.5", 5).minus(oneDotFive).toString()).toEqual("1");
expect(Decimal.fromUserInput("3.5", 5).minus(oneDotFive).toString()).toEqual("2");
expect(Decimal.fromUserInput("4.3", 5).minus(oneDotFive).toString()).toEqual("2.8");
expect(Decimal.fromUserInput("1.62345", 5).minus(oneDotFive).toString()).toEqual("0.12345");
// original value remain unchanged
expect(zero.toString()).toEqual("0");
expect(one.toString()).toEqual("1");
expect(oneDotFive.toString()).toEqual("1.5");
});
it("throws for different fractional digits", () => {
const zero = Decimal.fromUserInput("0", 5);
expect(() => Decimal.fromUserInput("1", 1).minus(zero)).toThrowError(/do not match/i);
expect(() => Decimal.fromUserInput("1", 2).minus(zero)).toThrowError(/do not match/i);
expect(() => Decimal.fromUserInput("1", 3).minus(zero)).toThrowError(/do not match/i);
expect(() => Decimal.fromUserInput("1", 4).minus(zero)).toThrowError(/do not match/i);
expect(() => Decimal.fromUserInput("1", 6).minus(zero)).toThrowError(/do not match/i);
expect(() => Decimal.fromUserInput("1", 7).minus(zero)).toThrowError(/do not match/i);
});
it("throws for negative results", () => {
const one = Decimal.fromUserInput("1", 5);
expect(() => Decimal.fromUserInput("0", 5).minus(one)).toThrowError(/must not be negative/i);
expect(() => Decimal.fromUserInput("0.5", 5).minus(one)).toThrowError(/must not be negative/i);
expect(() => Decimal.fromUserInput("0.98765", 5).minus(one)).toThrowError(/must not be negative/i);
});
});
describe("multiply", () => {
it("returns correct values for Uint32", () => {
const zero = Decimal.fromUserInput("0", 5);

View File

@ -126,6 +126,19 @@ export class Decimal {
return new Decimal(sum.toString(), this.fractionalDigits);
}
/**
* a.minus(b) returns a-b.
*
* Both values need to have the same fractional digits.
* The resulting difference needs to be non-negative.
*/
public minus(b: Decimal): Decimal {
if (this.fractionalDigits !== b.fractionalDigits) throw new Error("Fractional digits do not match");
const difference = this.data.atomics.sub(new BN(b.atomics));
if (difference.ltn(0)) throw new Error("Difference must not be negative");
return new Decimal(difference.toString(), this.fractionalDigits);
}
/**
* a.multiply(b) returns a*b.
*

View File

@ -25,6 +25,13 @@ export declare class Decimal {
* Both values need to have the same fractional digits.
*/
plus(b: Decimal): Decimal;
/**
* a.minus(b) returns a-b.
*
* Both values need to have the same fractional digits.
* The resulting difference needs to be non-negative.
*/
minus(b: Decimal): Decimal;
/**
* a.multiply(b) returns a*b.
*

View File

View File

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

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/socket",
"version": "0.22.2",
"version": "0.22.3",
"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.2",
"@cosmjs/stream": "^0.22.3",
"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.2",
"version": "0.22.3",
"description": "Utilities for Cosmos SDK 0.40",
"contributors": [
"Simon Warta <webmaster128@users.noreply.github.com>"
@ -46,13 +46,13 @@
},
"dependencies": {
"@confio/ics23": "^0.6.3",
"@cosmjs/encoding": "^0.22.2",
"@cosmjs/launchpad": "^0.22.2",
"@cosmjs/math": "^0.22.2",
"@cosmjs/proto-signing": "^0.22.2",
"@cosmjs/stream": "^0.22.2",
"@cosmjs/tendermint-rpc": "^0.22.2",
"@cosmjs/utils": "^0.22.2",
"@cosmjs/encoding": "^0.22.3",
"@cosmjs/launchpad": "^0.22.3",
"@cosmjs/math": "^0.22.3",
"@cosmjs/proto-signing": "^0.22.3",
"@cosmjs/stream": "^0.22.3",
"@cosmjs/tendermint-rpc": "^0.22.3",
"@cosmjs/utils": "^0.22.3",
"long": "^4.0.0",
"protobufjs": "~6.10.0"
}

View File

View File

@ -1,6 +1,6 @@
{
"name": "@cosmjs/stream",
"version": "0.22.2",
"version": "0.22.3",
"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.2",
"version": "0.22.3",
"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.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",
"@cosmjs/crypto": "^0.22.3",
"@cosmjs/encoding": "^0.22.3",
"@cosmjs/json-rpc": "^0.22.3",
"@cosmjs/math": "^0.22.3",
"@cosmjs/socket": "^0.22.3",
"@cosmjs/stream": "^0.22.3",
"axios": "^0.19.0",
"readonly-date": "^1.0.0",
"type-tagger": "^1.0.0",
"xstream": "^11.10.0"
},
"devDependencies": {
"@cosmjs/utils": "^0.22.2"
"@cosmjs/utils": "^0.22.3"
}
}

View File

View File

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