eth-address-index

signed metadata declarations for ethereum addresses
Log | Files | Refs

commit d659ae72f54aba1f40074a47e16e5acb2fdf5957
parent 4400240b3e70886afb30528fe225c968a08fbb9d
Author: nolash <dev@holbrook.no>
Date:   Tue, 29 Dec 2020 19:44:14 +0100

Fix address declarator executables

Diffstat:
Apython/eth_address_declarator/__init__.py | 1+
Apython/eth_address_declarator/data/AddressDeclarator.bin | 2++
Apython/eth_address_declarator/data/AddressDeclarator.json | 1+
Apython/eth_address_declarator/data/GiftableToken.bin | 2++
Apython/eth_address_declarator/data/GiftableToken.json | 1+
Apython/eth_address_declarator/declarator.py | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apython/eth_address_declarator/runnable/add.py | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apython/eth_address_declarator/runnable/deploy.py | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apython/eth_token_index/data/TokenUniqueSymbolIndex.bin | 2++
Apython/eth_token_index/data/TokenUniqueSymbolIndex.json | 1+
Mpython/setup.cfg | 20++++++++++----------
Mpython/tests/test_deploy.py | 72+++++++++++++++++++++++++++++++-----------------------------------------
Dpython/tests/test_inteface.py | 105-------------------------------------------------------------------------------
Cpython/tests/test_deploy.py -> python/tests/test_tokenendorse.py | 0
Msolidity/AddressDeclarator.bin | 4++--
Msolidity/AddressDeclarator.json | 2+-
Msolidity/AddressDeclarator.sol | 39+++++++++++++++++++++++++++------------
Msolidity/Makefile | 7++++++-
Asolidity/TokenUniqueSymbolIndex.bin | 2++
Asolidity/TokenUniqueSymbolIndex.json | 1+
Asolidity/TokenUniqueSymbolIndex.sol | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msolidity/test.py | 43++++++++++++++++++++++++++++++++++++++++---
Asolidity/test_addressdeclarator.py | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsolidity/tokenendorser_test.py -> solidity/test_tokenendorser.py | 0
Asolidity/test_tokenindex.py | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 files changed, 580 insertions(+), 175 deletions(-)

diff --git a/python/eth_address_declarator/__init__.py b/python/eth_address_declarator/__init__.py @@ -0,0 +1 @@ +from .declarator import AddressDeclarator diff --git a/python/eth_address_declarator/data/AddressDeclarator.bin b/python/eth_address_declarator/data/AddressDeclarator.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b5060405162001bc838038062001bc8833981810160405281019062000037919062000717565b6060336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600581908060018154018082558091505060019003906000526020600020016000909190919091509080519060200190620000b69291906200068f565b5060056001600580549050620000cd91906200083e565b8154811062000105577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001434090806001815401808255809150506001900390600052602060002001600090919091909150556200014933836200015260201b60201c565b505050620009c3565b600080606060006200016b3387620003b360201b60201c565b92506002600084815260200190815260200160002054905060008114156200030c57600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506005829080600181540180825580915050600190039060005260206000200160009091909190915090805190602001906200026a9291906200068f565b50600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020869080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b60016005805490506200032091906200083e565b90508060026000858152602001908152602001600020819055506005818154811062000375577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018590806001815401808255809150506001900390600052602060002001600090919091909150556001935050505092915050565b6000806000602867ffffffffffffffff811115620003fa577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156200042d5781602001600182028036833780820191505090505b50905060008560405160200162000445919062000795565b604051602081830303815290604052905060005b601481101562000527578181815181106200049d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b838281518110620004e2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806200051e90620008f7565b91505062000459565b50846040516020016200053b919062000795565b604051602081830303815290604052905060005b60148110156200062b5781818151811062000593577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b83601483620005ae9190620007e1565b81518110620005e6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806200062290620008f7565b9150506200054f565b506002826040516200063e9190620007b2565b602060405180830381855afa1580156200065c573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019062000681919062000717565b925082935050505092915050565b828054828255906000526020600020908101928215620006ce579160200282015b82811115620006cd578251825591602001919060010190620006b0565b5b509050620006dd9190620006e1565b5090565b5b80821115620006fc576000816000905550600101620006e2565b5090565b6000815190506200071181620009a9565b92915050565b6000602082840312156200072a57600080fd5b60006200073a8482850162000700565b91505092915050565b62000758620007528262000879565b62000945565b82525050565b60006200076b82620007cb565b620007778185620007d6565b935062000789818560208601620008c1565b80840191505092915050565b6000620007a3828462000743565b60148201915081905092915050565b6000620007c082846200075e565b915081905092915050565b600081519050919050565b600081905092915050565b6000620007ee82620008b7565b9150620007fb83620008b7565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156200083357620008326200096d565b5b828201905092915050565b60006200084b82620008b7565b91506200085883620008b7565b9250828210156200086e576200086d6200096d565b5b828203905092915050565b6000620008868262000897565b9050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b83811015620008e1578082015181840152602081019050620008c4565b83811115620008f1576000848401525b50505050565b60006200090482620008b7565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156200093a57620009396200096d565b5b600182019050919050565b6000620009528262000959565b9050919050565b600062000966826200099c565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160601b9050919050565b620009b4816200088d565b8114620009c057600080fd5b50565b6111f580620009d36000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c80638c661b36116100665780638c661b361461016d5780638da5cb5b1461019d578063ae47ece0146101bb578063d0e95db1146101eb578063ff7496b41461021b5761009e565b806301ffc9a7146100a357806322168e4f146100d357806350e0c6d3146101035780637d64bf1d14610133578063880ad0af14610163575b600080fd5b6100bd60048036038101906100b89190610c91565b61024b565b6040516100ca9190610eae565b60405180910390f35b6100ed60048036038101906100e89190610c2c565b610252565b6040516100fa9190610e71565b60405180910390f35b61011d60048036038101906101189190610b8b565b6102fe565b60405161012a9190610f04565b60405180910390f35b61014d60048036038101906101489190610c2c565b61034a565b60405161015a9190610e71565b60405180910390f35b61016b6103f6565b005b61018760048036038101906101829190610bb4565b610431565b6040516101949190610e8c565b60405180910390f35b6101a56104f5565b6040516101b29190610e71565b60405180910390f35b6101d560048036038101906101d09190610bf0565b610519565b6040516101e29190610eae565b60405180910390f35b61020560048036038101906102009190610b8b565b61076c565b6040516102129190610f04565b60405180910390f35b61023560048036038101906102309190610cba565b6107b8565b6040516102429190610ec9565b60405180910390f35b6000919050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002082815481106102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490509050919050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002082815481106103c3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905092915050565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161042890610ee4565b60405180910390fd5b606060008061044085856107f5565b91506002600083815260200190815260200160002054905060058181548110610492577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018054806020026020016040519081016040528092919081815260200182805480156104e657602002820191906000526020600020905b8154815260200190600101908083116104d2575b50505050509250505092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806060600061052a33876107f5565b92506002600084815260200190815260200160002054905060008114156106c857600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600582908060018154018082558091505060019003906000526020600020016000909190919091509080519060200190610626929190610ab8565b50600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020869080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b60016005805490506106da9190610fd5565b90508060026000858152602001908152602001600020819055506005818154811061072e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018590806001815401808255809150506001900390600052602060002001600090919091909150556001935050505092915050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490509050919050565b600582815481106107c857600080fd5b9060005260206000200181815481106107e057600080fd5b90600052602060002001600091509150505481565b6000806000602867ffffffffffffffff81111561083b577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561086d5781602001600182028036833780820191505090505b5090506000856040516020016108839190610e3f565b604051602081830303815290604052905060005b601481101561095f578181815181106108d9577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b83828151811061091d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610957906110ba565b915050610897565b50846040516020016109719190610e3f565b604051602081830303815290604052905060005b6014811015610a59578181815181106109c7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b836014836109e09190610f7f565b81518110610a17577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610a51906110ba565b915050610985565b50600282604051610a6a9190610e5a565b602060405180830381855afa158015610a87573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190610aaa9190610c68565b925082935050505092915050565b828054828255906000526020600020908101928215610af4579160200282015b82811115610af3578251825591602001919060010190610ad8565b5b509050610b019190610b05565b5090565b5b80821115610b1e576000816000905550600101610b06565b5090565b600081359050610b3181611163565b92915050565b600081359050610b468161117a565b92915050565b600081519050610b5b8161117a565b92915050565b600081359050610b7081611191565b92915050565b600081359050610b85816111a8565b92915050565b600060208284031215610b9d57600080fd5b6000610bab84828501610b22565b91505092915050565b60008060408385031215610bc757600080fd5b6000610bd585828601610b22565b9250506020610be685828601610b22565b9150509250929050565b60008060408385031215610c0357600080fd5b6000610c1185828601610b22565b9250506020610c2285828601610b37565b9150509250929050565b60008060408385031215610c3f57600080fd5b6000610c4d85828601610b22565b9250506020610c5e85828601610b76565b9150509250929050565b600060208284031215610c7a57600080fd5b6000610c8884828501610b4c565b91505092915050565b600060208284031215610ca357600080fd5b6000610cb184828501610b61565b91505092915050565b60008060408385031215610ccd57600080fd5b6000610cdb85828601610b76565b9250506020610cec85828601610b76565b9150509250929050565b6000610d028383610da1565b60208301905092915050565b610d1781611009565b82525050565b610d2e610d2982611009565b611103565b82525050565b6000610d3f82610f2f565b610d498185610f52565b9350610d5483610f1f565b8060005b83811015610d85578151610d6c8882610cf6565b9750610d7783610f45565b925050600181019050610d58565b5085935050505092915050565b610d9b8161101b565b82525050565b610daa81611027565b82525050565b610db981611027565b82525050565b6000610dca82610f3a565b610dd48185610f63565b9350610de4818560208601611087565b80840191505092915050565b6000610dfd601783610f6e565b91507f6f776e65722063616e6e6f74206265206368616e6765640000000000000000006000830152602082019050919050565b610e398161107d565b82525050565b6000610e4b8284610d1d565b60148201915081905092915050565b6000610e668284610dbf565b915081905092915050565b6000602082019050610e866000830184610d0e565b92915050565b60006020820190508181036000830152610ea68184610d34565b905092915050565b6000602082019050610ec36000830184610d92565b92915050565b6000602082019050610ede6000830184610db0565b92915050565b60006020820190508181036000830152610efd81610df0565b9050919050565b6000602082019050610f196000830184610e30565b92915050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b6000610f8a8261107d565b9150610f958361107d565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610fca57610fc9611127565b5b828201905092915050565b6000610fe08261107d565b9150610feb8361107d565b925082821015610ffe57610ffd611127565b5b828203905092915050565b60006110148261105d565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156110a557808201518184015260208101905061108a565b838111156110b4576000848401525b50505050565b60006110c58261107d565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156110f8576110f7611127565b5b600182019050919050565b600061110e82611115565b9050919050565b600061112082611156565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160601b9050919050565b61116c81611009565b811461117757600080fd5b50565b61118381611027565b811461118e57600080fd5b50565b61119a81611031565b81146111a557600080fd5b50565b6111b18161107d565b81146111bc57600080fd5b5056fea26469706673582212204460994967d4a16fb30d1f457d533e6929ca94e119064c8d4865ff61ed18590864736f6c63430008000033 +\ No newline at end of file diff --git a/python/eth_address_declarator/data/AddressDeclarator.json b/python/eth_address_declarator/data/AddressDeclarator.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"contents","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declarationAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"}],"name":"declarationCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declaratorAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"declaratorCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/eth_address_declarator/data/GiftableToken.bin b/python/eth_address_declarator/data/GiftableToken.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b506040516200120338038062001203833981810160405260608110156200003757600080fd5b81019080805160405193929190846401000000008211156200005857600080fd5b838201915060208201858111156200006f57600080fd5b82518660018202830111640100000000821117156200008d57600080fd5b8083526020830192505050908051906020019080838360005b83811015620000c3578082015181840152602081019050620000a6565b50505050905090810190601f168015620000f15780820380516001836020036101000a031916815260200191505b50604052602001805160405193929190846401000000008211156200011557600080fd5b838201915060208201858111156200012c57600080fd5b82518660018202830111640100000000821117156200014a57600080fd5b8083526020830192505050908051906020019080838360005b838110156200018057808201518184015260208101905062000163565b50505050905090810190601f168015620001ae5780820380516001836020036101000a031916815260200191505b5060405260200180519060200190929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600290805190602001906200021a929190620002af565b50816003908051906020019062000233929190620002af565b5080600460006101000a81548160ff021916908360ff16021790555060018060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050505062000365565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282620002e7576000855562000333565b82601f106200030257805160ff191683800117855562000333565b8280016001018555821562000333579182015b828111156200033257825182559160200191906001019062000315565b5b50905062000342919062000346565b5090565b5b808211156200036157600081600090555060010162000347565b5090565b610e8e80620003756000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c806355b6ed5c1161007157806355b6ed5c146102bd57806370a082311461033557806395d89b411461038d578063983b2d5614610410578063a0712d681461046a578063a9059cbb146104ae576100b4565b806306fdde03146100b9578063095ea7b31461013c57806318160ddd146101a057806323b872dd146101be5780633092afd514610242578063313ce5671461029c575b600080fd5b6100c1610512565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101015780820151818401526020810190506100e6565b50505050905090810190601f16801561012e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101886004803603604081101561015257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105b0565b60405180821515815260200191505060405180910390f35b6101a86106ab565b6040518082815260200191505060405180910390f35b61022a600480360360608110156101d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106b1565b60405180821515815260200191505060405180910390f35b6102846004803603602081101561025857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109a8565b60405180821515815260200191505060405180910390f35b6102a4610a9a565b604051808260ff16815260200191505060405180910390f35b61031f600480360360408110156102d357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610aad565b6040518082815260200191505060405180910390f35b6103776004803603602081101561034b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ad2565b6040518082815260200191505060405180910390f35b610395610aea565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103d55780820151818401526020810190506103ba565b50505050905090810190601f1680156104025780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104526004803603602081101561042657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b88565b60405180821515815260200191505060405180910390f35b6104966004803603602081101561048057600080fd5b8101908080359060200190929190505050610c43565b60405180821515815260200191505060405180910390f35b6104fa600480360360408110156104c457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d01565b60405180821515815260200191505060405180910390f35b60028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105a85780601f1061057d576101008083540402835291602001916105a8565b820191906000526020600020905b81548152906001019060200180831161058b57829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60055481565b600081600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561073c57600080fd5b81600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561078857600080fd5b81600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205403600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555081600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055503373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167f5f7542858008eeb041631f30e6109ae94b83a58e9a58261dd2c42c508850f939856040518082815260200191505060405180910390a4600190509392505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610a3057508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b610a3957600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b600460009054906101000a900460ff1681565b6007602052816000526040600020602052806000526040600020600091509150505481565b60066020528060005260406000206000915090505481565b60038054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b805780601f10610b5557610100808354040283529160200191610b80565b820191906000526020600020905b815481529060010190602001808311610b6357829003601f168201915b505050505081565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610be357600080fd5b60018060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610c9b57600080fd5b81600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508160056000828254019250508190555060019050919050565b600081600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610d4f57600080fd5b81600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509291505056fea2646970667358221220decedd646f4686c330f11369f5c7b4908d8940d20f00c85711890c5f75172d8764736f6c63430007050033 +\ No newline at end of file diff --git a/python/eth_address_declarator/data/GiftableToken.json b/python/eth_address_declarator/data/GiftableToken.json @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/eth_address_declarator/declarator.py b/python/eth_address_declarator/declarator.py @@ -0,0 +1,84 @@ +# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +# SPDX-License-Identifier: GPL-3.0-or-later +# File-version: 1 +# Description: Python interface to abi and bin files for faucet contracts + +# standard imports +import logging +import json +import os +import hashlib + +logg = logging.getLogger(__name__) + +moddir = os.path.dirname(__file__) +datadir = os.path.join(moddir, 'data') + + +class TokenEndorser: + + __abi = None + __bytecode = None + __address = None + + def __init__(self, w3, address, signer_address=None): + abi = TokenEndorser.abi() + TokenEndorser.bytecode() + self.__address = address + self.contract = w3.eth.contract(abi=abi, address=address) + self.w3 = w3 + if signer_address != None: + self.signer_address = signer_address + else: + if type(self.w3.eth.defaultAccount).__name__ == 'Empty': + self.w3.eth.defaultAccount = self.w3.eth.accounts[0] + self.signer_address = self.w3.eth.defaultAccount + + + @staticmethod + def abi(): + if TokenEndorser.__abi == None: + f = open(os.path.join(datadir, 'AccountDeclarator.json'), 'r') + AccountDeclarator.__abi = json.load(f) + f.close() + return TokenEndorser.__abi + + + @staticmethod + def bytecode(): + if TokenEndorser.__bytecode == None: + f = open(os.path.join(datadir, 'AccountDeclarator.bin')) + AccountDeclarator.__bytecode = f.read() + f.close() + return TokenEndorser.__bytecode + + +# def token_from_symbol(self, symbol): +# return self.contract.functions.tokenSymbolIndex(symbol).call() +# def + +# +# def endorsed_tokens(self, endorser_address): +# tokens = [] +# for i in range(self.contract.functions.endorserTokenCount(endorser_address).call()): +# tidx = self.contract.functions.endorser(endorser_address, i).call() +# t = self.contract.functions.tokens(tidx).call() +# tokens.append(t) +# return tokens +# +# def declared(self, declarator_address): +# addresses = [] +# for i +# +# +# def add(self, token_address, data): +# self.contract.functions.add(token_address, data).transact({'from': self.signer_address}) +# + +def to_endorsement_key(declarator_address_hex, declaration_address_hex): + h = hashlib.new('sha256') + h.update(bytes.fromhex(token_address_hex[2:])) + h.update(bytes.fromhex(endorser_address_hex[2:])) + return h.digest() + + diff --git a/python/eth_address_declarator/runnable/add.py b/python/eth_address_declarator/runnable/add.py @@ -0,0 +1,59 @@ +"""Adds a new Address declaration + +.. 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) + +script_dir = os.path.dirname(__file__) +data_dir = os.path.join(script_dir, '..', 'data') + +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('-r', '--contract-address', dest='r', type=str, help='Token endorsement contract address') +argparser.add_argument('-o', '--endorser-address', dest='o', type=str, help='Address to use to sign endorsement transaction') +argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir)) +argparser.add_argument('-v', action='store_true', help='Be verbose') +argparser.add_argument('address', type=str, help='Ethereum address to add declaration to') +argparser.add_argument('declaration', type=str, help='SHA256 sum of endorsement data to add') +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.abi_dir, 'AddressDeclarator.json'), 'r') + abi = json.load(f) + f.close() + + w3.eth.defaultAccount = w3.eth.accounts[0] + if args.o != None: + w3.eth.defaultAccount = args.o + logg.debug('endorser address {}'.format(w3.eth.defaultAccount)) + + c = w3.eth.contract(abi=abi, address=args.r) + + tx_hash = c.functions.addDeclaration(args.address, args.declaration).transact() + print(tx_hash.hex()) + + +if __name__ == '__main__': + main() diff --git a/python/eth_address_declarator/runnable/deploy.py b/python/eth_address_declarator/runnable/deploy.py @@ -0,0 +1,64 @@ +"""Deploys address declaration 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) + +script_dir = os.path.dirname(__file__) +data_dir = os.path.join(script_dir, '..', 'data') + +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('-o', '--owner', dest='o', type=str, help='Accounts declarator owner') +argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir)) +argparser.add_argument('-v', action='store_true', help='Be verbose') +argparser.add_argument('owner_description_digest', type=str, help='SHA256 of description metadata of contract deployer') +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.abi_dir, 'AddressDeclarator.json'), 'r') + abi = json.load(f) + f.close() + + f = open(os.path.join(args.abi_dir, 'AddressDeclarator.bin'), 'r') + bytecode = f.read() + f.close() + + w3.eth.defaultAccount = w3.eth.accounts[0] + if args.o != None: + w3.eth.defaultAccount = args.o + logg.debug('owner address {}'.format(w3.eth.defaultAccount)) + + c = w3.eth.contract(abi=abi, bytecode=bytecode) + logg.info('digest {}'.format(args.owner_description_digest)) + tx_hash = c.constructor(args.owner_description_digest).transact() + + rcpt = w3.eth.getTransactionReceipt(tx_hash) + + print(rcpt.contractAddress) + + +if __name__ == '__main__': + main() diff --git a/python/eth_token_index/data/TokenUniqueSymbolIndex.bin b/python/eth_token_index/data/TokenUniqueSymbolIndex.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610a1a806100606000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638da5cb5b1161005b5780638da5cb5b146100ec578063bb34534c1461010a578063cbb834341461013a578063d22057a9146101585761007d565b80634f64b2be146100825780637ef50298146100b2578063880ad0af146100e2575b600080fd5b61009c60048036038101906100979190610714565b610188565b6040516100a991906107f2565b60405180910390f35b6100cc60048036038101906100c79190610645565b6101c7565b6040516100d99190610848565b60405180910390f35b6100ea6101df565b005b6100f461021a565b60405161010191906107f2565b60405180910390f35b610124600480360381019061011f9190610645565b61023e565b60405161013191906107f2565b60405180910390f35b6101426102c4565b60405161014f9190610848565b60405180910390f35b610172600480360381019061016d9190610697565b6102d1565b60405161017f919061080d565b60405180910390f35b6002818154811061019857600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60016020528060005260406000206000915090505481565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161021190610828565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806001600084815260200190815260200160002054905060028181548110610291577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16915050919050565b6000600280549050905090565b600060606000806000808673ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f95d89b41000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161038291906107db565b6000604051808303816000865af19150503d80600081146103bf576040519150601f19603f3d011682016040523d82523d6000602084013e6103c4565b606091505b5091509150816103d357600080fd5b808060200190518101906103e791906106d3565b94506002856040516103f991906107db565b602060405180830381855afa158015610416573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190610439919061066e565b935083881461044757600080fd5b60016000858152602001908152602001600020549250600073ffffffffffffffffffffffffffffffffffffffff16600284815481106104af577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146104fa57600080fd5b60028054905060016000868152602001908152602001600020819055506002879080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060019550505050505092915050565b600061059c61059784610894565b610863565b9050828152602081018484840111156105b457600080fd5b6105bf84828561093d565b509392505050565b6000813590506105d68161099f565b92915050565b6000813590506105eb816109b6565b92915050565b600081519050610600816109b6565b92915050565b600082601f83011261061757600080fd5b8151610627848260208601610589565b91505092915050565b60008135905061063f816109cd565b92915050565b60006020828403121561065757600080fd5b6000610665848285016105dc565b91505092915050565b60006020828403121561068057600080fd5b600061068e848285016105f1565b91505092915050565b600080604083850312156106aa57600080fd5b60006106b8858286016105dc565b92505060206106c9858286016105c7565b9150509250929050565b6000602082840312156106e557600080fd5b600082015167ffffffffffffffff8111156106ff57600080fd5b61070b84828501610606565b91505092915050565b60006020828403121561072657600080fd5b600061073484828501610630565b91505092915050565b610746816108eb565b82525050565b610755816108fd565b82525050565b6000610766826108c4565b61077081856108cf565b935061078081856020860161093d565b80840191505092915050565b60006107996017836108da565b91507f6f776e65722063616e6e6f74206265206368616e6765640000000000000000006000830152602082019050919050565b6107d581610933565b82525050565b60006107e7828461075b565b915081905092915050565b6000602082019050610807600083018461073d565b92915050565b6000602082019050610822600083018461074c565b92915050565b600060208201905081810360008301526108418161078c565b9050919050565b600060208201905061085d60008301846107cc565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561088a57610889610970565b5b8060405250919050565b600067ffffffffffffffff8211156108af576108ae610970565b5b601f19601f8301169050602081019050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006108f682610913565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b8381101561095b578082015181840152602081019050610940565b8381111561096a576000848401525b50505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6109a8816108eb565b81146109b357600080fd5b50565b6109bf81610909565b81146109ca57600080fd5b50565b6109d681610933565b81146109e157600080fd5b5056fea26469706673582212202ccad4d8425a8283d41cfdbe1a799b322c946ee19e2e74b11748d2836abf48b664736f6c63430008000033 +\ No newline at end of file diff --git a/python/eth_token_index/data/TokenUniqueSymbolIndex.json b/python/eth_token_index/data/TokenUniqueSymbolIndex.json @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"},{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,10 +1,10 @@ [metadata] -name = eth-token-endorser -version = 0.0.2 -description = Ethereum token address to multihash metadata mapper +name = eth-address-declarator +version = 0.0.1 +description = Signed metadata declarations for ethereum addresses author = Louis Holbrook author_email = dev@holbrook.no -url = https://gitlab.com/nolash/simple-multisig +url = https://gitlab.com/nolash/eth-address-declarator keywords = ethereum classifiers = @@ -24,8 +24,8 @@ licence_files = include_package_data = True python_requires = >= 3.6 packages = - eth_token_endorser - eth_token_endorser.runnable + eth_address_declarator + eth_address_declarator.runnable install_requires = web3==5.12.2 tests_require = @@ -39,10 +39,10 @@ testing = [options.package_data] * = - data/TokenEndorser.json - data/TokenEndorser.bin + data/AddressDeclarator.json + data/AddressDeclarator.bin [options.entry_points] console_scripts = - eth-token-endorser-deploy = eth_token_endorser.runnable.deploy:main - eth-token-endorser-add = eth_token_endorser.runnable.add:main + eth-address-declarator-deploy = eth_address_declarator.runnable.deploy:main + eth-address-declarator-add = eth_address_declarator.runnable.add:main diff --git a/python/tests/test_deploy.py b/python/tests/test_deploy.py @@ -27,11 +27,13 @@ class Test(unittest.TestCase): }) # create store of used accounts - f = open(os.path.join(testdir, '../eth_token_endorser/data/TokenEndorser.bin'), 'r') + #f = open(os.path.join(testdir, '../eth_token_index/data/TokenUniqueSymbolIndex.bin'), 'r') + f = open(os.path.join(testdir, '../../solidity/TokenUniqueSymbolIndex.bin'), 'r') bytecode = f.read() f.close() - f = open(os.path.join(testdir, '../eth_token_endorser/data/TokenEndorser.json'), 'r') + #f = open(os.path.join(testdir, '../eth_token_index/data/TokenUniqueSymbolIndex.json'), 'r') + f = open(os.path.join(testdir, '../../solidity/TokenUniqueSymbolIndex.json'), 'r') self.abi = json.load(f) f.close() @@ -71,6 +73,13 @@ class Test(unittest.TestCase): self.address_token_two = r.contractAddress + t = self.w3.eth.contract(abi=self.abi_token, bytecode=bytecode) + tx_hash = t.constructor('Bar Token Duplicate', 'BAR', 18).transact({'from': self.w3.eth.accounts[0]}) + + r = self.w3.eth.getTransactionReceipt(tx_hash) + + self.address_token_three = r.contractAddress + def tearDown(self): pass @@ -79,55 +88,36 @@ class Test(unittest.TestCase): def test_basic(self): c = self.w3.eth.contract(abi=self.abi, address=self.address) - d = '0x' + os.urandom(32).hex() - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]}) + h = hashlib.new('sha256') + h.update('FOO'.encode('utf-8')) + z = h.digest() + # owner text with self.assertRaises(Exception): - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]}) - - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]}) - c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[0]}) - c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[1]}) + c.functions.register(z.hex(), self.address_token_one).transact({'from': self.w3.eth.accounts[1]}) + logg.debug('using identifier {}'.format(z.hex())) + # Register FOO symbol + c.functions.register(z.hex(), self.address_token_one).transact({'from': self.w3.eth.accounts[0]}) - def test_endorsement(self): - c = self.w3.eth.contract(abi=self.abi, address=self.address) - - d = '0x' + os.urandom(32).hex() - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]}) - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]}) + # Raise on duplicate FOO symbol + with self.assertRaises(Exception): + c.functions.register(z.hex(), self.address_token_one).transact({'from': self.w3.eth.accounts[0]}) + # Raise on mismatch between supplied symbol and token symbol reported by ERC20 + with self.assertRaises(Exception): + c.functions.register(z.hex(), self.address_token_two).transact({'from': self.w3.eth.accounts[0]}) h = hashlib.new('sha256') - h.update(bytes.fromhex(self.address_token_one[2:])) - h.update(bytes.fromhex(self.w3.eth.accounts[0][2:])) + h.update('BAR'.encode('utf-8')) z = h.digest() - assert d[2:] == c.functions.endorsement(z.hex()).call().hex() - - c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[0]}) - - assert c.functions.endorsers(self.w3.eth.accounts[0], 0).call() == 1 - assert c.functions.endorsers(self.w3.eth.accounts[1], 0).call() == 1 - assert c.functions.endorsers(self.w3.eth.accounts[0], 1).call() == 2 - - assert c.functions.tokens(1).call() == self.address_token_one - assert c.functions.tokens(2).call() == self.address_token_two - - assert c.functions.tokenIndex(self.address_token_one).call() == 1 - assert c.functions.tokenIndex(self.address_token_two).call() == 2 + # Register BAR symbol + c.functions.register(z.hex(), self.address_token_two).transact({'from': self.w3.eth.accounts[0]}) - - - def test_symbol_index(self): - c = self.w3.eth.contract(abi=self.abi, address=self.address) - d = '0x' + os.urandom(32).hex() - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]}) - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]}) - c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[1]}) - - self.assertEqual(c.functions.tokenSymbolIndex('FOO').call(), self.address_token_one); - self.assertEqual(c.functions.tokenSymbolIndex('BAR').call(), self.address_token_two); + # Raise on duplicate BAR symbol (with different token contract address) + with self.assertRaises(Exception): + c.functions.register(z.hex(), self.address_token_three).transact({'from': self.w3.eth.accounts[0]}) if __name__ == '__main__': diff --git a/python/tests/test_inteface.py b/python/tests/test_inteface.py @@ -1,105 +0,0 @@ -import os -import unittest -import json -import logging - -import web3 -import eth_tester -import eth_abi - -from eth_token_endorser import TokenEndorser - -logging.basicConfig(level=logging.DEBUG) -logg = logging.getLogger() - -logging.getLogger('web3').setLevel(logging.WARNING) -logging.getLogger('eth.vm').setLevel(logging.WARNING) - -testdir = os.path.dirname(__file__) - - -class Test(unittest.TestCase): - - contract = None - - def setUp(self): - eth_params = eth_tester.backends.pyevm.main.get_default_genesis_params({ - 'gas_limit': 9000000, - }) - - # create store of used accounts - f = open(os.path.join(testdir, '../eth_token_endorser/data/TokenEndorser.bin'), 'r') - bytecode = f.read() - f.close() - - f = open(os.path.join(testdir, '../eth_token_endorser/data/TokenEndorser.json'), 'r') - self.abi = json.load(f) - f.close() - - - backend = eth_tester.PyEVMBackend(eth_params) - self.eth_tester = eth_tester.EthereumTester(backend) - provider = web3.Web3.EthereumTesterProvider(self.eth_tester) - self.w3 = web3.Web3(provider) - c = self.w3.eth.contract(abi=self.abi, bytecode=bytecode) - tx_hash = c.constructor().transact({'from': self.w3.eth.accounts[0]}) - - r = self.w3.eth.getTransactionReceipt(tx_hash) - - self.address = r.contractAddress - - - # create token - f = open(os.path.join(testdir, '../eth_token_endorser/data/GiftableToken.bin'), 'r') - bytecode = f.read() - f.close() - - f = open(os.path.join(testdir, '../eth_token_endorser/data/GiftableToken.json'), 'r') - self.abi_token = json.load(f) - f.close() - - t = self.w3.eth.contract(abi=self.abi_token, bytecode=bytecode) - tx_hash = t.constructor('Foo Token', 'FOO', 18).transact({'from': self.w3.eth.accounts[0]}) - - r = self.w3.eth.getTransactionReceipt(tx_hash) - - self.address_token_one = r.contractAddress - - t = self.w3.eth.contract(abi=self.abi_token, bytecode=bytecode) - tx_hash = t.constructor('Bar Token', 'BAR', 18).transact({'from': self.w3.eth.accounts[0]}) - - r = self.w3.eth.getTransactionReceipt(tx_hash) - - self.address_token_two = r.contractAddress - - - c = self.w3.eth.contract(abi=self.abi, address=self.address) - d = '0x' + os.urandom(32).hex() - c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]}) - c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[0]}) - - - def tearDown(self): - pass - - - def test_interface(self): - i = TokenEndorser(self.w3, self.address) #, self.w3.eth.accounts[1]) - self.assertEqual(i.token_from_symbol('FOO'), self.address_token_one) - - - def test_endorsed_tokens(self): - i = TokenEndorser(self.w3, self.address) #, self.w3.eth.accounts[1]) - t = i.endorsed_tokens(self.w3.eth.accounts[0]) - self.assertEqual(t[0], self.address_token_one) - self.assertEqual(t[1], self.address_token_two) - - - def test_add(self): - i = TokenEndorser(self.w3, self.address, self.w3.eth.accounts[1]) - d = '0x' + os.urandom(32).hex() - i.add(self.address_token_one, d) - - -if __name__ == '__main__': - unittest.main() diff --git a/python/tests/test_deploy.py b/python/tests/test_tokenendorse.py diff --git a/solidity/AddressDeclarator.bin b/solidity/AddressDeclarator.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b50604051620018bc380380620018bc833981810160405281019062000037919062000677565b6060336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600381908060018154018082558091505060019003906000526020600020016000909190919091509080519060200190620000b6929190620005ef565b5060036001600380549050620000cd91906200079e565b8154811062000105577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001434090806001815401808255809150506001900390600052602060002001600090919091909150556200014933836200015260201b60201c565b50505062000923565b600080606060006200016b33876200031360201b60201c565b92506001600084815260200190815260200160002054905060008114156200026c57600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506003829080600181540180825580915050600190039060005260206000200160009091909190915090805190602001906200026a929190620005ef565b505b60016003805490506200028091906200079e565b905080600160008581526020019081526020016000208190555060038181548110620002d5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018590806001815401808255809150506001900390600052602060002001600090919091909150556001935050505092915050565b6000806000602867ffffffffffffffff8111156200035a577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156200038d5781602001600182028036833780820191505090505b509050600085604051602001620003a59190620006f5565b604051602081830303815290604052905060005b60148110156200048757818181518110620003fd577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b83828151811062000442577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806200047e9062000857565b915050620003b9565b50846040516020016200049b9190620006f5565b604051602081830303815290604052905060005b60148110156200058b57818181518110620004f3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b836014836200050e919062000741565b8151811062000546577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080620005829062000857565b915050620004af565b506002826040516200059e919062000712565b602060405180830381855afa158015620005bc573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190620005e1919062000677565b925082935050505092915050565b8280548282559060005260206000209081019282156200062e579160200282015b828111156200062d57825182559160200191906001019062000610565b5b5090506200063d919062000641565b5090565b5b808211156200065c57600081600090555060010162000642565b5090565b600081519050620006718162000909565b92915050565b6000602082840312156200068a57600080fd5b60006200069a8482850162000660565b91505092915050565b620006b8620006b282620007d9565b620008a5565b82525050565b6000620006cb826200072b565b620006d7818562000736565b9350620006e981856020860162000821565b80840191505092915050565b6000620007038284620006a3565b60148201915081905092915050565b6000620007208284620006be565b915081905092915050565b600081519050919050565b600081905092915050565b60006200074e8262000817565b91506200075b8362000817565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115620007935762000792620008cd565b5b828201905092915050565b6000620007ab8262000817565b9150620007b88362000817565b925082821015620007ce57620007cd620008cd565b5b828203905092915050565b6000620007e682620007f7565b9050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156200084157808201518184015260208101905062000824565b8381111562000851576000848401525b50505050565b6000620008648262000817565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156200089a5762000899620008cd565b5b600182019050919050565b6000620008b282620008b9565b9050919050565b6000620008c682620008fc565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160601b9050919050565b6200091481620007ed565b81146200092057600080fd5b50565b610f8980620009336000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c80638da5cb5b1161005b5780638da5cb5b14610127578063ae47ece014610145578063d0e95db114610175578063ff7496b4146101a557610088565b806301ffc9a71461008d5780634cf94740146100bd578063880ad0af146100ed5780638c661b36146100f7575b600080fd5b6100a760048036038101906100a29190610a25565b6101d5565b6040516100b49190610c42565b60405180910390f35b6100d760048036038101906100d291906109c0565b6101dc565b6040516100e49190610c05565b60405180910390f35b6100f561022a565b005b610111600480360381019061010c9190610948565b610265565b60405161011e9190610c20565b60405180910390f35b61012f610329565b60405161013c9190610c05565b60405180910390f35b61015f600480360381019061015a9190610984565b61034d565b60405161016c9190610c42565b60405180910390f35b61018f600480360381019061018a919061091f565b610500565b60405161019c9190610c98565b60405180910390f35b6101bf60048036038101906101ba9190610a4e565b61054c565b6040516101cc9190610c5d565b60405180910390f35b6000919050565b600260205281600052604060002081815481106101f857600080fd5b906000526020600020016000915091509054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161025c90610c78565b60405180910390fd5b60606000806102748585610589565b915060016000838152602001908152602001600020549050600381815481106102c6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200180548060200260200160405190810160405280929190818152602001828054801561031a57602002820191906000526020600020905b815481526020019060010190808311610306575b50505050509250505092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806060600061035e3387610589565b925060016000848152602001908152602001600020549050600081141561045c57600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060038290806001815401808255809150506001900390600052602060002001600090919091909150908051906020019061045a92919061084c565b505b600160038054905061046e9190610d69565b9050806001600085815260200190815260200160002081905550600381815481106104c2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018590806001815401808255809150506001900390600052602060002001600090919091909150556001935050505092915050565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490509050919050565b6003828154811061055c57600080fd5b90600052602060002001818154811061057457600080fd5b90600052602060002001600091509150505481565b6000806000602867ffffffffffffffff8111156105cf577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156106015781602001600182028036833780820191505090505b5090506000856040516020016106179190610bd3565b604051602081830303815290604052905060005b60148110156106f35781818151811061066d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b8382815181106106b1577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806106eb90610e4e565b91505061062b565b50846040516020016107059190610bd3565b604051602081830303815290604052905060005b60148110156107ed5781818151811061075b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b836014836107749190610d13565b815181106107ab577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806107e590610e4e565b915050610719565b506002826040516107fe9190610bee565b602060405180830381855afa15801561081b573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019061083e91906109fc565b925082935050505092915050565b828054828255906000526020600020908101928215610888579160200282015b8281111561088757825182559160200191906001019061086c565b5b5090506108959190610899565b5090565b5b808211156108b257600081600090555060010161089a565b5090565b6000813590506108c581610ef7565b92915050565b6000813590506108da81610f0e565b92915050565b6000815190506108ef81610f0e565b92915050565b60008135905061090481610f25565b92915050565b60008135905061091981610f3c565b92915050565b60006020828403121561093157600080fd5b600061093f848285016108b6565b91505092915050565b6000806040838503121561095b57600080fd5b6000610969858286016108b6565b925050602061097a858286016108b6565b9150509250929050565b6000806040838503121561099757600080fd5b60006109a5858286016108b6565b92505060206109b6858286016108cb565b9150509250929050565b600080604083850312156109d357600080fd5b60006109e1858286016108b6565b92505060206109f28582860161090a565b9150509250929050565b600060208284031215610a0e57600080fd5b6000610a1c848285016108e0565b91505092915050565b600060208284031215610a3757600080fd5b6000610a45848285016108f5565b91505092915050565b60008060408385031215610a6157600080fd5b6000610a6f8582860161090a565b9250506020610a808582860161090a565b9150509250929050565b6000610a968383610b35565b60208301905092915050565b610aab81610d9d565b82525050565b610ac2610abd82610d9d565b610e97565b82525050565b6000610ad382610cc3565b610add8185610ce6565b9350610ae883610cb3565b8060005b83811015610b19578151610b008882610a8a565b9750610b0b83610cd9565b925050600181019050610aec565b5085935050505092915050565b610b2f81610daf565b82525050565b610b3e81610dbb565b82525050565b610b4d81610dbb565b82525050565b6000610b5e82610cce565b610b688185610cf7565b9350610b78818560208601610e1b565b80840191505092915050565b6000610b91601783610d02565b91507f6f776e65722063616e6e6f74206265206368616e6765640000000000000000006000830152602082019050919050565b610bcd81610e11565b82525050565b6000610bdf8284610ab1565b60148201915081905092915050565b6000610bfa8284610b53565b915081905092915050565b6000602082019050610c1a6000830184610aa2565b92915050565b60006020820190508181036000830152610c3a8184610ac8565b905092915050565b6000602082019050610c576000830184610b26565b92915050565b6000602082019050610c726000830184610b44565b92915050565b60006020820190508181036000830152610c9181610b84565b9050919050565b6000602082019050610cad6000830184610bc4565b92915050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b6000610d1e82610e11565b9150610d2983610e11565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610d5e57610d5d610ebb565b5b828201905092915050565b6000610d7482610e11565b9150610d7f83610e11565b925082821015610d9257610d91610ebb565b5b828203905092915050565b6000610da882610df1565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b83811015610e39578082015181840152602081019050610e1e565b83811115610e48576000848401525b50505050565b6000610e5982610e11565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415610e8c57610e8b610ebb565b5b600182019050919050565b6000610ea282610ea9565b9050919050565b6000610eb482610eea565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160601b9050919050565b610f0081610d9d565b8114610f0b57600080fd5b50565b610f1781610dbb565b8114610f2257600080fd5b50565b610f2e81610dc5565b8114610f3957600080fd5b50565b610f4581610e11565b8114610f5057600080fd5b5056fea2646970667358221220429e476bedf8f13891c550510f5e51ab149e9d63dcc86b1cd521655378704b2864736f6c63430008000033 -\ No newline at end of file +60806040523480156200001157600080fd5b5060405162001bc838038062001bc8833981810160405281019062000037919062000717565b6060336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600581908060018154018082558091505060019003906000526020600020016000909190919091509080519060200190620000b69291906200068f565b5060056001600580549050620000cd91906200083e565b8154811062000105577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001434090806001815401808255809150506001900390600052602060002001600090919091909150556200014933836200015260201b60201c565b505050620009c3565b600080606060006200016b3387620003b360201b60201c565b92506002600084815260200190815260200160002054905060008114156200030c57600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506005829080600181540180825580915050600190039060005260206000200160009091909190915090805190602001906200026a9291906200068f565b50600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020869080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b60016005805490506200032091906200083e565b90508060026000858152602001908152602001600020819055506005818154811062000375577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018590806001815401808255809150506001900390600052602060002001600090919091909150556001935050505092915050565b6000806000602867ffffffffffffffff811115620003fa577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156200042d5781602001600182028036833780820191505090505b50905060008560405160200162000445919062000795565b604051602081830303815290604052905060005b601481101562000527578181815181106200049d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b838281518110620004e2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806200051e90620008f7565b91505062000459565b50846040516020016200053b919062000795565b604051602081830303815290604052905060005b60148110156200062b5781818151811062000593577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b83601483620005ae9190620007e1565b81518110620005e6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806200062290620008f7565b9150506200054f565b506002826040516200063e9190620007b2565b602060405180830381855afa1580156200065c573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019062000681919062000717565b925082935050505092915050565b828054828255906000526020600020908101928215620006ce579160200282015b82811115620006cd578251825591602001919060010190620006b0565b5b509050620006dd9190620006e1565b5090565b5b80821115620006fc576000816000905550600101620006e2565b5090565b6000815190506200071181620009a9565b92915050565b6000602082840312156200072a57600080fd5b60006200073a8482850162000700565b91505092915050565b62000758620007528262000879565b62000945565b82525050565b60006200076b82620007cb565b620007778185620007d6565b935062000789818560208601620008c1565b80840191505092915050565b6000620007a3828462000743565b60148201915081905092915050565b6000620007c082846200075e565b915081905092915050565b600081519050919050565b600081905092915050565b6000620007ee82620008b7565b9150620007fb83620008b7565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156200083357620008326200096d565b5b828201905092915050565b60006200084b82620008b7565b91506200085883620008b7565b9250828210156200086e576200086d6200096d565b5b828203905092915050565b6000620008868262000897565b9050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b83811015620008e1578082015181840152602081019050620008c4565b83811115620008f1576000848401525b50505050565b60006200090482620008b7565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156200093a57620009396200096d565b5b600182019050919050565b6000620009528262000959565b9050919050565b600062000966826200099c565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160601b9050919050565b620009b4816200088d565b8114620009c057600080fd5b50565b6111f580620009d36000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c80638c661b36116100665780638c661b361461016d5780638da5cb5b1461019d578063ae47ece0146101bb578063d0e95db1146101eb578063ff7496b41461021b5761009e565b806301ffc9a7146100a357806322168e4f146100d357806350e0c6d3146101035780637d64bf1d14610133578063880ad0af14610163575b600080fd5b6100bd60048036038101906100b89190610c91565b61024b565b6040516100ca9190610eae565b60405180910390f35b6100ed60048036038101906100e89190610c2c565b610252565b6040516100fa9190610e71565b60405180910390f35b61011d60048036038101906101189190610b8b565b6102fe565b60405161012a9190610f04565b60405180910390f35b61014d60048036038101906101489190610c2c565b61034a565b60405161015a9190610e71565b60405180910390f35b61016b6103f6565b005b61018760048036038101906101829190610bb4565b610431565b6040516101949190610e8c565b60405180910390f35b6101a56104f5565b6040516101b29190610e71565b60405180910390f35b6101d560048036038101906101d09190610bf0565b610519565b6040516101e29190610eae565b60405180910390f35b61020560048036038101906102009190610b8b565b61076c565b6040516102129190610f04565b60405180910390f35b61023560048036038101906102309190610cba565b6107b8565b6040516102429190610ec9565b60405180910390f35b6000919050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002082815481106102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490509050919050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002082815481106103c3577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905092915050565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161042890610ee4565b60405180910390fd5b606060008061044085856107f5565b91506002600083815260200190815260200160002054905060058181548110610492577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018054806020026020016040519081016040528092919081815260200182805480156104e657602002820191906000526020600020905b8154815260200190600101908083116104d2575b50505050509250505092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806060600061052a33876107f5565b92506002600084815260200190815260200160002054905060008114156106c857600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600582908060018154018082558091505060019003906000526020600020016000909190919091509080519060200190610626929190610ab8565b50600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020869080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b60016005805490506106da9190610fd5565b90508060026000858152602001908152602001600020819055506005818154811061072e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018590806001815401808255809150506001900390600052602060002001600090919091909150556001935050505092915050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490509050919050565b600582815481106107c857600080fd5b9060005260206000200181815481106107e057600080fd5b90600052602060002001600091509150505481565b6000806000602867ffffffffffffffff81111561083b577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561086d5781602001600182028036833780820191505090505b5090506000856040516020016108839190610e3f565b604051602081830303815290604052905060005b601481101561095f578181815181106108d9577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b83828151811061091d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610957906110ba565b915050610897565b50846040516020016109719190610e3f565b604051602081830303815290604052905060005b6014811015610a59578181815181106109c7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602001015160f81c60f81b836014836109e09190610f7f565b81518110610a17577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610a51906110ba565b915050610985565b50600282604051610a6a9190610e5a565b602060405180830381855afa158015610a87573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190610aaa9190610c68565b925082935050505092915050565b828054828255906000526020600020908101928215610af4579160200282015b82811115610af3578251825591602001919060010190610ad8565b5b509050610b019190610b05565b5090565b5b80821115610b1e576000816000905550600101610b06565b5090565b600081359050610b3181611163565b92915050565b600081359050610b468161117a565b92915050565b600081519050610b5b8161117a565b92915050565b600081359050610b7081611191565b92915050565b600081359050610b85816111a8565b92915050565b600060208284031215610b9d57600080fd5b6000610bab84828501610b22565b91505092915050565b60008060408385031215610bc757600080fd5b6000610bd585828601610b22565b9250506020610be685828601610b22565b9150509250929050565b60008060408385031215610c0357600080fd5b6000610c1185828601610b22565b9250506020610c2285828601610b37565b9150509250929050565b60008060408385031215610c3f57600080fd5b6000610c4d85828601610b22565b9250506020610c5e85828601610b76565b9150509250929050565b600060208284031215610c7a57600080fd5b6000610c8884828501610b4c565b91505092915050565b600060208284031215610ca357600080fd5b6000610cb184828501610b61565b91505092915050565b60008060408385031215610ccd57600080fd5b6000610cdb85828601610b76565b9250506020610cec85828601610b76565b9150509250929050565b6000610d028383610da1565b60208301905092915050565b610d1781611009565b82525050565b610d2e610d2982611009565b611103565b82525050565b6000610d3f82610f2f565b610d498185610f52565b9350610d5483610f1f565b8060005b83811015610d85578151610d6c8882610cf6565b9750610d7783610f45565b925050600181019050610d58565b5085935050505092915050565b610d9b8161101b565b82525050565b610daa81611027565b82525050565b610db981611027565b82525050565b6000610dca82610f3a565b610dd48185610f63565b9350610de4818560208601611087565b80840191505092915050565b6000610dfd601783610f6e565b91507f6f776e65722063616e6e6f74206265206368616e6765640000000000000000006000830152602082019050919050565b610e398161107d565b82525050565b6000610e4b8284610d1d565b60148201915081905092915050565b6000610e668284610dbf565b915081905092915050565b6000602082019050610e866000830184610d0e565b92915050565b60006020820190508181036000830152610ea68184610d34565b905092915050565b6000602082019050610ec36000830184610d92565b92915050565b6000602082019050610ede6000830184610db0565b92915050565b60006020820190508181036000830152610efd81610df0565b9050919050565b6000602082019050610f196000830184610e30565b92915050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b6000610f8a8261107d565b9150610f958361107d565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610fca57610fc9611127565b5b828201905092915050565b6000610fe08261107d565b9150610feb8361107d565b925082821015610ffe57610ffd611127565b5b828203905092915050565b60006110148261105d565b9050919050565b60008115159050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156110a557808201518184015260208101905061108a565b838111156110b4576000848401525b50505050565b60006110c58261107d565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156110f8576110f7611127565b5b600182019050919050565b600061110e82611115565b9050919050565b600061112082611156565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160601b9050919050565b61116c81611009565b811461117757600080fd5b50565b61118381611027565b811461118e57600080fd5b50565b61119a81611031565b81146111a557600080fd5b50565b6111b18161107d565b81146111bc57600080fd5b5056fea26469706673582212204460994967d4a16fb30d1f457d533e6929ca94e119064c8d4865ff61ed18590864736f6c63430008000033 +\ No newline at end of file diff --git a/solidity/AddressDeclarator.json b/solidity/AddressDeclarator.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"contents","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"declarator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"declaratorCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}] +[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"addDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"contents","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"}],"name":"declaration","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declarationAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_declarator","type":"address"}],"name":"declarationCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"},{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"declaratorAddressAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_subject","type":"address"}],"name":"declaratorCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}] diff --git a/solidity/AddressDeclarator.sol b/solidity/AddressDeclarator.sol @@ -7,8 +7,10 @@ contract AddressDeclarator { // EIP 173 address public owner; - mapping( bytes32 => uint256 ) declarations; - mapping( address => address[] ) public declarator; + mapping( address => address[] ) declarationIndex; + mapping( bytes32 => uint256 ) declarationContentIndex; + mapping( address => address[] ) declarator; + mapping( address => address[] ) declaratorReverse; bytes32[][] public contents; constructor(bytes32 _initialDescription) { @@ -50,28 +52,41 @@ contract AddressDeclarator { return declarator[_subject].length; } + function declaratorAddressAt(address _subject, uint256 _idx) public view returns ( address ) { + return declarator[_subject][_idx]; + } + function addDeclaration(address _subject, bytes32 _proof) public returns ( bool ) { bytes32 k; bytes32[] memory declarationContents; - uint256 declarationsIndex; + uint256 idx; k = toReference(msg.sender, _subject); - declarationsIndex = declarations[k]; - if (declarationsIndex == 0) { // This also works for the constructor :) + idx = declarationContentIndex[k]; + if (idx == 0) { // This also works for the constructor :) declarator[_subject].push(msg.sender); - contents.push(declarationContents); //= contents[declarationsIndex], + contents.push(declarationContents); //= contents[idx], + declarationIndex[msg.sender].push(_subject); } - declarationsIndex = contents.length-1; - declarations[k] = declarationsIndex; - contents[declarationsIndex].push(_proof); + idx = contents.length-1; + declarationContentIndex[k] = idx; + contents[idx].push(_proof); return true; } function declaration(address _declarator, address _subject) public view returns ( bytes32[] memory ) { bytes32 k; - uint256 i; + uint256 idx; k = toReference(_declarator, _subject); - i = declarations[k]; - return contents[i]; + idx = declarationContentIndex[k]; + return contents[idx]; + } + + function declarationCount(address _declarator) public view returns ( uint256 ) { + return declarationIndex[_declarator].length; + } + + function declarationAddressAt(address _declarator, uint256 _idx) public view returns ( address ) { + return declarationIndex[_declarator][_idx]; } } diff --git a/solidity/Makefile b/solidity/Makefile @@ -2,6 +2,10 @@ all: solc AddressDeclarator.sol --abi | awk 'NR>3' > AddressDeclarator.json solc AddressDeclarator.sol --bin | awk 'NR>3' > AddressDeclarator.bin truncate -s -1 AddressDeclarator.bin + solc TokenUniqueSymbolIndex.sol --abi | awk 'NR>3' > TokenUniqueSymbolIndex.json + solc TokenUniqueSymbolIndex.sol --bin | awk 'NR>3' > TokenUniqueSymbolIndex.bin + truncate -s -1 TokenUniqueSymbolIndex.bin + old: solc TokenEndorser.sol --abi | awk 'NR>3' > TokenEndorser.json @@ -9,6 +13,7 @@ old: truncate -s -1 TokenEndorser.bin test: all - python test.py + #python test.py + python test_tokenindex.py .PHONY: test diff --git a/solidity/TokenUniqueSymbolIndex.bin b/solidity/TokenUniqueSymbolIndex.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600260009080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506109e3806100c46000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638da5cb5b1161005b5780638da5cb5b146100ec578063bb34534c1461010a578063cbb834341461013a578063d22057a9146101585761007d565b80634f64b2be146100825780637ef50298146100b2578063880ad0af146100e2575b600080fd5b61009c600480360381019061009791906106dd565b610188565b6040516100a991906107bb565b60405180910390f35b6100cc60048036038101906100c7919061060e565b6101c7565b6040516100d99190610811565b60405180910390f35b6100ea6101df565b005b6100f461021a565b60405161010191906107bb565b60405180910390f35b610124600480360381019061011f919061060e565b61023e565b60405161013191906107bb565b60405180910390f35b6101426102c4565b60405161014f9190610811565b60405180910390f35b610172600480360381019061016d9190610660565b6102d1565b60405161017f91906107d6565b60405180910390f35b6002818154811061019857600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60016020528060005260406000206000915090505481565b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610211906107f1565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806001600084815260200190815260200160002054905060028181548110610291577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16915050919050565b6000600280549050905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461032c57600080fd5b60606000806000808673ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f95d89b41000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516103db91906107a4565b6000604051808303816000865af19150503d8060008114610418576040519150601f19603f3d011682016040523d82523d6000602084013e61041d565b606091505b50915091508161042c57600080fd5b80806020019051810190610440919061069c565b945060028560405161045291906107a4565b602060405180830381855afa15801561046f573d6000803e3d6000fd5b5050506040513d601f19601f820116820180604052508101906104929190610637565b93508388146104a057600080fd5b60016000858152602001908152602001600020549250600083146104c357600080fd5b60028054905060016000868152602001908152602001600020819055506002879080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060019550505050505092915050565b60006105656105608461085d565b61082c565b90508281526020810184848401111561057d57600080fd5b610588848285610906565b509392505050565b60008135905061059f81610968565b92915050565b6000813590506105b48161097f565b92915050565b6000815190506105c98161097f565b92915050565b600082601f8301126105e057600080fd5b81516105f0848260208601610552565b91505092915050565b60008135905061060881610996565b92915050565b60006020828403121561062057600080fd5b600061062e848285016105a5565b91505092915050565b60006020828403121561064957600080fd5b6000610657848285016105ba565b91505092915050565b6000806040838503121561067357600080fd5b6000610681858286016105a5565b925050602061069285828601610590565b9150509250929050565b6000602082840312156106ae57600080fd5b600082015167ffffffffffffffff8111156106c857600080fd5b6106d4848285016105cf565b91505092915050565b6000602082840312156106ef57600080fd5b60006106fd848285016105f9565b91505092915050565b61070f816108b4565b82525050565b61071e816108c6565b82525050565b600061072f8261088d565b6107398185610898565b9350610749818560208601610906565b80840191505092915050565b60006107626017836108a3565b91507f6f776e65722063616e6e6f74206265206368616e6765640000000000000000006000830152602082019050919050565b61079e816108fc565b82525050565b60006107b08284610724565b915081905092915050565b60006020820190506107d06000830184610706565b92915050565b60006020820190506107eb6000830184610715565b92915050565b6000602082019050818103600083015261080a81610755565b9050919050565b60006020820190506108266000830184610795565b92915050565b6000604051905081810181811067ffffffffffffffff8211171561085357610852610939565b5b8060405250919050565b600067ffffffffffffffff82111561087857610877610939565b5b601f19601f8301169050602081019050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006108bf826108dc565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b83811015610924578082015181840152602081019050610909565b83811115610933576000848401525b50505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610971816108b4565b811461097c57600080fd5b50565b610988816108d2565b811461099357600080fd5b50565b61099f816108fc565b81146109aa57600080fd5b5056fea264697066735822122065acf4d9b69a14b392a3392cf17e2db9d96934bf3e05a4ed9f7d8be85f6aebaa64736f6c63430008000033 +\ No newline at end of file diff --git a/solidity/TokenUniqueSymbolIndex.json b/solidity/TokenUniqueSymbolIndex.json @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"},{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}] diff --git a/solidity/TokenUniqueSymbolIndex.sol b/solidity/TokenUniqueSymbolIndex.sol @@ -0,0 +1,55 @@ +pragma solidity >=0.6.12; + +// SPDX-License-Identifier: GPL-3.0-or-later + +contract TokenUniqueSymbolIndex { + + // EIP 173 + address public owner; + + mapping ( bytes32 => uint256 ) public registry; + address[] public tokens; + + constructor() { + owner = msg.sender; + tokens.push(address(0)); + } + + // EIP 172 + function transferOwnership() public { + revert("owner cannot be changed"); + } + + function addressOf(bytes32 _key) public view returns ( address ) { + uint256 idx; + + idx = registry[_key]; + return tokens[idx]; + } + + function register(bytes32 _key, address _token) public returns (bool) { + require(msg.sender == owner); + + bytes memory token_symbol; + bytes32 token_symbol_key; + uint256 idx; + + (bool _ok, bytes memory _r) = _token.call(abi.encodeWithSignature('symbol()')); + require(_ok); + + token_symbol = abi.decode(_r, (bytes)); + token_symbol_key = sha256(token_symbol); + + require(_key == token_symbol_key); + idx = registry[token_symbol_key]; + require(idx == 0); + + registry[token_symbol_key] = tokens.length; + tokens.push(_token); + return true; + } + + function registryCount() public view returns ( uint256 ) { + return tokens.length; + } +} diff --git a/solidity/test.py b/solidity/test.py @@ -36,6 +36,7 @@ declarations = [ ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], + ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], ] # Deployment is a self-signed declaration @@ -48,7 +49,7 @@ c = w3.eth.contract(abi=abi, address=r.contractAddress) r = c.functions.declaratorCount(w3.eth.accounts[0]).call() assert r == 1 -r = c.functions.declarator(w3.eth.accounts[0], 0).call() +r = c.functions.declaratorAddressAt(w3.eth.accounts[0], 0).call() assert r == w3.eth.accounts[0] r = c.functions.declaration(w3.eth.accounts[0], w3.eth.accounts[0]).call() @@ -61,7 +62,7 @@ c.functions.addDeclaration(w3.eth.accounts[0], declarations[1][0]).transact({'fr r = c.functions.declaratorCount(w3.eth.accounts[0]).call() assert r == 2 -r = c.functions.declarator(w3.eth.accounts[0], 1).call() +r = c.functions.declaratorAddressAt(w3.eth.accounts[0], 1).call() assert r == w3.eth.accounts[2] r = c.functions.declaration(w3.eth.accounts[2], w3.eth.accounts[0]).call() @@ -89,9 +90,45 @@ assert r == 2 r = c.functions.declaratorCount(w3.eth.accounts[1]).call() assert r == 1 -r = c.functions.declarator(w3.eth.accounts[1], 0).call() +r = c.functions.declaratorAddressAt(w3.eth.accounts[1], 0).call() assert r == w3.eth.accounts[2] r = c.functions.declaration(w3.eth.accounts[2], w3.eth.accounts[1]).call() assert r[0].hex() == declarations[2][0][2:] + +# Add declaration for 0 by 3 +c.functions.addDeclaration(w3.eth.accounts[0], declarations[3][0]).transact({'from': w3.eth.accounts[3]}) + + +# 0 declared itself and 1 +r = c.functions.declarationCount(w3.eth.accounts[0]).call() +assert r == 1 + +# 0 was declared by itself, 1 and 3 +r = c.functions.declaratorCount(w3.eth.accounts[0]).call() +assert r == 3 + +# 1 declared noone +r = c.functions.declarationCount(w3.eth.accounts[1]).call() +assert r == 0 + +# 1 was declared by 2 +r = c.functions.declaratorCount(w3.eth.accounts[1]).call() +assert r == 1 + +# 2 declared 0 and 1 +r = c.functions.declarationCount(w3.eth.accounts[2]).call() +assert r == 2 + +# 2 was declared by noone +r = c.functions.declaratorCount(w3.eth.accounts[2]).call() +assert r == 0 + +# 3 declared 0 +r = c.functions.declarationCount(w3.eth.accounts[3]).call() +assert r == 1 + +# 3 was declared by noone +r = c.functions.declaratorCount(w3.eth.accounts[3]).call() +assert r == 0 diff --git a/solidity/test_addressdeclarator.py b/solidity/test_addressdeclarator.py @@ -0,0 +1,134 @@ +import logging +import os +import json +import hashlib + +import web3 +import eth_tester + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + + +eth_params = eth_tester.backends.pyevm.main.get_default_genesis_params({ + 'gas_limit': 9000000, + }) +backend = eth_tester.PyEVMBackend(eth_params) +instance = eth_tester.EthereumTester(backend) +provider = web3.Web3.EthereumTesterProvider(instance) +w3 = web3.Web3(provider) + + +f = open('AddressDeclarator.bin', 'r') +bytecode = f.read() +f.close() + +f = open('AddressDeclarator.json', 'r') +abi = json.load(f) +f.close() + +#token_address = web3.Web3.toChecksumAddress('0x' + os.urandom(20).hex()) + +c = w3.eth.contract(abi=abi, bytecode=bytecode) +#tx_hash = c.constructor().transact({'from': w3.eth.accounts[0]}) + +declarations = [ + ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], + ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], + ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], + ['0x' + os.urandom(32).hex(), '0x' + os.urandom(32).hex()], + ] + +# Deployment is a self-signed declaration +tx_hash = c.constructor(declarations[0][0]).transact({'from': w3.eth.accounts[0]}) +r = w3.eth.getTransactionReceipt(tx_hash) +logg.debug('contract {}'.format(r.contractAddress)) + +c = w3.eth.contract(abi=abi, address=r.contractAddress) + +r = c.functions.declaratorCount(w3.eth.accounts[0]).call() +assert r == 1 + +r = c.functions.declaratorAddressAt(w3.eth.accounts[0], 0).call() +assert r == w3.eth.accounts[0] + +r = c.functions.declaration(w3.eth.accounts[0], w3.eth.accounts[0]).call() +assert r[0].hex() == declarations[0][0][2:] + + +# Add first declaration for 0 by 2 +c.functions.addDeclaration(w3.eth.accounts[0], declarations[1][0]).transact({'from': w3.eth.accounts[2]}) + +r = c.functions.declaratorCount(w3.eth.accounts[0]).call() +assert r == 2 + +r = c.functions.declaratorAddressAt(w3.eth.accounts[0], 1).call() +assert r == w3.eth.accounts[2] + +r = c.functions.declaration(w3.eth.accounts[2], w3.eth.accounts[0]).call() +assert r[0].hex() == declarations[1][0][2:] + + +# Add second declaration for 0 by 2 +c.functions.addDeclaration(w3.eth.accounts[0], declarations[1][1]).transact({'from': w3.eth.accounts[2]}) + +r = c.functions.declaratorCount(w3.eth.accounts[0]).call() +assert r == 2 + + +r = c.functions.declaration(w3.eth.accounts[2], w3.eth.accounts[0]).call() +assert r[0].hex() == declarations[1][0][2:] +assert r[1].hex() == declarations[1][1][2:] + + +# Add first declaration for 1 by 2 +c.functions.addDeclaration(w3.eth.accounts[1], declarations[2][0]).transact({'from': w3.eth.accounts[2]}) + +r = c.functions.declaratorCount(w3.eth.accounts[0]).call() +assert r == 2 + +r = c.functions.declaratorCount(w3.eth.accounts[1]).call() +assert r == 1 + +r = c.functions.declaratorAddressAt(w3.eth.accounts[1], 0).call() +assert r == w3.eth.accounts[2] + +r = c.functions.declaration(w3.eth.accounts[2], w3.eth.accounts[1]).call() +assert r[0].hex() == declarations[2][0][2:] + + +# Add declaration for 0 by 3 +c.functions.addDeclaration(w3.eth.accounts[0], declarations[3][0]).transact({'from': w3.eth.accounts[3]}) + + +# 0 declared itself and 1 +r = c.functions.declarationCount(w3.eth.accounts[0]).call() +assert r == 1 + +# 0 was declared by itself, 1 and 3 +r = c.functions.declaratorCount(w3.eth.accounts[0]).call() +assert r == 3 + +# 1 declared noone +r = c.functions.declarationCount(w3.eth.accounts[1]).call() +assert r == 0 + +# 1 was declared by 2 +r = c.functions.declaratorCount(w3.eth.accounts[1]).call() +assert r == 1 + +# 2 declared 0 and 1 +r = c.functions.declarationCount(w3.eth.accounts[2]).call() +assert r == 2 + +# 2 was declared by noone +r = c.functions.declaratorCount(w3.eth.accounts[2]).call() +assert r == 0 + +# 3 declared 0 +r = c.functions.declarationCount(w3.eth.accounts[3]).call() +assert r == 1 + +# 3 was declared by noone +r = c.functions.declaratorCount(w3.eth.accounts[3]).call() +assert r == 0 diff --git a/solidity/tokenendorser_test.py b/solidity/test_tokenendorser.py diff --git a/solidity/test_tokenindex.py b/solidity/test_tokenindex.py @@ -0,0 +1,54 @@ +import logging +import os +import json +import hashlib + +import web3 +import eth_tester + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + + +eth_params = eth_tester.backends.pyevm.main.get_default_genesis_params({ + 'gas_limit': 9000000, + }) +backend = eth_tester.PyEVMBackend(eth_params) +instance = eth_tester.EthereumTester(backend) +provider = web3.Web3.EthereumTesterProvider(instance) +w3 = web3.Web3(provider) + + +f = open('TokenUniqueSymbolIndex.bin', 'r') +bytecode = f.read() +f.close() + +f = open('TokenUniqueSymbolIndex.json', 'r') +abi = json.load(f) +f.close() + +token_address = web3.Web3.toChecksumAddress('0x' + os.urandom(20).hex()) + +c = w3.eth.contract(abi=abi, bytecode=bytecode) +tx_hash = c.constructor().transact({'from': w3.eth.accounts[0]}) +r = w3.eth.getTransactionReceipt(tx_hash) +logg.debug('contract {}'.format(r.contractAddress)) + +c = w3.eth.contract(abi=abi, address=r.contractAddress) +d = '0x' + os.urandom(32).hex() + +# Initial token will fail in any case +h =hashlib.new('sha256') +h.update('FOO'.encode('utf-8')) +z = h.digest() +foo_symbol = z.hex() + +fail = False +try: + c.functions.register(foo_symbol, token_address).transact({'from':w3.eth.accounts[0]}) +except: + fail = True + pass + +if not fail: + raise RuntimeError('expected fail on register same token to same address')