Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve ENS addresses upon submission #114

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way this could be achieved is keeping the assumption the input is not sanitized and match domains here, not sure if we should be accepting subdomains...

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
63 changes: 37 additions & 26 deletions ui/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,39 @@ import { useDropzone } from 'react-dropzone'
import Select from 'react-select'

export default function App() {
const chainOptions = [
{ value: 'mainnet', label: 'Ethereum Mainnet' },
{ value: 'ropsten', label: 'Ropsten' },
{ value: 'rinkeby', label: 'Rinkeby' },
{ value: 'kovan', label: 'Kovan' },
{ value: 'goerli', label: 'Görli' }
]

if (process.env.NODE_ENV === 'testing'){
chainOptions.push({
value: 'localhost',
label: 'localhost:8545'
})
}
const chainOptions = [
{ value: 'mainnet', label: 'Ethereum Mainnet' },
{ value: 'ropsten', label: 'Ropsten' },
{ value: 'rinkeby', label: 'Rinkeby' },
{ value: 'kovan', label: 'Kovan' },
{ value: 'goerli', label: 'Görli' }
]

if (process.env.NODE_ENV === 'testing'){
chainOptions.push({
value: 'localhost',
label: 'localhost:8545'
})
}

const { acceptedFiles, getRootProps, getInputProps } = useDropzone()
const [chain, updateChain] = useState(chainOptions[0])
const [address, updateAddress] = useState('')
const [loading, updateLoading] = useState(false)
const [error, updateError] = useState(null)
const url = process.env.SERVER_URL
const repositoryUrl = process.env.REPOSITORY_URL
const log = console.log
log(`Server URL: ${url}`)
const { acceptedFiles, getRootProps, getInputProps } = useDropzone()
const [chain, updateChain] = useState(chainOptions[0])
const [address, updateAddress] = useState('')
const [ens, updateENS] = useState(false)
const [loading, updateLoading] = useState(false)
const [error, updateError] = useState(null)
const url = process.env.SERVER_URL
const repositoryUrl = process.env.REPOSITORY_URL
const log = console.log
log(`Server URL: ${url}`)

const [result, updateResult] = useState([])

function handleChange(e) {
updateENS(/[A-Za-z]\w+(.eth)$/.test(e.target.value))
updateAddress(e.target.value)
}

function handleSubmit() {
updateError(null)
updateResult([])
Expand All @@ -40,11 +46,16 @@ export default function App() {
formData.append('files', file)
})
formData.append('chain', chain.value)
if (address) formData.append('address', address)
if (address) {
formData.append('address', address)
formData.append('isENS', ens)
}

try{
fetch(`${url}`, {
method: 'POST',
body: formData

})
.then(res => res.json())
.then(response => {
Expand Down Expand Up @@ -114,9 +125,9 @@ export default function App() {
<input
type="text"
name="address"
placeholder="Contract Address (required)"
placeholder="Contract Address (optional for Mainnet) or ENS Address"
value={address}
onChange={e => updateAddress(e.target.value)}
onChange={e => handleChange(e)}
/>

<div {...getRootProps({ className: 'app-dropzone' })}>
Expand Down
2 changes: 1 addition & 1 deletion ui/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ input[type='submit']:disabled {
}

.app-fieldset_left > * {
min-width: 240px;
min-width: 300px;
}

.select {
Expand Down