parent
a3427b4795
commit
cc6c24677e
@ -1,46 +0,0 @@ |
|||||||
import type { ChainSettings, ContractVerificationSettings, SettingsForVerifier, VerifierSettings } from './SettingsTypes' |
|
||||||
import { VerifierIdentifier, VERIFIERS } from './VerificationTypes' |
|
||||||
|
|
||||||
const DEFAULTS: SettingsForVerifier = { |
|
||||||
Sourcify: { |
|
||||||
apiUrl: 'https://sourcify.dev/server', |
|
||||||
explorerUrl: 'https://repo.sourcify.dev', |
|
||||||
}, |
|
||||||
Etherscan: { |
|
||||||
apiUrl: 'https://api.etherscan.io', |
|
||||||
explorerUrl: 'https://etherscan.io', |
|
||||||
apiKey: undefined, |
|
||||||
}, |
|
||||||
Blockscout: { |
|
||||||
apiUrl: 'https://eth.blockscout.com', |
|
||||||
}, |
|
||||||
} |
|
||||||
|
|
||||||
export function mergeChainSettingsWithDefaults(chainId: string, userSettings: ContractVerificationSettings): ChainSettings { |
|
||||||
const verifiers: SettingsForVerifier = {} |
|
||||||
|
|
||||||
for (const verifierId of VERIFIERS) { |
|
||||||
const userSetting: VerifierSettings = userSettings.chains[chainId]?.verifiers[verifierId] |
|
||||||
|
|
||||||
if (userSetting) { |
|
||||||
verifiers[verifierId] = { ...userSetting } |
|
||||||
// Only apply default settings for Etherscan and Blockscout on mainnet
|
|
||||||
if (verifierId === 'Sourcify' || chainId === '1') { |
|
||||||
// Add keys not defined by user
|
|
||||||
for (const key of Object.keys(DEFAULTS[verifierId])) { |
|
||||||
if (!verifiers[verifierId][key]) { |
|
||||||
verifiers[verifierId][key] = DEFAULTS[verifierId][key] |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
// Only apply default settings for Etherscan and Blockscout on mainnet
|
|
||||||
} else if (verifierId === 'Sourcify' || chainId === '1') { |
|
||||||
verifiers[verifierId] = DEFAULTS[verifierId] |
|
||||||
} |
|
||||||
} |
|
||||||
return { verifiers } |
|
||||||
} |
|
||||||
|
|
||||||
export function validConfiguration(chainSettings: ChainSettings | undefined, verifierId: VerifierIdentifier) { |
|
||||||
return !!chainSettings && !!chainSettings.verifiers[verifierId]?.apiUrl && (verifierId !== 'Etherscan' || !!chainSettings.verifiers[verifierId]?.apiKey) |
|
||||||
} |
|
@ -0,0 +1,17 @@ |
|||||||
|
{ |
||||||
|
"Sourcify": { |
||||||
|
"apiUrl": "https://sourcify.dev/server", |
||||||
|
"explorerUrl": "https://repo.sourcify.dev" |
||||||
|
}, |
||||||
|
"Etherscan": { |
||||||
|
"1": { |
||||||
|
"apiUrl": "https://api.etherscan.io", |
||||||
|
"explorerUrl": "https://etherscan.io" |
||||||
|
} |
||||||
|
}, |
||||||
|
"Blockscout": { |
||||||
|
"1": { |
||||||
|
"apiUrl": "https://eth.blockscout.com" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
import type { ChainSettings, ContractVerificationSettings, SettingsForVerifier, VerifierSettings } from '../types/SettingsTypes' |
||||||
|
import { VerifierIdentifier, VERIFIERS } from '../types/VerificationTypes' |
||||||
|
import DEFAULT_APIS from './default-apis.json' |
||||||
|
|
||||||
|
export function mergeChainSettingsWithDefaults(chainId: string, userSettings: ContractVerificationSettings): ChainSettings { |
||||||
|
const verifiers: SettingsForVerifier = {} |
||||||
|
|
||||||
|
for (const verifierId of VERIFIERS) { |
||||||
|
const userSetting: VerifierSettings = userSettings.chains[chainId]?.verifiers[verifierId] ?? {} |
||||||
|
|
||||||
|
verifiers[verifierId] = { ...userSetting } |
||||||
|
|
||||||
|
let defaultsForVerifier: VerifierSettings |
||||||
|
if (verifierId === 'Sourcify') { |
||||||
|
defaultsForVerifier = DEFAULT_APIS['Sourcify'] |
||||||
|
} else { |
||||||
|
defaultsForVerifier = DEFAULT_APIS[verifierId][chainId] ?? {} |
||||||
|
} |
||||||
|
|
||||||
|
// Prefer user settings over defaults
|
||||||
|
verifiers[verifierId] = Object.assign({}, defaultsForVerifier, userSetting) |
||||||
|
} |
||||||
|
return { verifiers } |
||||||
|
} |
||||||
|
|
||||||
|
export function validConfiguration(chainSettings: ChainSettings | undefined, verifierId: VerifierIdentifier) { |
||||||
|
return !!chainSettings && !!chainSettings.verifiers[verifierId]?.apiUrl && (verifierId !== 'Etherscan' || !!chainSettings.verifiers[verifierId]?.apiKey) |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
export * from './default-settings' |
Loading…
Reference in new issue