Fix address declarator executables

This commit is contained in:
nolash
2020-12-29 19:44:14 +01:00
parent 4400240b3e
commit d659ae72f5
24 changed files with 627 additions and 92 deletions

View File

@@ -0,0 +1 @@
from .declarator import AddressDeclarator

File diff suppressed because one or more lines are too long

View File

@@ -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"}]

File diff suppressed because one or more lines are too long

View File

@@ -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"}]

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

File diff suppressed because one or more lines are too long

View File

@@ -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"}]

View File

@@ -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

View File

@@ -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]})
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]})
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]})
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('FOO'.encode('utf-8'))
z = h.digest()
assert d[2:] == c.functions.endorsement(z.hex()).call().hex()
# owner text
with self.assertRaises(Exception):
c.functions.register(z.hex(), self.address_token_one).transact({'from': self.w3.eth.accounts[1]})
c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[0]})
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]})
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
# 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]})
assert c.functions.tokens(1).call() == self.address_token_one
assert c.functions.tokens(2).call() == self.address_token_two
# 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]})
assert c.functions.tokenIndex(self.address_token_one).call() == 1
assert c.functions.tokenIndex(self.address_token_two).call() == 2
h = hashlib.new('sha256')
h.update('BAR'.encode('utf-8'))
z = h.digest()
# 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__':

View File

@@ -2,13 +2,12 @@ import os
import unittest
import json
import logging
import hashlib
import web3
import eth_tester
import eth_abi
from eth_token_endorser import TokenEndorser
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -73,32 +72,62 @@ class Test(unittest.TestCase):
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_basic(self):
c = self.w3.eth.contract(abi=self.abi, address=self.address)
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)
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]})
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]})
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]})
h = hashlib.new('sha256')
h.update(bytes.fromhex(self.address_token_one[2:]))
h.update(bytes.fromhex(self.w3.eth.accounts[0][2:]))
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
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);
if __name__ == '__main__':