Skip to content

Commit

Permalink
Resolving ENS address on submission
Browse files Browse the repository at this point in the history
  • Loading branch information
corydickson committed Mar 31, 2020
1 parent c09d82d commit 8c54ce5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const save = outputFileSync;
import {
cborDecode,
getBytecode,
resolveAddress,
recompile,
RecompilationResult,
} from './utils';
Expand Down Expand Up @@ -188,18 +189,23 @@ export default class Injector {
* and by swarm | ipfs hash.
* @param {string} repository repository root (ex: 'repository')
* @param {string} chain chain name (ex: 'ropsten')
* @param {string} address contract address
* @param {string} address contract address or ENS address
* @param {boolean} isENS needs to be resolved by ENS
* @param {string[]} files
* @return {Promise<string[]>} addresses of successfully verified contracts
*/
public async inject(
repository: string,
chain: string,
address: string,
isENS: boolean,
files: string[]
) : Promise<string[]> {

if (address) {
if (isENS) {
address = resolveAddress(address)
}
address = Web3.utils.toChecksumAddress(address)
}

Expand Down
1 change: 1 addition & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ app.post('/', (req, res) => {
repository,
req.body.chain,
req.body.address,
req.body.isENS,
files
).then(result => {
res.status(200).send({ result })
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ export async function getBytecode(web3: Web3, address: string) {
return await web3.eth.getCode(address);
};

/**
* Wraps ens.getAddress
* @param {Web3} web3 connected web3 instance
* @param {string} address ENS address
*/
export async function resolveAddress(web3: Web3, address: string) {
console.log("Resolving ENS address at " + address + "to ethereum account...")
return await web3.eth.ens.getAddress(address)
}

/**
* Formats metadata into an object which can be passed to solc for recompilation
* @param {any} metadata solc metadata object
Expand Down

0 comments on commit 8c54ce5

Please sign in to comment.