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

Adding contract name verification feature #275

Merged
merged 5 commits into from
Jan 9, 2025
Merged
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
56 changes: 50 additions & 6 deletions src/components/VerifyContract.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
form-row(v-bind='formFields.ABI_ENCODED_ARGUMENTS')
ctrl-radio-grp.frow(name='encoded' @change='(value)=>abiEncodedArgs=value' :selected='abiEncodedArgs')
form-row
button.brand.big(name="submit")
button.brand.big(name="submit" :disabled="errors.length > 0")
span Verify

form.flex(v-if='method === verifyMethods.SOLIDITY_SOURCE_FILE' @submit.prevent='submit')
Expand Down Expand Up @@ -94,7 +94,7 @@
form-row(v-bind='formFields.LIB_ADDRESS')
input(type='text' v-model='lib.address' v-bind='formFields.LIB_ADDRESS.input' )
form-row
button.brand.big(name="submit")
button.brand.big(name="submit" :disabled="errors.length > 0")
span Verify
//-button.btn.big(name="submit" @click.passive='resetForm')
span Reset
Expand Down Expand Up @@ -198,7 +198,8 @@ export default {
errors: [],
timer: undefined,
method: VERIFY_METHODS.SOLIDITY_SOURCE_FILE,
sources: undefined
sources: undefined,
json: undefined
}
},
created () {
Expand Down Expand Up @@ -383,18 +384,22 @@ export default {
this.clearErrors()
this.sources = undefined
this.method = method
this.files = []
},
handleStandardJsonInput (json) {
this.errors.pop()
this.json = json
if (json[0]) {
try {
const { sources, settings } = JSON.parse(json[0].contents)

if (!sources) this.addError('Invalid JSON, missing sources')
if (!settings) this.addError('Invalid JSON, missing settings')

this.settings = settings
this.sources = sources
const fileName = json[0].name.replace('.json', '')
if (this.name && fileName !== this.name) {
this.addError(messages.JSON_INPUT_INVALID(this.name))
}
} catch (error) {
this.addError(error)
}
Expand Down Expand Up @@ -478,8 +483,36 @@ export default {
changeName (name) {
this.name = name.trim()
this.inputErrors.delete('name')
this.clearErrors()
if (this.files.length > 0) {
const hasMatchingFile = this.files.some(file => file.name.replace('.sol', '') === this.name)
if (!hasMatchingFile) {
this.errors.push(messages.CONTRACT_NAME_INVALID(this.name))
} else {
this.clearErrors()
}
}
if (this.json && this.json[0]) {
const fileName = this.json[0].name.replace('.json', '')
if (fileName !== this.name) {
this.addError(messages.JSON_INPUT_INVALID(this.name))
}
}
},
verifyContractName () {
if (this.name && this.files.length > 0) {
const hasMatchingFile = this.files.some(file => file.name.replace('.sol', '') === this.name)
if (!hasMatchingFile) {
this.errors.push(messages.CONTRACT_NAME_INVALID(this.name))
}
}
if (this.name && this.json && this.json[0]) {
const fileName = this.json[0].name.replace('.json', '')
if (fileName !== this.name) {
this.addError(messages.JSON_INPUT_INVALID(this.name))
}
}
},

changeAddress (address) {
this.address = address.trim()
this.reset()
Expand All @@ -489,12 +522,14 @@ export default {
}
},
changeVersion (version) {
console.log('version in change is', version)
this.version = version
this.inputErrors.delete('version')
this.errors.pop()
if (!this.isSupportedSolidityVersion()) {
this.errors.push(messages.NOT_SUPPORTED_SOLIDITY_VERSION_ERROR(version))
}
this.verifyContractName()
},
changeAllVersions (version) {
this.showAllVersions = version
Expand All @@ -520,6 +555,15 @@ export default {
updateFiles (files) {
this.files = files
this.inputErrors.delete('file')
this.clearErrors()
if (this.name && files.length > 0) {
const hasMatchingFile = files.some(file => file.name.replace('.sol', '') === this.name)
if (!hasMatchingFile) {
this.errors.push(messages.CONTRACT_NAME_INVALID(this.name))
} else {
this.clearErrors()
}
}
},
buildsList (builds) {
return builds.concat().reverse().reduce((v, a, i) => {
Expand Down
4 changes: 3 additions & 1 deletion src/config/texts/verifyContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const messages = {
REQUEST_VERIFICATION: 'Requesting verification',
SHOW_RESULT: 'Go to contract page',
VERIFIER_DATA_ERROR: 'Missing contract verifier data',
NOT_SUPPORTED_SOLIDITY_VERSION_ERROR: (value) => `You have selected version ${value} which is not supported. Please, try another one.`
NOT_SUPPORTED_SOLIDITY_VERSION_ERROR: (value) => `You have selected version ${value} which is not supported. Please, try another one.`,
CONTRACT_NAME_INVALID: (contractName) => `No file matches the Contract Name (${contractName}). Please ensure one of the uploaded files has the correct name.`,
JSON_INPUT_INVALID: (contractName) => `The JSON input does not match the contract name (${contractName}). Please ensure the JSON input is correct.`
}

export const formFields = {
Expand Down
4 changes: 4 additions & 0 deletions src/styles/_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@
padding: 12px 30px;
color: $white_100;
border-radius: 8px;
&:disabled {
opacity: 0.5;
cursor: not-allowed;
}
}
}
}
Expand Down
Loading