commit 320c9fdde9ea20beacf417078d4fd5eece9c60f9
parent 689552a05eb3b0d8c587b7bd292b1cd0630e1cb0
Author: nolash <dev@holbrook.no>
Date: Sat, 17 Apr 2021 11:13:58 +0200
Rearrange code, add owned interface
Diffstat:
12 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/python/.gitignore b/python/.gitignore
@@ -0,0 +1,6 @@
+gmon.out
+__pycache__
+*.pyc
+build/
+dist/
+*.egg-info
diff --git a/python/eth_owner/__init__.py b/python/eth_owner/__init__.py
@@ -0,0 +1,2 @@
+from .owned import Owned
+from eth_owner.data import data_dir
diff --git a/python/eth_void_owner/data/Owned.bin b/python/eth_owner/data/Owned.bin
diff --git a/python/eth_void_owner/data/Owned.json b/python/eth_owner/data/Owned.json
diff --git a/python/eth_void_owner/data/VoidOwner.bin b/python/eth_owner/data/VoidOwner.bin
diff --git a/python/eth_void_owner/data/VoidOwner.json b/python/eth_owner/data/VoidOwner.json
diff --git a/python/eth_void_owner/data/__init__.py b/python/eth_owner/data/__init__.py
diff --git a/python/eth_owner/owned.py b/python/eth_owner/owned.py
@@ -0,0 +1,63 @@
+# standard imports
+import logging
+import json
+import os
+
+# external imports
+from chainlib.eth.tx import (
+ TxFactory,
+ TxFormat,
+ )
+from chainlib.eth.contract import (
+ ABIContractEncoder,
+ ABIContractDecoder,
+ ABIContractType,
+ abi_decode_single,
+ )
+from chainlib.eth.constant import ZERO_ADDRESS
+from chainlib.jsonrpc import (
+ jsonrpc_template,
+ )
+
+logg = logging.getLogger()
+
+moddir = os.path.dirname(__file__)
+datadir = os.path.join(moddir, 'data')
+
+
+class Owned(TxFactory):
+
+ interfaces = None
+
+ def owner(self, contract_address, idx, sender_address=ZERO_ADDRESS):
+ o = jsonrpc_template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('owner')
+ data = add_0x(enc.get())
+ tx = self.template(sender_address, contract_address)
+ tx = self.set_code(tx, data)
+ o['params'].append(self.normalize(tx))
+ return o
+
+
+ def transfer_ownership(self, sender_address, contract_address, address, tx_format=TxFormat.JSONRPC):
+ enc = ABIContractEncoder()
+ enc.method('transferOwnership')
+ enc.typ(ABIContractType.ADDRESS)
+ enc.address(address)
+ data = enc.get()
+ tx = self.template(sender_address, contract_address, use_nonce=True)
+ tx = self.set_code(tx, data)
+ tx = self.finalize(tx, tx_format)
+ return tx
+
+
+ def accept_ownership(self, sender_address, contract_address, address, tx_format=TxFormat.JSONRPC):
+ enc = ABIContractEncoder()
+ enc.method('acceptOwnership')
+ data = enc.get()
+ tx = self.template(sender_address, contract_address, use_nonce=True)
+ tx = self.set_code(tx, data)
+ tx = self.finalize(tx, tx_format)
+ return tx
diff --git a/python/eth_void_owner/interface.py b/python/eth_owner/void.py
diff --git a/python/eth_void_owner/__init__.py b/python/eth_void_owner/__init__.py
@@ -1,2 +0,0 @@
-from .interface import VoidOwner
-from eth_void_owner.data import data_dir
diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py
@@ -26,8 +26,9 @@ from chainlib.eth.contract import (
from hexathon import add_0x
# local imports
-from eth_void_owner import (
- VoidOwner,
+from eth_owner.void import VoidOwner
+from eth_owner import (
+ Owned,
data_dir,
)
diff --git a/solidity/Makefile b/solidity/Makefile
@@ -12,7 +12,7 @@ test: all
python ../python/tests/test_basic.py
install: all
- cp -v VoidOwner.{json,bin} ../python/eth_void_owner/data/
- cp -v Owned.{json,bin} ../python/eth_void_owner/data/
+ cp -v VoidOwner.{json,bin} ../python/eth_owner/data/
+ cp -v Owned.{json,bin} ../python/eth_owner/data/
.PHONY: test install