diff --git a/packages/faucet/src/actions/start/start.ts b/packages/faucet/src/actions/start/start.ts index 94396c1e..43789c4b 100644 --- a/packages/faucet/src/actions/start/start.ts +++ b/packages/faucet/src/actions/start/start.ts @@ -133,8 +133,8 @@ export async function start(args: ReadonlyArray): Promise { amount: creditAmount(ticker), tokenTicker: ticker, }; - logSendJob(signer, job); - await sendOnFirstChain(profile, signer, job); + logSendJob(job); + await sendOnFirstChain(profile, connection, job); } catch (e) { console.error(e); throw new HttpError(500, "Sending tokens failed"); diff --git a/packages/faucet/src/debugging.ts b/packages/faucet/src/debugging.ts index 1fb4c9ab..a5d7cf64 100644 --- a/packages/faucet/src/debugging.ts +++ b/packages/faucet/src/debugging.ts @@ -1,7 +1,7 @@ import { Account, Amount } from "@iov/bcp"; import { Decimal } from "@iov/encoding"; -import { MultiChainSigner } from "@iov/multichain"; +import { codecImplementation } from "./codec"; import { SendJob } from "./types"; /** A string representation of a coin in a human-readable format that can change at any time */ @@ -30,8 +30,8 @@ export function logAccountsState(accounts: ReadonlyArray): void { console.info("Distributors:\n" + distributors.map(r => ` ${debugAccount(r)}`).join("\n")); } -export function logSendJob(signer: MultiChainSigner, job: SendJob): void { - const from = signer.identityToAddress(job.sender); +export function logSendJob(job: SendJob): void { + const from = codecImplementation().identityToAddress(job.sender); const to = job.recipient; const amount = debugAmount(job.amount); console.info(`Sending ${amount} from ${from} to ${to} ...`); diff --git a/packages/faucet/src/multichainhelpers.ts b/packages/faucet/src/multichainhelpers.ts index d54b8891..cedcac8d 100644 --- a/packages/faucet/src/multichainhelpers.ts +++ b/packages/faucet/src/multichainhelpers.ts @@ -1,5 +1,6 @@ import { Account, + BlockchainConnection, Identity, isBlockInfoFailed, isBlockInfoPending, @@ -10,6 +11,7 @@ import { UserProfile } from "@iov/keycontrol"; import { MultiChainSigner } from "@iov/multichain"; import { needsRefill, refillAmount } from "./cashflow"; +import { codecImplementation } from "./codec"; import { debugAccount, logAccountsState, logSendJob } from "./debugging"; import { SendJob } from "./types"; @@ -61,23 +63,25 @@ export async function tokenTickersOfFirstChain( */ export async function sendOnFirstChain( profile: UserProfile, - signer: MultiChainSigner, + connection: BlockchainConnection, job: SendJob, ): Promise { - const chainId = signer.chainIds()[0]; - const connection = signer.connection(chainId); + const codec = codecImplementation(); const sendWithFee = await connection.withDefaultFee({ kind: "bcp/send", - chainId: chainId, - sender: signer.identityToAddress(job.sender), + chainId: connection.chainId(), + sender: codec.identityToAddress(job.sender), senderPubkey: job.sender.pubkey, recipient: job.recipient, memo: "We ❤️ developers – iov.one", amount: job.amount, }); - const post = await signer.signAndPost(job.sender, sendWithFee); + const nonce = await connection.getNonce({ pubkey: job.sender.pubkey }); + const signed = await profile.signTransaction(job.sender, sendWithFee, codec, nonce); + + const post = await connection.postTx(codec.bytesToPost(signed)); const blockInfo = await post.blockInfo.waitFor(info => !isBlockInfoPending(info)); if (isBlockInfoFailed(blockInfo)) { throw new Error(`Sending tokens failed. Code: ${blockInfo.code}, message: ${blockInfo.message}`); @@ -90,6 +94,7 @@ export function availableTokensFromHolder(holderAccount: Account): ReadonlyArray export async function refillFirstChain(profile: UserProfile, signer: MultiChainSigner): Promise { const chainId = signer.chainIds()[0]; + const connection = signer.connection(chainId); console.info(`Connected to network: ${chainId}`); console.info(`Tokens on network: ${(await tokenTickersOfFirstChain(signer)).join(", ")}`); @@ -124,8 +129,8 @@ export async function refillFirstChain(profile: UserProfile, signer: MultiChainS } if (jobs.length > 0) { for (const job of jobs) { - logSendJob(signer, job); - await sendOnFirstChain(profile, signer, job); + logSendJob(job); + await sendOnFirstChain(profile, connection, job); await sleep(50); }