diff --git a/src/server/index.js b/src/server/index.js index acfef2e..91e0a7f 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, @@ -85,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`)) @@ -110,6 +117,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 +126,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, 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()