HarryR / panautomata

Cross-chain proofs and atomic transactions
GNU General Public License v3.0
18 stars 2 forks source link

Embed contract ABI files in python project, use pkg_resources #24

Open HarryR opened 6 years ago

HarryR commented 6 years ago

This means that the whole project can be bundled into a .egg or .wheel file, or checked out from the git repo without having to build the Solidity side.

This avoids things like:

link_b = rpc_b.proxy('../solidity/build/contracts/LithiumLink.json', LINK_ADDRESS)
bob = rpc_b.proxy('../solidity/build/contracts/ExamplePingPongB.json', CONTRACT_B, ACCOUNT_A)

I want to avoid code generation, so just loading the ABI file and using it via SolProxy is good enough.

It may be an option to specify some kind of ABI load path for EthJsonRpc for use with SolProxy, e.g.:

rpc.proxy('LithiumLink')

Will find the LithiumLink.abi file from the correct place and load that.

Another problem is making sure the build system updates the ABI files in the Python package whenever the Solidity side changes.

One potential solution would be to embed the ABI JSON as a python dictionary within a module, and ensure that this is updated whenever a contract is built.

e.g. if it auto-generates the solidity_contracts module, then you could do solidity_contracts.LithiumLink(rpc, account) instead of rpc.proxy('path-to-LithiumLink', account) etc. That is code generation, but makes life easier and doesn't require pkg_resources fudgery.