Remove references to "first chain"
This commit is contained in:
parent
cb3df57426
commit
84c5998ca8
@ -9,12 +9,12 @@ import { codecDefaultFractionalDigits, codecImplementation, createChainConnector
|
||||
import * as constants from "../../constants";
|
||||
import { logAccountsState, logSendJob } from "../../debugging";
|
||||
import {
|
||||
accountsOfFirstChain,
|
||||
availableTokensFromHolder,
|
||||
identitiesOfFirstWallet,
|
||||
refillFirstChain,
|
||||
sendOnFirstChain,
|
||||
tokenTickersOfFirstChain,
|
||||
loadAccounts,
|
||||
loadTokenTickers,
|
||||
refill,
|
||||
send,
|
||||
} from "../../multichainhelpers";
|
||||
import { setSecretAndCreateIdentities } from "../../profile";
|
||||
import { SendJob } from "../../types";
|
||||
@ -52,24 +52,24 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
|
||||
setFractionalDigits(codecDefaultFractionalDigits());
|
||||
await setSecretAndCreateIdentities(profile, constants.mnemonic, connectedChainId);
|
||||
|
||||
const chainTokens = await tokenTickersOfFirstChain(connection);
|
||||
const chainTokens = await loadTokenTickers(connection);
|
||||
console.info("Chain tokens:", chainTokens);
|
||||
|
||||
const accounts = await accountsOfFirstChain(profile, connection);
|
||||
const accounts = await loadAccounts(profile, connection);
|
||||
logAccountsState(accounts);
|
||||
|
||||
let availableTokens = availableTokensFromHolder(accounts[0]);
|
||||
console.info("Available tokens:", availableTokens);
|
||||
setInterval(async () => {
|
||||
const updatedAccounts = await accountsOfFirstChain(profile, connection);
|
||||
const updatedAccounts = await loadAccounts(profile, connection);
|
||||
availableTokens = availableTokensFromHolder(updatedAccounts[0]);
|
||||
console.info("Available tokens:", availableTokens);
|
||||
}, 60_000);
|
||||
|
||||
const distibutorIdentities = identitiesOfFirstWallet(profile).slice(1);
|
||||
|
||||
await refillFirstChain(profile, connection);
|
||||
setInterval(async () => refillFirstChain(profile, connection), 60_000); // ever 60 seconds
|
||||
await refill(profile, connection);
|
||||
setInterval(async () => refill(profile, connection), 60_000); // ever 60 seconds
|
||||
|
||||
console.info("Creating webserver ...");
|
||||
const api = new Koa();
|
||||
@ -88,7 +88,7 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
|
||||
"See https://github.com/iov-one/iov-faucet for all further information.\n";
|
||||
break;
|
||||
case "/status": {
|
||||
const updatedAccounts = await accountsOfFirstChain(profile, connection);
|
||||
const updatedAccounts = await loadAccounts(profile, connection);
|
||||
context.response.body = {
|
||||
status: "ok",
|
||||
nodeUrl: blockchainBaseUrl,
|
||||
@ -132,7 +132,7 @@ export async function start(args: ReadonlyArray<string>): Promise<void> {
|
||||
tokenTicker: ticker,
|
||||
};
|
||||
logSendJob(job);
|
||||
await sendOnFirstChain(profile, connection, job);
|
||||
await send(profile, connection, job);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw new HttpError(500, "Sending tokens failed");
|
||||
|
||||
@ -23,7 +23,7 @@ export function identitiesOfFirstWallet(profile: UserProfile): ReadonlyArray<Ide
|
||||
return profile.getIdentities(wallet.id);
|
||||
}
|
||||
|
||||
export async function accountsOfFirstChain(
|
||||
export async function loadAccounts(
|
||||
profile: UserProfile,
|
||||
connection: BlockchainConnection,
|
||||
): Promise<ReadonlyArray<Account>> {
|
||||
@ -50,7 +50,7 @@ export async function accountsOfFirstChain(
|
||||
return out;
|
||||
}
|
||||
|
||||
export async function tokenTickersOfFirstChain(
|
||||
export async function loadTokenTickers(
|
||||
connection: BlockchainConnection,
|
||||
): Promise<ReadonlyArray<TokenTicker>> {
|
||||
return (await connection.getAllTokens()).map(token => token.tokenTicker);
|
||||
@ -59,7 +59,7 @@ export async function tokenTickersOfFirstChain(
|
||||
/**
|
||||
* Creates and posts a send transaction. Then waits until the transaction is in a block.
|
||||
*/
|
||||
export async function sendOnFirstChain(
|
||||
export async function send(
|
||||
profile: UserProfile,
|
||||
connection: BlockchainConnection,
|
||||
job: SendJob,
|
||||
@ -90,16 +90,13 @@ export function availableTokensFromHolder(holderAccount: Account): ReadonlyArray
|
||||
return holderAccount.balance.map(coin => coin.tokenTicker);
|
||||
}
|
||||
|
||||
export async function refillFirstChain(
|
||||
profile: UserProfile,
|
||||
connection: BlockchainConnection,
|
||||
): Promise<void> {
|
||||
export async function refill(profile: UserProfile, connection: BlockchainConnection): Promise<void> {
|
||||
console.info(`Connected to network: ${connection.chainId()}`);
|
||||
console.info(`Tokens on network: ${(await tokenTickersOfFirstChain(connection)).join(", ")}`);
|
||||
console.info(`Tokens on network: ${(await loadTokenTickers(connection)).join(", ")}`);
|
||||
|
||||
const holderIdentity = identitiesOfFirstWallet(profile)[0];
|
||||
|
||||
const accounts = await accountsOfFirstChain(profile, connection);
|
||||
const accounts = await loadAccounts(profile, connection);
|
||||
logAccountsState(accounts);
|
||||
const holderAccount = accounts[0];
|
||||
const distributorAccounts = accounts.slice(1);
|
||||
@ -128,12 +125,12 @@ export async function refillFirstChain(
|
||||
if (jobs.length > 0) {
|
||||
for (const job of jobs) {
|
||||
logSendJob(job);
|
||||
await sendOnFirstChain(profile, connection, job);
|
||||
await send(profile, connection, job);
|
||||
await sleep(50);
|
||||
}
|
||||
|
||||
console.info("Done refilling accounts.");
|
||||
logAccountsState(await accountsOfFirstChain(profile, connection));
|
||||
logAccountsState(await loadAccounts(profile, connection));
|
||||
} else {
|
||||
console.info("Nothing to be done. Anyways, thanks for checking.");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user