Skip to content

Commit

Permalink
Added an example how to expand source code files into Populus ABI blob
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Dec 14, 2018
1 parent de277af commit 5059b26
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/source/other.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,41 @@ Private key must be **without** 0x prefixed hex format.
More information

* http://ethereum.stackexchange.com/a/10020/620

Flatting source code for ABI files
==================================

Here is a snippet that will expand the source code of all contracts for the generated ``build/contracts.json`` file. This will allow easier verification (reproducible builds) when using ABI data.

You can run from Python shell:

.. code-block:: python
import populus
import json
from ico.importexpand import expand_contract_imports
p = populus.Project()
data = json.load(open("build/contracts.json", "rt"))
for contract in data.values():
# This was a source code file for an abstract contract
if not contract["metadata"]:
continue
targets = contract["metadata"]["settings"]["compilationTarget"]
contract_file = list(targets.keys())[0] # "contracts/AMLToken.sol": "AMLToken"
# Eliminate base path, as this will be set by expand_contract_imports
if "zeppelin/" not in contract_file:
contract_file = contract_file.replace("contracts/", "")
else:
pass
# contract_file = contract_file.replace("zeppelin/", "zeppelin/contracts/")
source, imports = expand_contract_imports(p, contract_file)
contract["source"] = source
# Write out expanded ABI data
json.dump(data, open("build/contracts-flattened.json", "wt"))

0 comments on commit 5059b26

Please sign in to comment.