Remove unused ethereum support from faucet

This commit is contained in:
Simon Warta 2020-01-29 14:51:22 +01:00
parent bf22ee313f
commit 3fbd1288fe
12 changed files with 9 additions and 146 deletions

View File

@ -63,7 +63,6 @@ The faucet uses standard HD paths for each blockchain, e.g.
```
IOV m/44'/234'/a'
Lisk m/44'/134'/a'
Ethereum m/44'/60'/0'/0/a
CosmWasm m/44'/118'/0'/0/a
```

View File

@ -37,7 +37,6 @@
"@iov/bns": "^2.0.0-alpha.7",
"@iov/crypto": "^2.0.0-alpha.7",
"@iov/encoding": "^2.0.0-alpha.7",
"@iov/ethereum": "^2.0.0-alpha.7",
"@iov/lisk": "^2.0.0-alpha.7",
"@iov/multichain": "^2.0.0-alpha.7",
"@koa/cors": "^3.0.0",

View File

@ -5,7 +5,7 @@ import cors = require("@koa/cors");
import Koa from "koa";
import bodyParser from "koa-bodyparser";
import { creditAmount, gasLimit, gasPrice, setFractionalDigits } from "../../cashflow";
import { creditAmount, setFractionalDigits } from "../../cashflow";
import {
codecDefaultFractionalDigits,
codecFromString,
@ -73,8 +73,8 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
const distibutorIdentities = identitiesOfFirstWallet(profile).slice(1);
await refillFirstChain(profile, signer, codec);
setInterval(async () => refillFirstChain(profile, signer, codec), 60_000); // ever 60 seconds
await refillFirstChain(profile, signer);
setInterval(async () => refillFirstChain(profile, signer), 60_000); // ever 60 seconds
console.info("Creating webserver ...");
const api = new Koa();
@ -135,8 +135,6 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
recipient: address,
amount: creditAmount(ticker),
tokenTicker: ticker,
gasPrice: gasPrice(codec),
gasLimit: gasLimit(codec),
};
logSendJob(signer, job);
await sendOnFirstChain(profile, signer, job);

View File

@ -1,15 +1,7 @@
// tslint:disable: no-object-mutation
import { TokenTicker } from "@iov/bcp";
import {
creditAmount,
gasLimit,
gasPrice,
refillAmount,
refillThreshold,
setFractionalDigits,
} from "./cashflow";
import { Codec } from "./codec";
import { creditAmount, refillAmount, refillThreshold, setFractionalDigits } from "./cashflow";
describe("Cashflow", () => {
beforeAll(() => {
@ -130,34 +122,4 @@ describe("Cashflow", () => {
});
});
});
describe("gasPrice", () => {
it("returns undefined for non-Ethereum codecs", () => {
expect(gasPrice(Codec.Lisk)).toBeUndefined();
expect(gasPrice(Codec.Bns)).toBeUndefined();
});
it("returns amount for Ethereum codec", () => {
expect(gasPrice(Codec.Ethereum)).toEqual({
quantity: "20000000000",
fractionalDigits: 18,
tokenTicker: "ETH",
});
});
});
describe("gasLimit", () => {
it("returns undefined for non-Ethereum codecs", () => {
expect(gasLimit(Codec.Lisk)).toBeUndefined();
expect(gasLimit(Codec.Bns)).toBeUndefined();
});
it("returns amount for Ethereum codec", () => {
expect(gasLimit(Codec.Ethereum)).toEqual({
quantity: "2100000",
fractionalDigits: 18,
tokenTicker: "ETH",
});
});
});
});

View File

@ -3,9 +3,6 @@ import BN = require("bn.js");
import { Account, Amount, TokenTicker } from "@iov/bcp";
import { Int53 } from "@iov/encoding";
import { Codec } from "./codec";
import * as constants from "./constants";
/** Send `factor` times credit amount on refilling */
const defaultRefillFactor = 20;
@ -61,37 +58,3 @@ export function needsRefill(account: Account, token: TokenTicker): boolean {
const refillQty = new BN(refillThreshold(token).quantity);
return new BN(tokenBalance).lt(refillQty);
}
export function gasPrice(codec: Codec): Amount | undefined {
switch (codec) {
case Codec.Bns:
case Codec.Lisk:
case Codec.CosmWasm:
return undefined;
case Codec.Ethereum:
return {
quantity: constants.ethereum.gasPrice,
fractionalDigits: 18,
tokenTicker: "ETH" as TokenTicker,
};
default:
throw new Error("No gasPrice imlementation found for this codec");
}
}
export function gasLimit(codec: Codec): Amount | undefined {
switch (codec) {
case Codec.Bns:
case Codec.Lisk:
case Codec.CosmWasm:
return undefined;
case Codec.Ethereum:
return {
quantity: constants.ethereum.gasLimit,
fractionalDigits: 18,
tokenTicker: "ETH" as TokenTicker,
};
default:
throw new Error("No gasLimit imlementation found for this codec");
}
}

View File

@ -4,11 +4,11 @@ describe("Codec", () => {
it("can convert string to codec", () => {
expect(codecFromString("bns")).toEqual(Codec.Bns);
expect(codecFromString("lisk")).toEqual(Codec.Lisk);
expect(codecFromString("ethereum")).toEqual(Codec.Ethereum);
expect(codecFromString("cosmwasm")).toEqual(Codec.CosmWasm);
expect(() => codecFromString("")).toThrowError(/not supported/i);
expect(() => codecFromString("abc")).toThrowError(/not supported/i);
expect(() => codecFromString("LISK")).toThrowError(/not supported/i);
expect(() => codecFromString("ETHEREUM")).toThrowError(/not supported/i);
expect(() => codecFromString("CosmWasm")).toThrowError(/not supported/i);
});
});

View File

@ -2,14 +2,12 @@ import { createCosmWasmConnector, TokenInfo } from "@cosmwasm/bcp";
import { ChainConnector, TokenTicker, TxCodec } from "@iov/bcp";
import { createBnsConnector } from "@iov/bns";
import { Slip10RawIndex } from "@iov/crypto";
import { createEthereumConnector } from "@iov/ethereum";
import { HdPaths } from "@iov/keycontrol";
import { createLiskConnector } from "@iov/lisk";
export const enum Codec {
Bns,
Lisk,
Ethereum,
CosmWasm,
}
@ -19,8 +17,6 @@ export function codecFromString(input: string): Codec {
return Codec.Bns;
case "lisk":
return Codec.Lisk;
case "ethereum":
return Codec.Ethereum;
case "cosmwasm":
return Codec.CosmWasm;
default:
@ -35,8 +31,6 @@ export function createPathBuilderForCodec(codec: Codec): (derivation: number) =>
return HdPaths.iov(accountIndex);
case Codec.Lisk:
return HdPaths.bip44Like(134, accountIndex);
case Codec.Ethereum:
return HdPaths.ethereum(accountIndex);
case Codec.CosmWasm:
return HdPaths.cosmos(accountIndex);
default:
@ -52,8 +46,6 @@ export function createChainConnector(codec: Codec, url: string): ChainConnector
return createBnsConnector(url);
case Codec.Lisk:
return createLiskConnector(url);
case Codec.Ethereum:
return createEthereumConnector(url, {});
case Codec.CosmWasm: {
const tokens: readonly TokenInfo[] = [
{
@ -86,8 +78,6 @@ export function codecDefaultFractionalDigits(codec: Codec): number {
return 9; // fixed for all weave tokens
case Codec.Lisk:
return 8;
case Codec.Ethereum:
return 18;
case Codec.CosmWasm:
return 6;
default:

View File

@ -1,7 +1,3 @@
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;
export const ethereum = {
gasPrice: "20000000000",
gasLimit: "2100000",
};

View File

@ -7,7 +7,6 @@ export function createWalletForCodec(input: Codec, mnemonic: string): Wallet {
case Codec.Bns:
case Codec.Lisk:
return Ed25519HdWallet.fromMnemonic(mnemonic);
case Codec.Ethereum:
case Codec.CosmWasm:
return Secp256k1HdWallet.fromMnemonic(mnemonic);
default:

View File

@ -9,8 +9,7 @@ import {
import { UserProfile } from "@iov/keycontrol";
import { MultiChainSigner } from "@iov/multichain";
import { gasLimit, gasPrice, needsRefill, refillAmount } from "./cashflow";
import { Codec } from "./codec";
import { needsRefill, refillAmount } from "./cashflow";
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
import { SendJob } from "./types";
@ -89,11 +88,7 @@ export function availableTokensFromHolder(holderAccount: Account): ReadonlyArray
return holderAccount.balance.map(coin => coin.tokenTicker);
}
export async function refillFirstChain(
profile: UserProfile,
signer: MultiChainSigner,
codec: Codec,
): Promise<void> {
export async function refillFirstChain(profile: UserProfile, signer: MultiChainSigner): Promise<void> {
const chainId = signer.chainIds()[0];
console.info(`Connected to network: ${chainId}`);
@ -124,8 +119,6 @@ export async function refillFirstChain(
recipient: refillDistibutor.address,
tokenTicker: token,
amount: refillAmount(token),
gasPrice: gasPrice(codec),
gasLimit: gasLimit(codec),
});
}
}

View File

@ -5,6 +5,4 @@ export interface SendJob {
readonly recipient: Address;
readonly tokenTicker: TokenTicker;
readonly amount: Amount;
readonly gasPrice?: Amount;
readonly gasLimit?: Amount;
}

View File

@ -149,28 +149,6 @@
bn.js "^4.11.8"
readonly-date "^1.0.0"
"@iov/ethereum@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/ethereum/-/ethereum-2.0.0-alpha.7.tgz#f1a72947e5ce62a7afc56f0320866f08b2bf01b9"
integrity sha512-q+AJsIuwbBbrEMpztgGQIsApFJQ/n7t9Uq/pi3OGqUdcXCG6JYJH+XjClv0yIVcMB8pxfNwQ9RvYy75Zpn0icw==
dependencies:
"@iov/bcp" "^2.0.0-alpha.7"
"@iov/crypto" "^2.0.0-alpha.7"
"@iov/encoding" "^2.0.0-alpha.7"
"@iov/jsonrpc" "^2.0.0-alpha.7"
"@iov/keycontrol" "^2.0.0-alpha.7"
"@iov/socket" "^2.0.0-alpha.7"
"@iov/stream" "^2.0.0-alpha.7"
"@iov/utils" "^2.0.0-alpha.7"
"@types/long" "^4.0.0"
axios "^0.19.0"
bn.js "^4.11.8"
fast-deep-equal "^3.1.1"
long "^4.0.0"
readonly-date "^1.0.0"
rlp "^2.2.3"
xstream "^11.10.0"
"@iov/jsonrpc@^2.0.0-alpha.7":
version "2.0.0-alpha.7"
resolved "https://registry.yarnpkg.com/@iov/jsonrpc/-/jsonrpc-2.0.0-alpha.7.tgz#7bff8e1f21d52ff07482212ded8cc00e01dda964"
@ -260,11 +238,6 @@
type-tagger "^1.0.0"
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==
"@koa/cors@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@koa/cors/-/cors-3.0.0.tgz#df021b4df2dadf1e2b04d7c8ddf93ba2d42519cb"
@ -1977,7 +1950,7 @@ bluebird@^3.3.0, bluebird@^3.5.1, bluebird@^3.5.3, bluebird@^3.5.5:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.1, bn.js@^4.11.8, bn.js@^4.4.0:
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==
@ -6928,13 +6901,6 @@ ripemd160@^2.0.0, ripemd160@^2.0.1, ripemd160@^2.0.2:
hash-base "^3.0.0"
inherits "^2.0.1"
rlp@^2.2.3:
version "2.2.4"
resolved "https://registry.yarnpkg.com/rlp/-/rlp-2.2.4.tgz#d6b0e1659e9285fc509a5d169a9bd06f704951c1"
integrity sha512-fdq2yYCWpAQBhwkZv+Z8o/Z4sPmYm1CUq6P7n6lVTOdb949CnqA0sndXal5C1NleSVSZm6q5F3iEbauyVln/iw==
dependencies:
bn.js "^4.11.1"
run-async@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"