erc20-transfer-authorization

Simple approval escrow for ERC20 spending
Log | Files | Refs

commit 5603ac10ded4da8c954e167e825b222f8b524098
parent 97da46bb09134cb7cabd0954c66a64931f829d76
Author: nolash <dev@holbrook.no>
Date:   Sun,  6 Dec 2020 17:24:32 +0100

Rename module

Diffstat:
Mpython/CHANGELOG | 2++
Rpython/simple_multisig/data/SimpleMultisig.abi.json -> python/erc20_approval_escrow/data/ERC20ApprovalEscrow.abi.json | 0
Apython/erc20_approval_escrow/data/ERC20ApprovalEscrow.bin | 2++
Rpython/simple_multisig/data/GiftableToken.abi.json -> python/erc20_approval_escrow/data/GiftableToken.abi.json | 0
Rpython/simple_multisig/data/GiftableToken.bin -> python/erc20_approval_escrow/data/GiftableToken.bin | 0
Apython/erc20_approval_escrow/runnable/deploy.py | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpython/setup.cfg | 15++++++++++-----
Dpython/simple_multisig/data/SimpleMultisig.bin | 2--
Dpython/simple_multisig/runnable/deploy.py | 65-----------------------------------------------------------------
Mpython/tests/test_app.py | 16++++++++--------
Rsolidity/SimpleMultisig.abi.json -> solidity/ERC20ApprovalEscrow.abi.json | 0
Asolidity/ERC20ApprovalEscrow.bin | 2++
Asolidity/ERC20ApprovalEscrow.sol | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msolidity/Makefile | 9++++-----
Dsolidity/SimpleMultisig.bin | 2--
Dsolidity/SimpleMultisig.sol | 75---------------------------------------------------------------------------
16 files changed, 168 insertions(+), 162 deletions(-)

diff --git a/python/CHANGELOG b/python/CHANGELOG @@ -1,2 +1,4 @@ +- 0.0.2 + * Rename module - 0.0.1 * Add deployer diff --git a/python/simple_multisig/data/SimpleMultisig.abi.json b/python/erc20_approval_escrow/data/ERC20ApprovalEscrow.abi.json diff --git a/python/erc20_approval_escrow/data/ERC20ApprovalEscrow.bin b/python/erc20_approval_escrow/data/ERC20ApprovalEscrow.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50604051610f54380380610f548339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b8382019150602082018581111561006957600080fd5b825186602082028301116401000000008211171561008657600080fd5b8083526020830192505050908051906020019060200280838360005b838110156100bd5780820151818401526020810190506100a2565b5050505090500160405250505060005b815181101561014e576001600260008484815181106100e857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506100cd565b50600160008190555050610ded806101676000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80630a144391146100675780636c355091146100c157806381d12c5814610143578063b8adaa11146101e3578063f6d713dd14610227578063fe0d94c114610245575b600080fd5b6100a96004803603602081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610289565b60405180821515815260200191505060405180910390f35b61012d600480360360608110156100d757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506102a9565b6040518082815260200191505060405180910390f35b61016f6004803603602081101561015957600080fd5b81019080803590602001909291905050506104b7565b604051808681526020018573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019550505050505060405180910390f35b61020f600480360360208110156101f957600080fd5b810190808035906020019092919050505061054d565b60405180821515815260200191505060405180910390f35b61022f61097f565b6040518082815260200191505060405180910390f35b6102716004803603602081101561025b57600080fd5b8101908080359060200190929190505050610985565b60405180821515815260200191505060405180910390f35b60026020528060005260406000206000915054906101000a900460ff1681565b600080600160008054815260200190815260200160002090506000548160000181905550848160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550338160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550838160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082816004018190555060008081548092919060010191905055508060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168160020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168260010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84600401548560000154604051808381526020018281526020019250505060405180910390a480600001549150509392505050565b60016020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661060e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f4552525f4e4f5f4143434553530000000000000000000000000000000000000081525060200191505060405180910390fd5b6000600160008481526020019081526020016000209050600081600001541161069f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f4552525f494e56414c49445f524551554553540000000000000000000000000081525060200191505060405180910390fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106108275780518252602082019150602081019050602083039250610804565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610889576040519150601f19603f3d011682016040523d82523d6000602084013e61088e565b606091505b50915091508161089a57fe5b7f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560048201600090555050819350505050919050565b60005481565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610a46576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f4552525f4e4f5f4143434553530000000000000000000000000000000000000081525060200191505060405180910390fd5b60006001600084815260200190815260200160002090506000816000015411610ad7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f4552525f494e56414c49445f524551554553540000000000000000000000000081525060200191505060405180910390fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b60208310610c5f5780518252602082019150602081019050602083039250610c3c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610cc1576040519150601f19603f3d011682016040523d82523d6000602084013e610cc6565b606091505b509150915081610cd257fe5b7fa445ec1ee84565906bc8646dcb62f6d1a75fc7a782a03e72220fb97f60ba89ab83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505081935050505091905056fea264697066735822122027854a054b06dcbba643ec3336be99a459dab354eee6bab60354f36d6e9f233464736f6c63430007050033 +\ No newline at end of file diff --git a/python/simple_multisig/data/GiftableToken.abi.json b/python/erc20_approval_escrow/data/GiftableToken.abi.json diff --git a/python/simple_multisig/data/GiftableToken.bin b/python/erc20_approval_escrow/data/GiftableToken.bin diff --git a/python/erc20_approval_escrow/runnable/deploy.py b/python/erc20_approval_escrow/runnable/deploy.py @@ -0,0 +1,65 @@ +"""Deploys erc20 approval escrow contract + +.. moduleauthor:: Louis Holbrook <dev@holbrook.no> +.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 + +""" + +# standard imports +import os +import json +import argparse +import logging + +# third-party imports +import web3 + + +logging.basicConfig(level=logging.WARNING) +logg = logging.getLogger() + +logging.getLogger('web3').setLevel(logging.WARNING) +logging.getLogger('urllib3').setLevel(logging.WARNING) + +argparser = argparse.ArgumentParser() +argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)') +argparser.add_argument('-a', '--approver', dest='a', action='append', type=str, help='approver to add') +argparser.add_argument('--contracts-dir', dest='contracts_dir', default='.', help='Directory containing bytecode and abi') +argparser.add_argument('-v', action='store_true', help='Be verbose') +args = argparser.parse_args() + +if args.v: + logg.setLevel(logging.DEBUG) + +def main(): + w3 = web3.Web3(web3.Web3.HTTPProvider(args.p)) + + f = open(os.path.join(args.contracts_dir, 'ERC20ApprovalEscrow.abi.json'), 'r') + abi = json.load(f) + f.close() + + f = open(os.path.join(args.contracts_dir, 'ERC20ApprovalEscrow.bin'), 'r') + bytecode = f.read() + f.close() + + w3.eth.defaultAccount = w3.eth.accounts[0] + + c = w3.eth.contract(abi=abi, bytecode=bytecode) + + approvers = [w3.eth.accounts[0]] + if args.a != None: + for a in args.a: + approvers.append(a) + + tx_hash = c.constructor(approvers).transact({'from': w3.eth.accounts[0]}) + + rcpt = w3.eth.getTransactionReceipt(tx_hash) + + address = rcpt.contractAddress + #c = w3.eth.contract(abi=abi, address=address) + + print(address) + + +if __name__ == '__main__': + main() diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,7 +1,7 @@ [metadata] -name = simple-multisig -version = 0.0.1 -description = Simple approval escrow for ERC20 spend approvals +name = erc20-approval-escrow +version = 0.0.2 +description = Simple approval escrow for ERC20 spend approval author = Louis Holbrook author_email = dev@holbrook.no url = https://gitlab.com/nolash/simple-multisig @@ -23,13 +23,18 @@ licence_files = [options] python_requires = >= 3.6 packages = - simple_multisig.runnable + erc20_approval_escrow.runnable install_requires = web3==5.12.2 tests_require = eth-tester==0.5.0b2 py-evm==0.3.0a20 +[options.extras_require] +testing = + eth-tester==0.5.0b2 + py-evm==0.3.0a20 + [options.entry_points] console_scripts = - simple-multisig-deploy = simple_multisig.runnable.deploy:main + simple-multisig-deploy = erc20_approval_escrow.runnable.deploy:main diff --git a/python/simple_multisig/data/SimpleMultisig.bin b/python/simple_multisig/data/SimpleMultisig.bin @@ -1 +0,0 @@ -608060405234801561001057600080fd5b50604051610db0380380610db08339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b8382019150602082018581111561006957600080fd5b825186602082028301116401000000008211171561008657600080fd5b8083526020830192505050908051906020019060200280838360005b838110156100bd5780820151818401526020810190506100a2565b5050505090500160405250505060005b815181101561014e576001600260008484815181106100e857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506100cd565b50600160008190555050610c49806101676000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80630a144391146100675780636c355091146100c157806381d12c5814610143578063b8adaa11146101e3578063f6d713dd14610227578063fe0d94c114610245575b600080fd5b6100a96004803603602081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610289565b60405180821515815260200191505060405180910390f35b61012d600480360360608110156100d757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506102a9565b6040518082815260200191505060405180910390f35b61016f6004803603602081101561015957600080fd5b81019080803590602001909291905050506104b7565b604051808681526020018573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019550505050505060405180910390f35b61020f600480360360208110156101f957600080fd5b810190808035906020019092919050505061054d565b60405180821515815260200191505060405180910390f35b61022f6108ad565b6040518082815260200191505060405180910390f35b6102716004803603602081101561025b57600080fd5b81019080803590602001909291905050506108b3565b60405180821515815260200191505060405180910390f35b60026020528060005260406000206000915054906101000a900460ff1681565b600080600160008054815260200190815260200160002090506000548160000181905550848160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550338160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550838160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082816004018190555060008081548092919060010191905055508060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168160020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168260010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84600401548560000154604051808381526020018281526020019250505060405180910390a480600001549150509392505050565b60016020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166105a557600080fd5b600060016000848152602001908152602001600020905060008160000154116105cd57600080fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106107555780518252602082019150602081019050602083039250610732565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146107b7576040519150601f19603f3d011682016040523d82523d6000602084013e6107bc565b606091505b5091509150816107c857fe5b7f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560048201600090555050819350505050919050565b60005481565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661090b57600080fd5b6000600160008481526020019081526020016000209050600081600001541161093357600080fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b60208310610abb5780518252602082019150602081019050602083039250610a98565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610b1d576040519150601f19603f3d011682016040523d82523d6000602084013e610b22565b606091505b509150915081610b2e57fe5b7fa445ec1ee84565906bc8646dcb62f6d1a75fc7a782a03e72220fb97f60ba89ab83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505081935050505091905056fea2646970667358221220602e22c4a3c6f16979c452060dfbb623b84957d760a0bda14e3d5356f5d4ca4064736f6c63430007050033 -\ No newline at end of file diff --git a/python/simple_multisig/runnable/deploy.py b/python/simple_multisig/runnable/deploy.py @@ -1,65 +0,0 @@ -"""Deploys simple multisig contract - -.. moduleauthor:: Louis Holbrook <dev@holbrook.no> -.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 - -""" - -# standard imports -import os -import json -import argparse -import logging - -# third-party imports -import web3 - - -logging.basicConfig(level=logging.WARNING) -logg = logging.getLogger() - -logging.getLogger('web3').setLevel(logging.WARNING) -logging.getLogger('urllib3').setLevel(logging.WARNING) - -argparser = argparse.ArgumentParser() -argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)') -argparser.add_argument('-a', '--approver', dest='a', action='append', type=str, help='approver to add') -argparser.add_argument('--contracts-dir', dest='contracts_dir', default='.', help='Directory containing bytecode and abi') -argparser.add_argument('-v', action='store_true', help='Be verbose') -args = argparser.parse_args() - -if args.v: - logg.setLevel(logging.DEBUG) - -def main(): - w3 = web3.Web3(web3.Web3.HTTPProvider(args.p)) - - f = open(os.path.join(args.contracts_dir, 'SimpleMultisig.abi.json'), 'r') - abi = json.load(f) - f.close() - - f = open(os.path.join(args.contracts_dir, 'SimpleMultisig.bin'), 'r') - bytecode = f.read() - f.close() - - w3.eth.defaultAccount = w3.eth.accounts[0] - - c = w3.eth.contract(abi=abi, bytecode=bytecode) - - approvers = [w3.eth.accounts[0]] - if args.a != None: - for a in args.a: - approvers.append(a) - - tx_hash = c.constructor(approvers).transact({'from': w3.eth.accounts[0]}) - - rcpt = w3.eth.getTransactionReceipt(tx_hash) - - address = rcpt.contractAddress - #c = w3.eth.contract(abi=abi, address=address) - - print(address) - - -if __name__ == '__main__': - main() diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -25,11 +25,11 @@ class Test(unittest.TestCase): 'gas_limit': 9000000, }) - f = open(os.path.join(testdir, '../simple_multisig/data/SimpleMultisig.bin'), 'r') + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/ERC20ApprovalEscrow.bin'), 'r') bytecode = f.read() f.close() - f = open(os.path.join(testdir, '../simple_multisig/data/SimpleMultisig.abi.json'), 'r') + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/ERC20ApprovalEscrow.abi.json'), 'r') self.abi_wallet = json.load(f) f.close() @@ -45,11 +45,11 @@ class Test(unittest.TestCase): self.address_wallet = r.contractAddress - f = open(os.path.join(testdir, '../simple_multisig/data/GiftableToken.bin'), 'r') + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/GiftableToken.bin'), 'r') bytecode = f.read() f.close() - f = open(os.path.join(testdir, '../simple_multisig/data/GiftableToken.abi.json'), 'r') + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/GiftableToken.abi.json'), 'r') self.abi_token = json.load(f) f.close() @@ -90,7 +90,7 @@ class Test(unittest.TestCase): serial = int(log.data[66:], 16) self.eth_tester.mine_block() - with self.assertRaises(TypeError): + with self.assertRaises(eth_tester.exceptions.TransactionFailed): w.functions.execute(serial).transact({'from': self.w3.eth.accounts[0]}) @@ -111,7 +111,7 @@ class Test(unittest.TestCase): serial = int(log.data[66:], 16) self.eth_tester.mine_block() - with self.assertRaises(eth_abi.exceptions.InsufficientDataBytes): + with self.assertRaises(eth_tester.exceptions.TransactionFailed): w.functions.execute(serial).transact({'from': self.w3.eth.accounts[3]}) tx_hashh = w.functions.execute(serial).transact({'from': self.w3.eth.accounts[0]}) @@ -120,7 +120,7 @@ class Test(unittest.TestCase): self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[2]).call(), 90) self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[3]).call(), 10) - + def test_rejection(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) @@ -140,11 +140,11 @@ class Test(unittest.TestCase): tx_hash = w.functions.reject(serial).transact({'from': self.w3.eth.accounts[0]}) r = self.w3.eth.getTransactionReceipt(tx_hash) - print('logs {}'.format(r.logs)) self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[2]).call(), 100) self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[3]).call(), 0) self.assertEqual(t.functions.allowances(self.w3.eth.accounts[2], w.address).call(), 0) + if __name__ == '__main__': unittest.main() diff --git a/solidity/SimpleMultisig.abi.json b/solidity/ERC20ApprovalEscrow.abi.json diff --git a/solidity/ERC20ApprovalEscrow.bin b/solidity/ERC20ApprovalEscrow.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50604051610f54380380610f548339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b8382019150602082018581111561006957600080fd5b825186602082028301116401000000008211171561008657600080fd5b8083526020830192505050908051906020019060200280838360005b838110156100bd5780820151818401526020810190506100a2565b5050505090500160405250505060005b815181101561014e576001600260008484815181106100e857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506100cd565b50600160008190555050610ded806101676000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80630a144391146100675780636c355091146100c157806381d12c5814610143578063b8adaa11146101e3578063f6d713dd14610227578063fe0d94c114610245575b600080fd5b6100a96004803603602081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610289565b60405180821515815260200191505060405180910390f35b61012d600480360360608110156100d757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506102a9565b6040518082815260200191505060405180910390f35b61016f6004803603602081101561015957600080fd5b81019080803590602001909291905050506104b7565b604051808681526020018573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019550505050505060405180910390f35b61020f600480360360208110156101f957600080fd5b810190808035906020019092919050505061054d565b60405180821515815260200191505060405180910390f35b61022f61097f565b6040518082815260200191505060405180910390f35b6102716004803603602081101561025b57600080fd5b8101908080359060200190929190505050610985565b60405180821515815260200191505060405180910390f35b60026020528060005260406000206000915054906101000a900460ff1681565b600080600160008054815260200190815260200160002090506000548160000181905550848160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550338160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550838160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082816004018190555060008081548092919060010191905055508060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168160020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168260010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84600401548560000154604051808381526020018281526020019250505060405180910390a480600001549150509392505050565b60016020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661060e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f4552525f4e4f5f4143434553530000000000000000000000000000000000000081525060200191505060405180910390fd5b6000600160008481526020019081526020016000209050600081600001541161069f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f4552525f494e56414c49445f524551554553540000000000000000000000000081525060200191505060405180910390fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106108275780518252602082019150602081019050602083039250610804565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610889576040519150601f19603f3d011682016040523d82523d6000602084013e61088e565b606091505b50915091508161089a57fe5b7f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560048201600090555050819350505050919050565b60005481565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610a46576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f4552525f4e4f5f4143434553530000000000000000000000000000000000000081525060200191505060405180910390fd5b60006001600084815260200190815260200160002090506000816000015411610ad7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f4552525f494e56414c49445f524551554553540000000000000000000000000081525060200191505060405180910390fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b60208310610c5f5780518252602082019150602081019050602083039250610c3c565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610cc1576040519150601f19603f3d011682016040523d82523d6000602084013e610cc6565b606091505b509150915081610cd257fe5b7fa445ec1ee84565906bc8646dcb62f6d1a75fc7a782a03e72220fb97f60ba89ab83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505081935050505091905056fea264697066735822122027854a054b06dcbba643ec3336be99a459dab354eee6bab60354f36d6e9f233464736f6c63430007050033 +\ No newline at end of file diff --git a/solidity/ERC20ApprovalEscrow.sol b/solidity/ERC20ApprovalEscrow.sol @@ -0,0 +1,75 @@ +pragma solidity >=0.6.12; + +// SPDX-License-Identifier: GPL-3.0-or-later + +contract ERC20ApprovalEscrow { + struct Transaction { + uint256 serial; + address sender; + address recipient; + address token; + uint256 value; + } + uint256 public serial; + mapping(uint256 => Transaction) public requests; + mapping(address => bool) public approvers; + + event NewRequest(address indexed _sender, address indexed _recipient, address indexed _token, uint256 _value, uint256 _serial); + event NewExecution(uint256 serial); + event NewRejection(uint256 serial); + + constructor(address[] memory _approvers) public { + for (uint i = 0; i < _approvers.length; i++) { + approvers[_approvers[i]] = true; + } + serial = 1; + } + + function request(address _recipient, address _token, uint256 _value) public returns (uint256) { + Transaction storage txx = requests[serial]; + + txx.serial = serial; + txx.recipient = _recipient; + txx.sender = msg.sender; + txx.token = _token; + txx.value = _value; + + serial++; + + emit NewRequest(txx.sender, txx.recipient, txx.token, txx.value, txx.serial); + + return txx.serial; + } + + function execute(uint256 _serial) public returns (bool) { + require(approvers[msg.sender], 'ERR_NO_ACCESS'); + + Transaction storage txx = requests[_serial]; + require(txx.serial > 0, 'ERR_INVALID_REQUEST'); + + (bool success, bytes memory _) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.recipient, txx.value)); + assert(success); + + emit NewExecution(txx.serial); + + delete requests[txx.serial]; + + return success; + } + + function reject(uint256 _serial) public returns (bool) { + require(approvers[msg.sender], 'ERR_NO_ACCESS'); + + Transaction storage txx = requests[_serial]; + require(txx.serial > 0, 'ERR_INVALID_REQUEST'); + + (bool success, bytes memory _) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.sender, txx.value)); + assert(success); + + emit NewRejection(txx.serial); + + delete requests[txx.serial]; + + return success; + } +} diff --git a/solidity/Makefile b/solidity/Makefile @@ -1,8 +1,7 @@ all: - solc --bin SimpleMultisig.sol | awk 'NR>3' > SimpleMultisig.bin - truncate -s -1 SimpleMultisig.bin - solc --abi SimpleMultisig.sol | awk 'NR>3' > SimpleMultisig.abi.json + solc --bin ERC20ApprovalEscrow.sol | awk 'NR>3' > ERC20ApprovalEscrow.bin + truncate -s -1 ERC20ApprovalEscrow.bin + solc --abi ERC20ApprovalEscrow.sol | awk 'NR>3' > ERC20ApprovalEscrow.abi.json install: all - cp -v *{json,bin} ../python/simple_multisig/data/ - + cp -v *{json,bin} ../python/erc20_approval_escrow/data/ diff --git a/solidity/SimpleMultisig.bin b/solidity/SimpleMultisig.bin @@ -1 +0,0 @@ -608060405234801561001057600080fd5b50604051610db0380380610db08339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b8382019150602082018581111561006957600080fd5b825186602082028301116401000000008211171561008657600080fd5b8083526020830192505050908051906020019060200280838360005b838110156100bd5780820151818401526020810190506100a2565b5050505090500160405250505060005b815181101561014e576001600260008484815181106100e857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806001019150506100cd565b50600160008190555050610c49806101676000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80630a144391146100675780636c355091146100c157806381d12c5814610143578063b8adaa11146101e3578063f6d713dd14610227578063fe0d94c114610245575b600080fd5b6100a96004803603602081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610289565b60405180821515815260200191505060405180910390f35b61012d600480360360608110156100d757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506102a9565b6040518082815260200191505060405180910390f35b61016f6004803603602081101561015957600080fd5b81019080803590602001909291905050506104b7565b604051808681526020018573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019550505050505060405180910390f35b61020f600480360360208110156101f957600080fd5b810190808035906020019092919050505061054d565b60405180821515815260200191505060405180910390f35b61022f6108ad565b6040518082815260200191505060405180910390f35b6102716004803603602081101561025b57600080fd5b81019080803590602001909291905050506108b3565b60405180821515815260200191505060405180910390f35b60026020528060005260406000206000915054906101000a900460ff1681565b600080600160008054815260200190815260200160002090506000548160000181905550848160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550338160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550838160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082816004018190555060008081548092919060010191905055508060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168160020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168260010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84600401548560000154604051808381526020018281526020019250505060405180910390a480600001549150509392505050565b60016020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166105a557600080fd5b600060016000848152602001908152602001600020905060008160000154116105cd57600080fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106107555780518252602082019150602081019050602083039250610732565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146107b7576040519150601f19603f3d011682016040523d82523d6000602084013e6107bc565b606091505b5091509150816107c857fe5b7f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560048201600090555050819350505050919050565b60005481565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661090b57600080fd5b6000600160008481526020019081526020016000209050600081600001541161093357600080fd5b600060608260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401808473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200193505050506040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b60208310610abb5780518252602082019150602081019050602083039250610a98565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114610b1d576040519150601f19603f3d011682016040523d82523d6000602084013e610b22565b606091505b509150915081610b2e57fe5b7fa445ec1ee84565906bc8646dcb62f6d1a75fc7a782a03e72220fb97f60ba89ab83600001546040518082815260200191505060405180910390a160016000846000015481526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505081935050505091905056fea2646970667358221220602e22c4a3c6f16979c452060dfbb623b84957d760a0bda14e3d5356f5d4ca4064736f6c63430007050033 -\ No newline at end of file diff --git a/solidity/SimpleMultisig.sol b/solidity/SimpleMultisig.sol @@ -1,75 +0,0 @@ -pragma solidity >=0.6.12; - -// SPDX-License-Identifier: GPL-3.0-or-later - -contract SimpleMultisig { - struct Transaction { - uint256 serial; - address sender; - address recipient; - address token; - uint256 value; - } - uint256 public serial; - mapping(uint256 => Transaction) public requests; - mapping(address => bool) public approvers; - - event NewRequest(address indexed _sender, address indexed _recipient, address indexed _token, uint256 _value, uint256 _serial); - event NewExecution(uint256 serial); - event NewRejection(uint256 serial); - - constructor(address[] memory _approvers) public { - for (uint i = 0; i < _approvers.length; i++) { - approvers[_approvers[i]] = true; - } - serial = 1; - } - - function request(address _recipient, address _token, uint256 _value) public returns (uint256) { - Transaction storage txx = requests[serial]; - - txx.serial = serial; - txx.recipient = _recipient; - txx.sender = msg.sender; - txx.token = _token; - txx.value = _value; - - serial++; - - emit NewRequest(txx.sender, txx.recipient, txx.token, txx.value, txx.serial); - - return txx.serial; - } - - function execute(uint256 _serial) public returns (bool) { - require(approvers[msg.sender], 'ERR_NO_ACCESS'); - - Transaction storage txx = requests[_serial]; - require(txx.serial > 0, 'ERR_INVALID_REQUEST'); - - (bool success, bytes memory _) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.recipient, txx.value)); - assert(success); - - emit NewExecution(txx.serial); - - delete requests[txx.serial]; - - return success; - } - - function reject(uint256 _serial) public returns (bool) { - require(approvers[msg.sender], 'ERR_NO_ACCESS'); - - Transaction storage txx = requests[_serial]; - require(txx.serial > 0, 'ERR_INVALID_REQUEST'); - - (bool success, bytes memory _) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.sender, txx.value)); - assert(success); - - emit NewRejection(txx.serial); - - delete requests[txx.serial]; - - return success; - } -}