mirror of
git://holbrook.no/eth-address-index
synced 2026-04-25 10:17:14 +02:00
Compare commits
1 Commits
v0.6.2
...
lash/funga
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5621c53df
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,5 +4,3 @@ dist/
|
|||||||
__pycache__
|
__pycache__
|
||||||
*.pyc
|
*.pyc
|
||||||
gmon.out
|
gmon.out
|
||||||
.idea
|
|
||||||
venv
|
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
stages:
|
|
||||||
- test
|
|
||||||
- run-coverage
|
|
||||||
- slither-analyzer
|
|
||||||
|
|
||||||
|
|
||||||
variables:
|
|
||||||
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .cache/pip
|
|
||||||
- .venv/
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- python -V # Print out python version for debugging
|
|
||||||
- pip install virtualenv
|
|
||||||
- virtualenv venv
|
|
||||||
- source venv/bin/activate
|
|
||||||
|
|
||||||
test:
|
|
||||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
|
||||||
script:
|
|
||||||
# install test dependencies
|
|
||||||
- cd python
|
|
||||||
- export PYTHONPATH=.
|
|
||||||
- pip install --extra-index-url https://pip.grassrootseconomics.net
|
|
||||||
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
|
|
||||||
-r requirements.txt -r test_requirements.txt
|
|
||||||
# run tests
|
|
||||||
- bash run_tests.sh
|
|
||||||
|
|
||||||
run-coverage:
|
|
||||||
stage: test
|
|
||||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
|
||||||
script:
|
|
||||||
- cd python
|
|
||||||
- export PYTHONPATH=.
|
|
||||||
- pip install --extra-index-url https://pip.grassrootseconomics.net
|
|
||||||
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
|
|
||||||
-r requirements.txt -r test_requirements.txt
|
|
||||||
- pip install pytest pytest-cov
|
|
||||||
- coverage run -m pytest
|
|
||||||
- coverage html
|
|
||||||
- coverage report --fail-under=90
|
|
||||||
|
|
||||||
coverage: '/^TOTAL.+?(\d+\%)$/'
|
|
||||||
artifacts:
|
|
||||||
reports:
|
|
||||||
cobertura: python/htmlcov/index.html
|
|
||||||
|
|
||||||
slither-analyzer:
|
|
||||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
|
||||||
allow_failure: true
|
|
||||||
script:
|
|
||||||
- cd solidity
|
|
||||||
- slither AddressDeclarator.sol
|
|
||||||
- slither AddressDeclarator.sol --print human-summary
|
|
||||||
BIN
python/.coverage
BIN
python/.coverage
Binary file not shown.
@@ -1,7 +0,0 @@
|
|||||||
[run]
|
|
||||||
branch = True
|
|
||||||
[report]
|
|
||||||
omit = .venv/*
|
|
||||||
**/runnable/*.py
|
|
||||||
[html]
|
|
||||||
|
|
||||||
@@ -1,18 +1,4 @@
|
|||||||
- 0.6.2
|
- 0.1.2-pending
|
||||||
* Remove haveDeclaration solidity method
|
|
||||||
- 0.6.1
|
|
||||||
* Fix broken calls for some chains; force block height parameter
|
|
||||||
- 0.6.0
|
|
||||||
* Upgrade deps
|
|
||||||
- 0.5.0
|
|
||||||
* Upgrade deps
|
|
||||||
- 0.4.0
|
|
||||||
* Upgrade chainlib
|
|
||||||
- 0.3.0
|
|
||||||
* Use -a and -e flag combination for consistency
|
|
||||||
- 0.2.5
|
|
||||||
* Remove proof array idx overwrite when adding multiple proofs to subject
|
|
||||||
- 0.1.2
|
|
||||||
* Move to chainlib-eth
|
* Move to chainlib-eth
|
||||||
- 0.1.1-unreleased
|
- 0.1.1-unreleased
|
||||||
- 0.1.0-unreleased
|
- 0.1.0-unreleased
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"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":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
|
[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"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":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"haveDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ from chainlib.eth.contract import (
|
|||||||
)
|
)
|
||||||
from chainlib.jsonrpc import JSONRPCRequest
|
from chainlib.jsonrpc import JSONRPCRequest
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
from chainlib.block import BlockSpec
|
|
||||||
from chainlib.eth.jsonrpc import to_blockheight_param
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -41,7 +39,7 @@ class Declarator(TxFactory):
|
|||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
||||||
def declarator_count(self, contract_address, subject_address, sender_address=ZERO_ADDRESS, id_generator=None, height=BlockSpec.LATEST):
|
def declarator_count(self, contract_address, subject_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_call'
|
o['method'] = 'eth_call'
|
||||||
@@ -53,13 +51,11 @@ class Declarator(TxFactory):
|
|||||||
tx = self.template(sender_address, contract_address)
|
tx = self.template(sender_address, contract_address)
|
||||||
tx = self.set_code(tx, data)
|
tx = self.set_code(tx, data)
|
||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
height = to_blockheight_param(height)
|
|
||||||
o['params'].append(height)
|
|
||||||
o = j.finalize(o)
|
o = j.finalize(o)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def declaration(self, contract_address, declarator_address, subject_address, sender_address=ZERO_ADDRESS, id_generator=None, height=BlockSpec.LATEST):
|
def declaration(self, contract_address, declarator_address, subject_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_call'
|
o['method'] = 'eth_call'
|
||||||
@@ -73,13 +69,11 @@ class Declarator(TxFactory):
|
|||||||
tx = self.template(sender_address, contract_address)
|
tx = self.template(sender_address, contract_address)
|
||||||
tx = self.set_code(tx, data)
|
tx = self.set_code(tx, data)
|
||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
height = to_blockheight_param(height)
|
|
||||||
o['params'].append(height)
|
|
||||||
o = j.finalize(o)
|
o = j.finalize(o)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def declaration_address_at(self, contract_address, declarator_address, idx, sender_address=ZERO_ADDRESS, id_generator=None, height=BlockSpec.LATEST):
|
def declaration_address_at(self, contract_address, declarator_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_call'
|
o['method'] = 'eth_call'
|
||||||
@@ -93,13 +87,11 @@ class Declarator(TxFactory):
|
|||||||
tx = self.template(sender_address, contract_address)
|
tx = self.template(sender_address, contract_address)
|
||||||
tx = self.set_code(tx, data)
|
tx = self.set_code(tx, data)
|
||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
height = to_blockheight_param(height)
|
|
||||||
o['params'].append(height)
|
|
||||||
o = j.finalize(o)
|
o = j.finalize(o)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def declarator_address_at(self, contract_address, subject_address, idx, sender_address=ZERO_ADDRESS, id_generator=None, height=BlockSpec.LATEST):
|
def declarator_address_at(self, contract_address, subject_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_call'
|
o['method'] = 'eth_call'
|
||||||
@@ -113,8 +105,6 @@ class Declarator(TxFactory):
|
|||||||
tx = self.template(sender_address, contract_address)
|
tx = self.template(sender_address, contract_address)
|
||||||
tx = self.set_code(tx, data)
|
tx = self.set_code(tx, data)
|
||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
height = to_blockheight_param(height)
|
|
||||||
o['params'].append(height)
|
|
||||||
o = j.finalize(o)
|
o = j.finalize(o)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
@@ -127,15 +117,12 @@ class Declarator(TxFactory):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def parse_declaration(self, v):
|
def parse_declaration(self, v):
|
||||||
cursor = 0
|
cursor = 0
|
||||||
r = []
|
v = strip_0x(v)
|
||||||
try:
|
|
||||||
v = strip_0x(v)
|
|
||||||
except ValueError:
|
|
||||||
return r
|
|
||||||
position = int.from_bytes(bytes.fromhex(v[cursor:cursor+64]), 'big')
|
position = int.from_bytes(bytes.fromhex(v[cursor:cursor+64]), 'big')
|
||||||
cursor += (position * 2)
|
cursor += (position * 2)
|
||||||
length = int.from_bytes(bytes.fromhex(v[cursor:cursor+64]), 'big')
|
length = int.from_bytes(bytes.fromhex(v[cursor:cursor+64]), 'big')
|
||||||
cursor += 64
|
cursor += 64
|
||||||
|
r = []
|
||||||
for i in range(length):
|
for i in range(length):
|
||||||
r.append(v[cursor:cursor+64])
|
r.append(v[cursor:cursor+64])
|
||||||
cursor += 64
|
cursor += 64
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Adds a new Address declaration
|
"""Adds a new Address declaration
|
||||||
|
|
||||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||||
|
|
||||||
@@ -6,6 +7,8 @@
|
|||||||
|
|
||||||
# standard imports
|
# standard imports
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
@@ -18,19 +21,6 @@ from hexathon import (
|
|||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
)
|
)
|
||||||
from chainlib.eth.cli.arg import (
|
|
||||||
Arg,
|
|
||||||
ArgFlag,
|
|
||||||
process_args,
|
|
||||||
)
|
|
||||||
from chainlib.eth.cli.config import (
|
|
||||||
Config,
|
|
||||||
process_config,
|
|
||||||
)
|
|
||||||
from chainlib.eth.cli.log import process_log
|
|
||||||
from chainlib.eth.settings import process_settings
|
|
||||||
from chainlib.settings import ChainSettings
|
|
||||||
|
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from eth_address_declarator.declarator import AddressDeclarator
|
from eth_address_declarator.declarator import AddressDeclarator
|
||||||
@@ -38,57 +28,58 @@ from eth_address_declarator.declarator import AddressDeclarator
|
|||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(__file__)
|
||||||
|
data_dir = os.path.join(script_dir, '..', 'data')
|
||||||
|
|
||||||
def process_config_local(config, arg, args, flags):
|
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
|
||||||
hsh = strip_0x(config.get('_POSARG'))
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
if len(hsh) != 64:
|
argparser.add_argument('-a', '--address', type=str, help='Address to add declaration for')
|
||||||
raise ValueError('declaration hash must be 32 bytes')
|
argparser.add_positional('declaration', type=str, help='SHA256 sum of endorsement data to add')
|
||||||
config.add(hsh, '_DECLARATION')
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
arg_flags = ArgFlag()
|
|
||||||
arg = Arg(arg_flags)
|
|
||||||
flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC
|
|
||||||
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser()
|
|
||||||
argparser = process_args(argparser, arg, flags)
|
|
||||||
argparser.add_argument('declaration', type=str, help='SHA256 sum of endorsement data to add')
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
logg = process_log(args, logg)
|
extra_args = {
|
||||||
|
'address': None,
|
||||||
|
'declaration': None,
|
||||||
|
}
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=AddressDeclarator.gas())
|
||||||
|
|
||||||
config = Config()
|
wallet = chainlib.eth.cli.Wallet()
|
||||||
config = process_config(config, arg, args, flags, positional_name='declaration')
|
wallet.from_config(config)
|
||||||
config = process_config_local(config, arg, args, flags)
|
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
|
||||||
|
|
||||||
settings = ChainSettings()
|
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
||||||
settings = process_settings(settings, config)
|
conn = rpc.connect_by_config(config)
|
||||||
logg.debug('settings loaded:\n{}'.format(settings))
|
|
||||||
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
conn = settings.get('CONN')
|
signer = rpc.get_signer()
|
||||||
c = AddressDeclarator(
|
signer_address = rpc.get_sender_address()
|
||||||
settings.get('CHAIN_SPEC'),
|
|
||||||
signer=settings.get('SIGNER'),
|
|
||||||
gas_oracle=settings.get('FEE_ORACLE'),
|
|
||||||
nonce_oracle=settings.get('NONCE_ORACLE'),
|
|
||||||
)
|
|
||||||
subject_address = to_checksum_address(settings.get('RECIPIENT'))
|
|
||||||
contract_address = to_checksum_address(settings.get('EXEC'))
|
|
||||||
|
|
||||||
(tx_hash_hex, o) = c.add_declaration(
|
gas_oracle = rpc.get_gas_oracle()
|
||||||
settings.get('EXEC'),
|
nonce_oracle = rpc.get_nonce_oracle()
|
||||||
settings.get('SENDER_ADDRESS'),
|
|
||||||
settings.get('RECIPIENT'),
|
|
||||||
add_0x(config.get('_DECLARATION')),
|
|
||||||
)
|
|
||||||
|
|
||||||
if settings.get('RPC_SEND'):
|
c = AddressDeclarator(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
subject_address = to_checksum_address(config.get('_ADDRESS'))
|
||||||
|
if not config.true('_UNSAFE') and subject_address != add_0x(config.get('_ADDRESS')):
|
||||||
|
raise ValueError('invalid checksum address for subject_address')
|
||||||
|
|
||||||
|
contract_address = to_checksum_address(config.get('_EXEC_ADDRESS'))
|
||||||
|
if not config.true('_UNSAFE') and contract_address != add_0x(config.get('_EXEC_ADDRESS')):
|
||||||
|
raise ValueError('invalid checksum address for contract')
|
||||||
|
|
||||||
|
declaration = config.get('_DECLARATION')
|
||||||
|
declaration_bytes = bytes.fromhex(strip_0x(declaration))
|
||||||
|
if len(declaration_bytes) != 32:
|
||||||
|
raise ValueError('declaration hash must be 32 bytes')
|
||||||
|
declaration = add_0x(declaration)
|
||||||
|
|
||||||
|
(tx_hash_hex, o) = c.add_declaration(contract_address, signer_address, subject_address, declaration)
|
||||||
|
|
||||||
|
if config.get('_RPC_SEND'):
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
if config.true('_WAIT'):
|
if config.get('_WAIT'):
|
||||||
r = conn.wait(tx_hash_hex)
|
r = conn.wait(tx_hash_hex)
|
||||||
if r['status'] == 0:
|
if r['status'] == 0:
|
||||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||||
|
|||||||
84
python/eth_address_declarator/runnable/deploy.py
Normal file
84
python/eth_address_declarator/runnable/deploy.py
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
"""Deploys address declaration contract
|
||||||
|
|
||||||
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||||
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# standard imports
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
from hexathon import (
|
||||||
|
add_0x,
|
||||||
|
strip_0x,
|
||||||
|
)
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
import chainlib.eth.cli
|
||||||
|
from chainlib.chain import ChainSpec
|
||||||
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from eth_address_declarator.declarator import AddressDeclarator
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
arg_flags = chainlib.eth.cli.argflag_std_write
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
|
argparser.add_argument('owner_description_hash', type=str, help='SHA256 of description metadata of contract deployer')
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
extra_args = {
|
||||||
|
'owner_description_hash': None,
|
||||||
|
}
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=AddressDeclarator.gas())
|
||||||
|
|
||||||
|
wallet = chainlib.eth.cli.Wallet()
|
||||||
|
wallet.from_config(config)
|
||||||
|
|
||||||
|
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
||||||
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
signer = rpc.get_signer()
|
||||||
|
signer_address = rpc.get_sender_address()
|
||||||
|
|
||||||
|
gas_oracle = rpc.get_gas_oracle()
|
||||||
|
nonce_oracle = rpc.get_nonce_oracle()
|
||||||
|
|
||||||
|
c = AddressDeclarator(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
owner_description_hash = config.get('_OWNER_DESCRIPTION_HASH')
|
||||||
|
owner_description_hash_bytes = bytes.fromhex(strip_0x(owner_description_hash))
|
||||||
|
if len(owner_description_hash_bytes) != 32:
|
||||||
|
raise ValueError('chain config hash must be 32 bytes')
|
||||||
|
owner_description_hash = add_0x(owner_description_hash)
|
||||||
|
|
||||||
|
(tx_hash_hex, o) = c.constructor(signer_address, owner_description_hash)
|
||||||
|
if config.get('_RPC_SEND'):
|
||||||
|
conn.do(o)
|
||||||
|
if config.get('_WAIT'):
|
||||||
|
r = conn.wait(tx_hash_hex)
|
||||||
|
if r['status'] == 0:
|
||||||
|
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||||
|
sys.exit(1)
|
||||||
|
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
|
||||||
|
address = r['contractAddress']
|
||||||
|
|
||||||
|
print(address)
|
||||||
|
else:
|
||||||
|
print(tx_hash_hex)
|
||||||
|
else:
|
||||||
|
print(o)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
"""Deploys address declaration contract
|
|
||||||
|
|
||||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
|
||||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
# standard imports
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import logging
|
|
||||||
from hexathon import (
|
|
||||||
add_0x,
|
|
||||||
strip_0x,
|
|
||||||
)
|
|
||||||
|
|
||||||
# external imports
|
|
||||||
import chainlib.eth.cli
|
|
||||||
from chainlib.chain import ChainSpec
|
|
||||||
from chainlib.eth.connection import EthHTTPConnection
|
|
||||||
from chainlib.eth.tx import receipt
|
|
||||||
from chainlib.eth.cli.arg import (
|
|
||||||
Arg,
|
|
||||||
ArgFlag,
|
|
||||||
process_args,
|
|
||||||
)
|
|
||||||
from chainlib.eth.cli.config import (
|
|
||||||
Config,
|
|
||||||
process_config,
|
|
||||||
)
|
|
||||||
from chainlib.eth.cli.log import process_log
|
|
||||||
from chainlib.eth.settings import process_settings
|
|
||||||
from chainlib.settings import ChainSettings
|
|
||||||
from chainlib.eth.constant import ZERO_CONTENT
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from eth_address_declarator.declarator import AddressDeclarator
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
|
||||||
logg = logging.getLogger()
|
|
||||||
|
|
||||||
|
|
||||||
def process_config_local(config, arg, args, flags):
|
|
||||||
hsh = args.owner_description_hash
|
|
||||||
if hsh == None:
|
|
||||||
hsh = ZERO_CONTENT
|
|
||||||
hsh = add_0x(hsh)
|
|
||||||
config.add(hsh, '_OWNER_DESCRIPTION_HASH')
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
arg_flags = ArgFlag()
|
|
||||||
arg = Arg(arg_flags)
|
|
||||||
flags = arg_flags.STD_WRITE
|
|
||||||
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser()
|
|
||||||
argparser = process_args(argparser, arg, flags)
|
|
||||||
argparser.add_argument('--owner-description-hash', type=str, help='SHA256 of description metadata of contract deployer')
|
|
||||||
args = argparser.parse_args()
|
|
||||||
|
|
||||||
logg = process_log(args, logg)
|
|
||||||
|
|
||||||
config = Config()
|
|
||||||
config = process_config(config, arg, args, flags)
|
|
||||||
config = process_config_local(config, arg, args, flags)
|
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
|
||||||
|
|
||||||
settings = ChainSettings()
|
|
||||||
settings = process_settings(settings, config)
|
|
||||||
logg.debug('settings loaded:\n{}'.format(settings))
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
conn = settings.get('CONN')
|
|
||||||
c = AddressDeclarator(
|
|
||||||
settings.get('CHAIN_SPEC'),
|
|
||||||
signer=settings.get('SIGNER'),
|
|
||||||
gas_oracle=settings.get('FEE_ORACLE'),
|
|
||||||
nonce_oracle=settings.get('NONCE_ORACLE'),
|
|
||||||
)
|
|
||||||
owner_description_hash = config.get('_OWNER_DESCRIPTION_HASH')
|
|
||||||
owner_description_hash_bytes = bytes.fromhex(strip_0x(owner_description_hash))
|
|
||||||
if len(owner_description_hash_bytes) != 32:
|
|
||||||
raise ValueError('chain config hash must be 32 bytes')
|
|
||||||
|
|
||||||
(tx_hash_hex, o) = c.constructor(
|
|
||||||
settings.get('SENDER_ADDRESS'),
|
|
||||||
owner_description_hash,
|
|
||||||
)
|
|
||||||
if settings.get('RPC_SEND'):
|
|
||||||
conn.do(o)
|
|
||||||
if config.true('_WAIT'):
|
|
||||||
r = conn.wait(tx_hash_hex)
|
|
||||||
if r['status'] == 0:
|
|
||||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
|
||||||
sys.exit(1)
|
|
||||||
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
|
|
||||||
address = r['contractAddress']
|
|
||||||
|
|
||||||
print(address)
|
|
||||||
else:
|
|
||||||
print(tx_hash_hex)
|
|
||||||
else:
|
|
||||||
print(o)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
@@ -6,7 +6,10 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# standard imports
|
# standard imports
|
||||||
|
import urllib
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -15,24 +18,10 @@ import chainlib.eth.cli
|
|||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.error import JSONRPCException
|
from chainlib.error import JSONRPCException
|
||||||
from chainlib.eth.address import to_checksum_address
|
from chainlib.eth.address import to_checksum_address
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
)
|
)
|
||||||
from chainlib.eth.cli.arg import (
|
|
||||||
Arg,
|
|
||||||
ArgFlag,
|
|
||||||
process_args,
|
|
||||||
)
|
|
||||||
from chainlib.eth.cli.config import (
|
|
||||||
Config,
|
|
||||||
process_config,
|
|
||||||
)
|
|
||||||
from chainlib.eth.cli.log import process_log
|
|
||||||
from chainlib.eth.settings import process_settings
|
|
||||||
from chainlib.settings import ChainSettings
|
|
||||||
|
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from eth_address_declarator import Declarator
|
from eth_address_declarator import Declarator
|
||||||
@@ -41,46 +30,35 @@ from eth_address_declarator.declarator import AddressDeclarator
|
|||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
#argparser.add_argument('--resolve', action='store_true', help='Attempt to resolve the hashes to actual content')
|
||||||
def process_config_local(config, arg, args, flags):
|
#argparser.add_argument('--resolve-http', dest='resolve_http', type=str, help='Base url to look up content hashes')
|
||||||
a = strip_0x(config.get('_POSARG'))
|
arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC
|
||||||
ac = to_checksum_address(a)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
if config.true('_UNSAFE'):
|
argparser.add_argument('--declarator-address', required=True, type=str, help='Declarator of address')
|
||||||
a = ac
|
argparser.add_positional('address', type=str, help='Ethereum declaration address to look up')
|
||||||
else:
|
|
||||||
if a != ac:
|
|
||||||
raise ValueError('declarator is not a valid checksum address')
|
|
||||||
config.add(a, '_DECLARATOR')
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
arg_flags = ArgFlag()
|
|
||||||
arg = Arg(arg_flags)
|
|
||||||
flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC | arg_flags.SENDER
|
|
||||||
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser()
|
|
||||||
argparser = process_args(argparser, arg, flags)
|
|
||||||
argparser.add_argument('declarator', type=str, help='Ethereum declaration address to look up')
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
logg = process_log(args, logg)
|
extra_args = {
|
||||||
|
'declarator_address': None,
|
||||||
|
'address': None,
|
||||||
|
}
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=AddressDeclarator.gas())
|
||||||
|
|
||||||
config = Config()
|
wallet = chainlib.eth.cli.Wallet()
|
||||||
config = process_config(config, arg, args, flags, positional_name='declarator')
|
wallet.from_config(config)
|
||||||
config = process_config_local(config, arg, args, flags)
|
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
|
||||||
|
|
||||||
settings = ChainSettings()
|
rpc = chainlib.eth.cli.Rpc()
|
||||||
settings = process_settings(settings, config)
|
conn = rpc.connect_by_config(config)
|
||||||
logg.debug('settings loaded:\n{}'.format(settings))
|
|
||||||
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||||
|
|
||||||
|
|
||||||
def out_element(e, w=sys.stdout):
|
def out_element(e, w=sys.stdout):
|
||||||
w.write(e[1] + '\n')
|
w.write(e[1] + '\n')
|
||||||
|
|
||||||
|
|
||||||
def ls(ifc, conn, contract_address, declarator_address, subject_address, w=sys.stdout, sender_address=ZERO_ADDRESS):
|
def ls(ifc, conn, contract_address, declarator_address, subject_address, w=sys.stdout):
|
||||||
o = ifc.declaration(contract_address, declarator_address, subject_address, sender_address=sender_address)
|
o = ifc.declaration(contract_address, declarator_address, subject_address)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
declarations = ifc.parse_declaration(r)
|
declarations = ifc.parse_declaration(r)
|
||||||
|
|
||||||
@@ -90,21 +68,41 @@ def ls(ifc, conn, contract_address, declarator_address, subject_address, w=sys.s
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
c = Declarator(
|
c = Declarator(chain_spec)
|
||||||
settings.get('CHAIN_SPEC')
|
|
||||||
)
|
|
||||||
|
|
||||||
ls(
|
contract_address = to_checksum_address(config.get('_EXEC_ADDRESS'))
|
||||||
c,
|
if not config.true('_UNSAFE') and contract_address != add_0x(config.get('_EXEC_ADDRESS')):
|
||||||
settings.get('CONN'),
|
raise ValueError('invalid checksum address for contract')
|
||||||
settings.get('EXEC'),
|
|
||||||
config.get('_DECLARATOR'),
|
|
||||||
settings.get('RECIPIENT'),
|
declarator_address = to_checksum_address(config.get('_DECLARATOR_ADDRESS'))
|
||||||
sender_address=settings.get('SENDER_ADDRESS'),
|
if not config.true('_UNSAFE') and declarator_address != add_0x(config.get('_DECLARATOR_ADDRESS')):
|
||||||
)
|
raise ValueError('invalid checksum address for declarator')
|
||||||
|
|
||||||
|
subject_address = to_checksum_address(config.get('_ADDRESS'))
|
||||||
|
if not config.true('_UNSAFE') and subject_address != add_0x(config.get('_ADDRESS')):
|
||||||
|
raise ValueError('invalid checksum address for subject')
|
||||||
|
|
||||||
|
ls(c, conn, contract_address, declarator_address, subject_address)
|
||||||
|
|
||||||
declarations = []
|
declarations = []
|
||||||
|
|
||||||
|
# for d in declarations:
|
||||||
|
# if not args.resolve:
|
||||||
|
# print(d.hex())
|
||||||
|
# continue
|
||||||
|
# if args.resolve_http:
|
||||||
|
# try:
|
||||||
|
# r = try_sha256(d)
|
||||||
|
# print(r)
|
||||||
|
# continue
|
||||||
|
# except urllib.error.HTTPError:
|
||||||
|
# pass
|
||||||
|
# try:
|
||||||
|
# print(try_utf8(d))
|
||||||
|
# except UnicodeDecodeError:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
confini~=0.6.0
|
confini>=0.3.6rc3,<0.5.0
|
||||||
chainlib-eth~=0.4.16
|
chainlib-eth>=0.0.10a5,<=0.1.0
|
||||||
chainlib==0.4.12
|
eth_erc20>=0.1.2a3,<=0.2.0
|
||||||
|
funga>=0.5.1a1,<0.6.0
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
default_pythonpath=$PYTHONPATH:.
|
|
||||||
export PYTHONPATH=${default_pythonpath:-.}
|
|
||||||
for f in `ls tests/*.py`; do
|
for f in `ls tests/*.py`; do
|
||||||
python $f
|
python $f
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = eth-address-index
|
name = eth-address-index
|
||||||
version = 0.6.2
|
version = 0.2.5a1
|
||||||
description = Signed metadata declarations for ethereum addresses
|
description = Signed metadata declarations for ethereum addresses
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
@@ -28,6 +28,11 @@ packages =
|
|||||||
eth_address_declarator.runnable
|
eth_address_declarator.runnable
|
||||||
eth_address_declarator.unittest
|
eth_address_declarator.unittest
|
||||||
|
|
||||||
|
[options.extras_require]
|
||||||
|
testing =
|
||||||
|
eth-tester==0.5.0b2
|
||||||
|
py-evm==0.3.0a20
|
||||||
|
|
||||||
[options.package_data]
|
[options.package_data]
|
||||||
* =
|
* =
|
||||||
data/AddressDeclarator.json
|
data/AddressDeclarator.json
|
||||||
@@ -36,6 +41,5 @@ packages =
|
|||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
eth-address-declarator-publish = eth_address_declarator.runnable.publish:main
|
eth-address-declarator-deploy = eth_address_declarator.runnable.deploy:main
|
||||||
eth-address-declarator-add = eth_address_declarator.runnable.add:main
|
eth-address-declarator-add = eth_address_declarator.runnable.add:main
|
||||||
eth-address-declarator-view = eth_address_declarator.runnable.view:main
|
|
||||||
|
|||||||
@@ -22,7 +22,4 @@ f.close()
|
|||||||
setup(
|
setup(
|
||||||
install_requires=requirements,
|
install_requires=requirements,
|
||||||
tests_require=test_requirements,
|
tests_require=test_requirements,
|
||||||
extras_require={
|
|
||||||
'dev': test_requirements,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
eth-tester==0.5.0b3
|
eth-tester==0.5.0b3
|
||||||
py-evm==0.3.0a20
|
py-evm==0.3.0a20
|
||||||
eth-accounts-index~=0.3.4
|
eth-accounts-index>=0.1.2a3,<0.2.0
|
||||||
eth_erc20~=0.5.0
|
|
||||||
|
|||||||
@@ -183,56 +183,5 @@ class TestAddressDeclarator(TestAddressDeclaratorBase):
|
|||||||
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.accounts[2]))
|
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.accounts[2]))
|
||||||
|
|
||||||
|
|
||||||
def test_three_first(self):
|
|
||||||
d = []
|
|
||||||
for i in range(3):
|
|
||||||
d.append(add_0x(os.urandom(32).hex()))
|
|
||||||
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
|
||||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
||||||
|
|
||||||
for proof in d:
|
|
||||||
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[0], self.foo_token_address, proof)
|
|
||||||
self.rpc.do(o)
|
|
||||||
|
|
||||||
o = c.declarator_count(self.address, self.foo_token_address, sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(c.parse_declarator_count(r), 1)
|
|
||||||
|
|
||||||
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
proofs = c.parse_declaration(r)
|
|
||||||
self.assertEqual(len(proofs), 3)
|
|
||||||
|
|
||||||
for i in range(3):
|
|
||||||
self.assertEqual(proofs[i], strip_0x(d[i]))
|
|
||||||
|
|
||||||
|
|
||||||
def test_three_first_different(self):
|
|
||||||
d = []
|
|
||||||
a = []
|
|
||||||
for i in range(3):
|
|
||||||
d.append(add_0x(os.urandom(32).hex()))
|
|
||||||
a.append(add_0x(os.urandom(20).hex()))
|
|
||||||
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
|
||||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
|
||||||
|
|
||||||
for i in range(3):
|
|
||||||
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[0], a[i], d[i])
|
|
||||||
self.rpc.do(o)
|
|
||||||
|
|
||||||
for i in range(3):
|
|
||||||
o = c.declarator_count(self.address, a[i], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
self.assertEqual(c.parse_declarator_count(r), 1)
|
|
||||||
|
|
||||||
o = c.declaration(self.address, self.accounts[0], a[i], sender_address=self.accounts[0])
|
|
||||||
r = self.rpc.do(o)
|
|
||||||
proofs = c.parse_declaration(r)
|
|
||||||
self.assertEqual(len(proofs), 1)
|
|
||||||
self.assertEqual(proofs[0], strip_0x(d[i]))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
|||||||
[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"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":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
|
[{"inputs":[{"internalType":"bytes32","name":"_initialDescription","type":"bytes32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_declarator","type":"address"},{"indexed":false,"internalType":"address","name":"_subject","type":"address"},{"indexed":false,"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"DeclarationAdded","type":"event"},{"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":[{"internalType":"address","name":"_declarator","type":"address"},{"internalType":"address","name":"_subject","type":"address"},{"internalType":"bytes32","name":"_proof","type":"bytes32"}],"name":"haveDeclaration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
|
||||||
|
|||||||
@@ -8,32 +8,32 @@ contract AddressDeclarator {
|
|||||||
mapping( bytes32 => uint256 ) declarationContentIndex; // the _latest_ content pointer for the declarator to subject mapping
|
mapping( bytes32 => uint256 ) declarationContentIndex; // the _latest_ content pointer for the declarator to subject mapping
|
||||||
mapping( address => address[] ) declarator;
|
mapping( address => address[] ) declarator;
|
||||||
mapping( address => address[] ) declaratorReverse;
|
mapping( address => address[] ) declaratorReverse;
|
||||||
|
mapping( bytes32 => bool ) declarationExistIndex;
|
||||||
bytes32[][] public contents;
|
bytes32[][] public contents;
|
||||||
|
|
||||||
event DeclarationAdded(address _declarator, address _subject, bytes32 _proof);
|
event DeclarationAdded(address _declarator, address _subject, bytes32 _proof);
|
||||||
|
|
||||||
constructor(bytes32 _initialDescription) {
|
constructor(bytes32 _initialDescription) public {
|
||||||
bytes32[] memory foundation;
|
bytes32[] memory foundation;
|
||||||
|
|
||||||
contents.push(foundation);
|
contents.push(foundation);
|
||||||
contents[contents.length-1].push(blockhash(block.number));
|
contents[contents.length-1].push(blockhash(block.number));
|
||||||
|
|
||||||
addDeclaration(msg.sender, _initialDescription);
|
addDeclaration(msg.sender, _initialDescription);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) {
|
function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) {
|
||||||
bytes32 k;
|
bytes32 k;
|
||||||
bytes memory addrMaterial = new bytes(40);
|
bytes memory signMaterial = new bytes(40);
|
||||||
bytes memory addrBytes = abi.encodePacked(_declarator);
|
bytes memory addrBytes = abi.encodePacked(_declarator);
|
||||||
for (uint256 i = 0; i < 20; i++) {
|
for (uint256 i = 0; i < 20; i++) {
|
||||||
addrMaterial[i] = addrBytes[i];
|
signMaterial[i] = addrBytes[i];
|
||||||
}
|
}
|
||||||
addrBytes = abi.encodePacked(_subject);
|
addrBytes = abi.encodePacked(_subject);
|
||||||
for (uint256 i = 0; i < 20; i++) {
|
for (uint256 i = 0; i < 20; i++) {
|
||||||
addrMaterial[i+20] = addrBytes[i];
|
signMaterial[i+20] = addrBytes[i];
|
||||||
}
|
}
|
||||||
k = sha256(addrMaterial);
|
k = sha256(signMaterial);
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,12 +77,14 @@ contract AddressDeclarator {
|
|||||||
declarator[_subject].push(tx.origin);
|
declarator[_subject].push(tx.origin);
|
||||||
contents.push(declarationContents);
|
contents.push(declarationContents);
|
||||||
declarationIndex[tx.origin].push(_subject);
|
declarationIndex[tx.origin].push(_subject);
|
||||||
idx = contents.length-1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idx = contents.length-1;
|
||||||
declarationContentIndex[ks[0]] = idx;
|
declarationContentIndex[ks[0]] = idx;
|
||||||
contents[idx].push(_proof);
|
contents[idx].push(_proof);
|
||||||
|
|
||||||
|
declarationExistIndex[ks[1]] = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +97,15 @@ contract AddressDeclarator {
|
|||||||
return contents[idx];
|
return contents[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Declarator
|
||||||
|
function haveDeclaration(address _declarator, address _subject, bytes32 _proof) public view returns (bool) {
|
||||||
|
bytes32[2] memory ks;
|
||||||
|
|
||||||
|
ks = toReference(_declarator, _subject, _proof);
|
||||||
|
|
||||||
|
return declarationExistIndex[ks[1]];
|
||||||
|
}
|
||||||
|
|
||||||
// Implements Declarator
|
// Implements Declarator
|
||||||
function declarationCount(address _declarator) public view returns ( uint256 ) {
|
function declarationCount(address _declarator) public view returns ( uint256 ) {
|
||||||
return declarationIndex[_declarator].length;
|
return declarationIndex[_declarator].length;
|
||||||
|
|||||||
Reference in New Issue
Block a user