eth-owned

EIP-173 interface and tools for chainlib-eth
git clone git://holbrook.no/eth-owned.git
Log | Files | Refs

commit 46138507d584e798087439bf73f6958aba0f40b3
parent 1ef1e6bd960087eaf1c1ea4d4c425302dde695db
Author: lash <dev@holbrook.no>
Date:   Tue, 14 Feb 2023 06:54:34 +0000

Transfer ownership final zcheme

Diffstat:
Mpython/CHANGELOG | 2++
Mpython/eth_owned/data/Owned.bin | 4++--
Mpython/eth_owned/data/Owned.json | 2+-
Mpython/eth_owned/owned.py | 7+++++--
Mpython/requirements.txt | 4++--
Mpython/setup.cfg | 4++--
Mpython/tests/test_owned.py | 15+++++++++++++++
Msolidity/Owned.sol | 11+++++++++++
8 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/python/CHANGELOG b/python/CHANGELOG @@ -1,3 +1,5 @@ +- 0.0.5 + * Enable finalization of ownership transfer - 0.0.4 * Upgrade dependencies - 0.0.3 diff --git a/python/eth_owned/data/Owned.bin b/python/eth_owned/data/Owned.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061041d806100606000396000f3fe608060405234801561001057600080fd5b506004361061005e576000357c01000000000000000000000000000000000000000000000000000000009004806379ba5097146100635780638da5cb5b14610081578063f2fde38b1461009f575b600080fd5b61006b6100cf565b6040516100789190610312565b60405180910390f35b610089610233565b604051610096919061036e565b60405180910390f35b6100b960048036038101906100b491906103ba565b610257565b6040516100c69190610312565b60405180910390f35b6000803373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461012c57600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600191505090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146102b157600080fd5b81600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550919050565b60008115159050919050565b61030c816102f7565b82525050565b60006020820190506103276000830184610303565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006103588261032d565b9050919050565b6103688161034d565b82525050565b6000602082019050610383600083018461035f565b92915050565b600080fd5b6103978161034d565b81146103a257600080fd5b50565b6000813590506103b48161038e565b92915050565b6000602082840312156103d0576103cf610389565b5b60006103de848285016103a5565b9150509291505056fea2646970667358221220f1cf2c4e714f722327a0f8c80ce6274ab8a035ca12beca97595282eae719ed3c64736f6c63430008110033 -\ No newline at end of file +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506105c1806100606000396000f3fe608060405234801561001057600080fd5b5060043610610069576000357c010000000000000000000000000000000000000000000000000000000090048063069b17751461006e57806379ba50971461009e5780638da5cb5b146100bc578063f2fde38b146100da575b600080fd5b610088600480360381019061008391906104a5565b61010a565b60405161009591906104ed565b60405180910390f35b6100a66101c5565b6040516100b391906104ed565b60405180910390f35b6100c461035f565b6040516100d19190610517565b60405180910390f35b6100f460048036038101906100ef91906104a5565b610383565b60405161010191906104ed565b60405180910390f35b60003073ffffffffffffffffffffffffffffffffffffffff1663f2fde38b836040518263ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016101619190610517565b6020604051808303816000875af1158015610180573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101a4919061055e565b5060018060146101000a81548160ff021916908360ff160217905550919050565b6000803373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461022257600080fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360018060149054906101000a900460ff1660ff1603610357576002600160146101000a81548160ff021916908360ff1602179055505b600191505090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146103dd57600080fd5b6002600160149054906101000a900460ff1660ff16106103fc57600080fd5b81600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061047282610447565b9050919050565b61048281610467565b811461048d57600080fd5b50565b60008135905061049f81610479565b92915050565b6000602082840312156104bb576104ba610442565b5b60006104c984828501610490565b91505092915050565b60008115159050919050565b6104e7816104d2565b82525050565b600060208201905061050260008301846104de565b92915050565b61051181610467565b82525050565b600060208201905061052c6000830184610508565b92915050565b61053b816104d2565b811461054657600080fd5b50565b60008151905061055881610532565b92915050565b60006020828403121561057457610573610442565b5b600061058284828501610549565b9150509291505056fea2646970667358221220d8ee713b16e7ffab13ce45a1c39c02a8ab7914c4620a7c5b7aba5f1e3a8ef3e464736f6c63430008110033 +\ No newline at end of file diff --git a/python/eth_owned/data/Owned.json b/python/eth_owned/data/Owned.json @@ -1 +1 @@ -[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"_newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"_newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnershipFinal","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/eth_owned/owned.py b/python/eth_owned/owned.py @@ -19,9 +19,12 @@ from chainlib.eth.constant import ZERO_ADDRESS class EIP173(TxFactory): - def transfer_ownership(self, contract_address, sender_address, new_owner_address, tx_format=TxFormat.JSONRPC): + def transfer_ownership(self, contract_address, sender_address, new_owner_address, final=False, tx_format=TxFormat.JSONRPC): enc = ABIContractEncoder() - enc.method('transferOwnership') + if final: + enc.method('transferOwnershipFinal') + else: + enc.method('transferOwnership') enc.typ(ABIContractType.ADDRESS) enc.address(new_owner_address) data = add_0x(enc.get()) diff --git a/python/requirements.txt b/python/requirements.txt @@ -1,3 +1,3 @@ confini~=0.6.3 -chainlib-eth~=0.4.3 -funga-eth==0.6.2 +chainlib-eth~=0.4.7 +funga-eth==0.6.4 diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-owned -version = 0.0.4 +version = 0.0.5 description = EIP 173 interface and tools author = Louis Holbrook author_email = dev@holbrook.no @@ -15,7 +15,7 @@ classifiers = Intended Audience :: Developers License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) Topic :: Internet - Topic :: Development :: Libraries + Topic :: Software Development :: Libraries #Topic :: Blockchain :: EVM license = GPL3 licence_files = diff --git a/python/tests/test_owned.py b/python/tests/test_owned.py @@ -130,5 +130,20 @@ class TestOwned(EthTesterCase): self.assertEqual(owner, strip_0x(self.address)) + def test_ownership_final(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn) + gas_oracle = OverrideGasOracle(limit=8000000, conn=self.conn) + c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) + (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True) + r = self.conn.do(o) + + c = Owned(self.chain_spec, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, signer=self.signer) + (tx_hash_hex, o) = c.transfer_ownership(self.address, self.accounts[0], self.accounts[1], final=True) + r = self.conn.do(o) + o = receipt(tx_hash_hex) + r = self.conn.do(o) + self.assertEqual(r['status'], 0) + + if __name__ == '__main__': unittest.main() diff --git a/solidity/Owned.sol b/solidity/Owned.sol @@ -9,6 +9,8 @@ contract Owned { address newOwner; + uint8 finalOwner; + // EIP173 event OwnershipTransferred(address indexed _previousOwner, address indexed _newOwner); @@ -19,9 +21,15 @@ contract Owned { // EIP173 function transferOwnership(address _newOwner) public returns (bool) { require(owner == msg.sender); + require(finalOwner < 2); newOwner = _newOwner; } + function transferOwnershipFinal(address _newOwner) public returns (bool) { + this.transferOwnership(_newOwner); + finalOwner = 1; + } + function acceptOwnership() public returns (bool) { address oldOwner; @@ -29,6 +37,9 @@ contract Owned { oldOwner = owner; owner = newOwner; emit OwnershipTransferred(oldOwner, owner); + if (finalOwner == 1) { + finalOwner = 2; + } return true; } }