From beba1c8db4e7c2b29ee6dedd97f05d57b4af23c1 Mon Sep 17 00:00:00 2001 From: Coogan Date: Sun, 16 May 2021 20:16:57 -0500 Subject: [PATCH 1/3] adds network-specific txn url to webapp --- src/webapp/index.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/webapp/index.js b/src/webapp/index.js index 8404ece..eae51c7 100644 --- a/src/webapp/index.js +++ b/src/webapp/index.js @@ -57,6 +57,27 @@ function getNetwork () { if (res.error) return console.res.error(res.error) var network = res.result state.network = network + + // set networkName for use in etherscan URL + switch(network) { + case '3': + state.networkName = 'ropsten'; + break + case '42': + state.networkName = 'kovan'; + break + case '4': + state.networkName = 'rinkeby'; + break + case '5': + state.networkName = 'goerli'; + break + // not sure about the best way to handle this, but + // need to have something if they're on non-public testnet + default: + state.networkName = 'unknown'; + break + } renderApp() }) } @@ -209,7 +230,7 @@ function renderApp () { } }, ( state.transactions.map((txHash) => { - return link(`https://ropsten.etherscan.io/tx/${txHash}`, txHash) + return link(`https://${state.networkName}.etherscan.io/tx/${txHash}`, txHash) }) )) ]) @@ -232,16 +253,18 @@ async function getEther () { if (!account) return var uri = `${window.location.href}v0/request` - var data = account + var data = { + 'account' : account, + 'network' : state.network, + } let res, body, err - try { res = await fetch(uri, { method: 'POST', body: data, headers: { - 'Content-Type': 'application/rawdata' + 'Content-Type': 'application/json' } }) body = await res.text() From fb0a44a21ef312f104ab37249ad29c43969bf6cd Mon Sep 17 00:00:00 2001 From: Coogan Date: Sun, 16 May 2021 20:25:09 -0500 Subject: [PATCH 2/3] comments where server/index.js needs to be altered --- src/server/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/server/index.js b/src/server/index.js index acfef2e..eb1311b 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -36,6 +36,8 @@ console.log('Acting as faucet for address:', config.address) // // ProviderEngine based caching layer, with fallback to geth +// +// need to be able to dynamically change rpcOrigin based on network requesting funds const engine = rpcWrapperEngine({ rpcUrl: config.rpcOrigin, addressHex: config.address, @@ -110,6 +112,8 @@ function startServer () { const alignedIpAddress = ipAddress.padStart(15, ' ') const requestorMessage = `${flag} ${alignedIpAddress} requesting for ${targetAddress}` // check for greediness + // + // need to change network here: const balance = await ethQuery.getBalance(targetAddress, 'pending') const balanceTooFull = balance.gt(MAX_BALANCE) if (balanceTooFull) { @@ -117,6 +121,7 @@ function startServer () { return didError(res, new Error('User is greedy - already has too much ether')) } // send value + // need ot change network here as well: const txHash = await ethQuery.sendTransaction({ to: targetAddress, from: config.address, From 07dc818c341b2103175420295c068f25278a0e58 Mon Sep 17 00:00:00 2001 From: Coogan Date: Sun, 16 May 2021 20:28:44 -0500 Subject: [PATCH 3/3] adds another comment --- src/server/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/server/index.js b/src/server/index.js index eb1311b..91e0a7f 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -87,6 +87,11 @@ function startServer () { async function handleRequest (req, res) { try { // parse address + // can parse for network here. + // can either be json object or + // inserted in a combined rawdata string with address, and then parsed out here + // depending on what the network is, make sure ethQuery engine knows when + // testing balance and sending transaction let targetAddress = req.body if (!targetAddress || typeof targetAddress !== 'string') { return didError(res, new Error(`Address parse failure - request body empty`))