Closed SonOfMosiah closed 8 months ago
Sure! Is there anything equivalent in sourcify that we should add?
The current Sourcify endpoint also returns some of this metadata:
sample:
{
"compiler": {
"version": "0.4.24+commit.e67f0147"
},
"language": "Solidity",
"output": {
"abi": [
{
"constant": false,
"inputs": [
{
"name": "newImplementation",
"type": "address"
}
],
"name": "upgradeTo",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newImplementation",
"type": "address"
},
{
"name": "data",
"type": "bytes"
}
],
"name": "upgradeToAndCall",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "implementation",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newAdmin",
"type": "address"
}
],
"name": "changeAdmin",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "admin",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_implementation",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"payable": true,
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "previousAdmin",
"type": "address"
},
{
"indexed": false,
"name": "newAdmin",
"type": "address"
}
],
"name": "AdminChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "implementation",
"type": "address"
}
],
"name": "Upgraded",
"type": "event"
}
],
"devdoc": {
"methods": {
"admin()": {
"return": "The address of the proxy admin.\r"
},
"changeAdmin(address)": {
"details": "Changes the admin of the proxy.\r Only the current admin can call this function.\r",
"params": {
"newAdmin": "Address to transfer proxy administration to.\r"
}
},
"implementation()": {
"return": "The address of the implementation.\r"
},
"upgradeTo(address)": {
"details": "Upgrade the backing implementation of the proxy.\r Only the admin can call this function.\r",
"params": {
"newImplementation": "Address of the new implementation.\r"
}
},
"upgradeToAndCall(address,bytes)": {
"details": "Upgrade the backing implementation of the proxy and call a function\r on the new implementation.\r This is useful to initialize the proxied contract.\r",
"params": {
"data": "Data to send as msg.data in the low level call.\r It should include the signature and the parameters of the function to be\r called, as described in\r https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector-and-argument-encoding.\r",
"newImplementation": "Address of the new implementation.\r"
}
}
},
"title": "FiatTokenProxy\r"
},
"userdoc": {
"methods": {}
}
},
"settings": {
"compilationTarget": {
"FiatTokenProxy.sol": "FiatTokenProxy"
},
"evmVersion": "byzantium",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
},
"sources": {
"FiatTokenProxy.sol": {
"keccak256": "0xea48c87ceb370ce992a18915b0ca1a12dc8162b457ba423d94206beebcd5355f",
"urls": [
"bzzr://219994f5e288ccb13071b697747f5858a875687050ac8be60b4b6a60bb84079a"
]
}
},
"version": 1
}
HMM ideally we'd come up with a new function that we can implement for both which normalizes the output in some useful way.
But if that's not something that's exciting for you at the moment, could just do an internal-ish helper for just Etherscan, like ._getSourceCode(...)
which doesn't normalize yet but you can use for now, then we can wrap it with a normalizing more public-facing helper later.
Looks like the common output fields that we could normalize are the following:
We could do an extra step to query the source files and return the source code from Sourcify to be added to this.
I like that list. What do you think is a good name for this loader function? Some ideas: loader.getContract(address)
, loader.getDeployment(address)
We could start without the source files, maybe add it in later if people want it.
I'd be in favor of getContract(address)
or getContractMetadata(address)
Let's go for getContract
and we can slowly stop using loadABI maybe.
Fixed in #77
Would love to see an option to call
getsourcecode
in the Etherscan loader. Helpful for retrieving the contract name + other metadata (as well as the abi).Happy to contribute to a PR if this is a welcomed feature.
Sample response for getsourcecode: