Skip to content

Commit

Permalink
Add a script to generate ABI files
Browse files Browse the repository at this point in the history
and use it to fix compilation error due to incomplete ABI json.
  • Loading branch information
DemiMarie committed Feb 28, 2019
1 parent d594e94 commit 574578b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
25 changes: 24 additions & 1 deletion ethcore/res/contracts/validator_set_aura.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,28 @@
],
"name": "InitiateChange",
"type": "event"
},
{
"constant": true,
"inputs": [
{
"name": "_maliciousMiningAddress",
"type": "address"
},
{
"name": "_blockNumber",
"type": "uint256"
}
],
"name": "maliceReportedForBlock",
"outputs": [
{
"name": "",
"type": "address[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
]
7 changes: 7 additions & 0 deletions ethcore/res/contracts/validator_set_aura.json.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
getValidators
initiateChange
emitInitiateChangeCallable
emitInitiateChange
maliceReportedForBlock
finalizeChange
InitiateChange
4 changes: 2 additions & 2 deletions ethcore/src/engines/validator_set/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ impl ValidatorSet for ValidatorSafeContract {
vec![(self.contract_address, data)]
};
let queued_reports = self.queued_reports.lock();
for i in queued_reports.iter() {
returned_transactions.push((self.contract_address, i.2.clone()))
for (_address, _block, data) in queued_reports.iter().take(10) {
returned_transactions.push((self.contract_address, data.clone()))
}
Ok(returned_transactions)
}
Expand Down
32 changes: 32 additions & 0 deletions scripts/get-abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python3 --
"""
Get the ABI of a contract JSON file (specified in ``sys.argv[1]``) and write it
to ``sys.argv[2]``. Both ``sys.argv[1]`` and ``sys.argv[2]`` must end in
.json. Additionally, a file named ``sys.argv[2] + '.txt'`` must exist. It
must have one line for each symbol in the ABI that will be placed in the output.
The input file must be encoded in UTF-8, and the output file will be encoded in
UTF-8.
"""

__version__ = '0.0.1'
__all__ = ['main']
import re
_re = re.compile(r'\A[A-Za-z_][A-Za-z0-9_]*\n\Z')
def main(input_file, output_file, used_file):
import os, json
_type, _dict, _open, _set = type, dict, open, set
with _open(used_file, 'r', encoding='UTF-8') as used_stream:
used_functions = _set(i.strip() for i in used_stream if _re.match(i))
with _open(input_file, 'r', encoding='UTF-8') as input_stream, \
_open(output_file, 'w', encoding='UTF-8') as output_stream:
my_list = [i for i in json.load(input_stream)['abi']
if _type(i) is _dict and i.get('name') in used_functions]
json.dump(my_list, output_stream, sort_keys=True, indent = '\t')
if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
print('must have 2 arguments, not {}'.format(len(sys.argv) - 1),
file=sys.stderr)
sys.exit(1)
main(sys.argv[1], sys.argv[2], sys.argv[2] + '.txt')

0 comments on commit 574578b

Please sign in to comment.