mirror of
git://holbrook.no/eth-accounts-index
synced 2024-11-25 18:26:45 +01:00
- Updates data from compiled solc.
This commit is contained in:
parent
ca05d2b2c7
commit
7913bf42f2
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"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":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"isRemoved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"remove","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
@ -7,20 +7,20 @@ import os
|
|||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
TxFactory,
|
TxFactory,
|
||||||
TxFormat,
|
TxFormat,
|
||||||
)
|
)
|
||||||
from chainlib.eth.contract import (
|
from chainlib.eth.contract import (
|
||||||
ABIContractEncoder,
|
ABIContractEncoder,
|
||||||
ABIContractDecoder,
|
ABIContractDecoder,
|
||||||
ABIContractType,
|
ABIContractType,
|
||||||
abi_decode_single,
|
abi_decode_single,
|
||||||
)
|
)
|
||||||
from chainlib.eth.constant import ZERO_ADDRESS
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
from chainlib.jsonrpc import JSONRPCRequest
|
from chainlib.jsonrpc import JSONRPCRequest
|
||||||
from chainlib.eth.error import RequestMismatchException
|
from chainlib.eth.error import RequestMismatchException
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
)
|
)
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
@ -38,10 +38,11 @@ class AccountsIndex(TxFactory):
|
|||||||
tx = self.finalize(tx, tx_format)
|
tx = self.finalize(tx, tx_format)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
||||||
def add(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def add(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
return self.__single_address_method('add', contract_address, sender_address, address, tx_format)
|
return self.__single_address_method('add', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
|
def remove(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
|
return self.__single_address_method('remove', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
def have(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
def have(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
@ -57,7 +58,6 @@ class AccountsIndex(TxFactory):
|
|||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
@ -70,11 +70,9 @@ class AccountsIndex(TxFactory):
|
|||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
def count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
return self.entry_count(contract_address, sender_address=sender_address, id_generator=id_generator)
|
return self.entry_count(contract_address, sender_address=sender_address, id_generator=id_generator)
|
||||||
|
|
||||||
|
|
||||||
def entry(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
def entry(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
@ -89,22 +87,18 @@ class AccountsIndex(TxFactory):
|
|||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_account(self, v):
|
def parse_account(self, v):
|
||||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
return abi_decode_single(ABIContractType.ADDRESS, v)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_entry_count(self, v):
|
def parse_entry_count(self, v):
|
||||||
return abi_decode_single(ABIContractType.UINT256, v)
|
return abi_decode_single(ABIContractType.UINT256, v)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_have(self, v):
|
def parse_have(self, v):
|
||||||
return abi_decode_single(ABIContractType.BOOLEAN, v)
|
return abi_decode_single(ABIContractType.BOOLEAN, v)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_add_request(self, v):
|
def parse_add_request(self, v):
|
||||||
v = strip_0x(v)
|
v = strip_0x(v)
|
||||||
@ -121,6 +115,6 @@ class AccountsIndex(TxFactory):
|
|||||||
|
|
||||||
dec = ABIContractDecoder()
|
dec = ABIContractDecoder()
|
||||||
dec.typ(ABIContractType.ADDRESS)
|
dec.typ(ABIContractType.ADDRESS)
|
||||||
dec.val(v[cursor:cursor+64])
|
dec.val(v[cursor:cursor + 64])
|
||||||
r = dec.decode()
|
r = dec.decode()
|
||||||
return r
|
return r
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
import pathlib
|
||||||
# external imports
|
# external imports
|
||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
TxFormat,
|
TxFormat,
|
||||||
)
|
)
|
||||||
from chainlib.eth.contract import (
|
from chainlib.eth.contract import (
|
||||||
ABIContractEncoder,
|
ABIContractEncoder,
|
||||||
ABIContractType,
|
ABIContractType,
|
||||||
)
|
)
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from .interface import AccountsIndex
|
from .interface import AccountsIndex
|
||||||
@ -18,40 +20,34 @@ datadir = os.path.join(moddir, 'data')
|
|||||||
|
|
||||||
|
|
||||||
class AccountRegistry(AccountsIndex):
|
class AccountRegistry(AccountsIndex):
|
||||||
|
|
||||||
__abi = None
|
__abi = None
|
||||||
__bytecode = None
|
__bytecode = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def abi():
|
def abi():
|
||||||
if AccountRegistry.__abi == None:
|
if AccountRegistry.__abi is None:
|
||||||
f = open(os.path.join(datadir, 'AccountsIndex.json'), 'r')
|
with open(os.path.join(datadir, 'AccountsIndex.json'), 'r') as f:
|
||||||
AccountRegistry.__abi = json.load(f)
|
AccountRegistry.__abi = json.load(f)
|
||||||
f.close()
|
|
||||||
return AccountRegistry.__abi
|
return AccountRegistry.__abi
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def bytecode():
|
def bytecode():
|
||||||
if AccountRegistry.__bytecode == None:
|
if AccountRegistry.__bytecode is None:
|
||||||
f = open(os.path.join(datadir, 'AccountsIndex.bin'))
|
AccountRegistry.__bytecode = pathlib.Path(
|
||||||
AccountRegistry.__bytecode = f.read()
|
os.path.join(datadir, 'AccountsIndex.bin')
|
||||||
f.close()
|
).read_text()
|
||||||
return AccountRegistry.__bytecode
|
return AccountRegistry.__bytecode
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def gas(code=None):
|
def gas(code=None):
|
||||||
return 1200000
|
return 1200000
|
||||||
|
|
||||||
|
|
||||||
def constructor(self, sender_address):
|
def constructor(self, sender_address):
|
||||||
code = AccountRegistry.bytecode()
|
code = AccountRegistry.bytecode()
|
||||||
tx = self.template(sender_address, None, use_nonce=True)
|
tx = self.template(sender_address, None, use_nonce=True)
|
||||||
tx = self.set_code(tx, code)
|
tx = self.set_code(tx, code)
|
||||||
return self.build(tx)
|
return self.build(tx)
|
||||||
|
|
||||||
|
|
||||||
def __single_address_method(self, method, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def __single_address_method(self, method, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
enc = ABIContractEncoder()
|
enc = ABIContractEncoder()
|
||||||
enc.method(method)
|
enc.method(method)
|
||||||
@ -63,10 +59,8 @@ class AccountRegistry(AccountsIndex):
|
|||||||
tx = self.finalize(tx, tx_format)
|
tx = self.finalize(tx, tx_format)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
||||||
def add_writer(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def add_writer(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
return self.__single_address_method('addWriter', contract_address, sender_address, address, tx_format)
|
return self.__single_address_method('addWriter', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
|
|
||||||
def delete_writer(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def delete_writer(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
return self.__single_address_method('deleteWriter', contract_address, sender_address, address, tx_format)
|
return self.__single_address_method('deleteWriter', contract_address, sender_address, address, tx_format)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = eth-accounts-index
|
name = eth-accounts-index
|
||||||
version = 0.3.0
|
version = 0.3.1
|
||||||
description = Accounts index evm contract tooling with permissioned writes
|
description = Accounts index evm contract tooling with permissioned writes
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
@ -50,7 +50,7 @@ class Test(EthTesterCase):
|
|||||||
(tx_hash, o) = c.constructor(self.accounts[0])
|
(tx_hash, o) = c.constructor(self.accounts[0])
|
||||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||||
r = self.conn.do(o)
|
r = self.conn.do(o)
|
||||||
logg.debug('deployed with hash {}'.format(r))
|
logg.debug(f'deployed with hash {r}')
|
||||||
|
|
||||||
o = receipt(r)
|
o = receipt(r)
|
||||||
r = self.conn.do(o)
|
r = self.conn.do(o)
|
||||||
@ -133,6 +133,37 @@ class Test(EthTesterCase):
|
|||||||
|
|
||||||
#self.assertFalse(registry.have(self.w3.eth.accounts[3]))
|
#self.assertFalse(registry.have(self.w3.eth.accounts[3]))
|
||||||
|
|
||||||
|
def test_5_remove(self):
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||||
|
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
|
b = os.urandom(20)
|
||||||
|
a = to_checksum_address(b.hex())
|
||||||
|
(tx_hash, o) = c.add(self.address, self.accounts[0], a)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
|
||||||
|
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
count = c.parse_entry_count(r)
|
||||||
|
self.assertEqual(count, 1)
|
||||||
|
|
||||||
|
b = os.urandom(20)
|
||||||
|
a = to_checksum_address(b.hex())
|
||||||
|
(tx_hash, o) = c.add(self.address, self.accounts[0], a)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
|
||||||
|
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
count = c.parse_entry_count(r)
|
||||||
|
self.assertEqual(count, 2)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.remove(self.address, self.accounts[0], a)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
|
||||||
|
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
count = c.parse_entry_count(r)
|
||||||
|
self.assertEqual(count, 1)
|
||||||
|
|
||||||
|
|
||||||
# TODO: reinstate all tests
|
# TODO: reinstate all tests
|
||||||
|
@ -5,7 +5,7 @@ pragma solidity >0.6.11;
|
|||||||
|
|
||||||
contract CustodialAccountIndex {
|
contract CustodialAccountIndex {
|
||||||
|
|
||||||
address[] entries;
|
uint256 public entryCount;
|
||||||
mapping(address => uint256) entryIndex;
|
mapping(address => uint256) entryIndex;
|
||||||
mapping(address => bool) writers;
|
mapping(address => bool) writers;
|
||||||
address public owner;
|
address public owner;
|
||||||
@ -16,8 +16,6 @@ contract CustodialAccountIndex {
|
|||||||
|
|
||||||
constructor() public {
|
constructor() public {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
entries.push(address(0));
|
|
||||||
count = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addWriter(address _writer) public returns (bool) {
|
function addWriter(address _writer) public returns (bool) {
|
||||||
@ -36,9 +34,18 @@ contract CustodialAccountIndex {
|
|||||||
function add(address _account) external returns (bool) {
|
function add(address _account) external returns (bool) {
|
||||||
require(writers[msg.sender]);
|
require(writers[msg.sender]);
|
||||||
require(entryIndex[_account] == 0);
|
require(entryIndex[_account] == 0);
|
||||||
entryIndex[_account] = entries.length;
|
entryIndex[_account] = block.timestamp;
|
||||||
entries.push(_account);
|
entryCount = entryCount + 1;
|
||||||
emit AddressAdded(_account, entries.length-1);
|
emit AddressAdded(_account, block.timestamp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements AccountsIndex
|
||||||
|
function remove(address _account) external returns (bool) {
|
||||||
|
require(writers[msg.sender]);
|
||||||
|
require(entryIndex[_account] > 0);
|
||||||
|
entryIndex[_account] = 0;
|
||||||
|
entryCount = entryCount - 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,16 +54,6 @@ contract CustodialAccountIndex {
|
|||||||
return entryIndex[_account] > 0;
|
return entryIndex[_account] > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements AccountsIndex
|
|
||||||
function entry(uint256 _idx) public returns (address) {
|
|
||||||
return entries[_idx+1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements AccountsIndex
|
|
||||||
function entryCount() public returns (uint256) {
|
|
||||||
return entries.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements EIP173
|
// Implements EIP173
|
||||||
function transferOwnership(address _newOwner) public returns (bool) {
|
function transferOwnership(address _newOwner) public returns (bool) {
|
||||||
require(msg.sender == owner);
|
require(msg.sender == owner);
|
||||||
@ -93,4 +90,11 @@ contract CustodialAccountIndex {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isRemoved(address _account) external view returns (bool){
|
||||||
|
if (entryIndex[_account] == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,6 @@ all:
|
|||||||
$(SOLC) --abi AccountsIndex.sol --evm-version byzantium | awk 'NR>3' > AccountsIndex.json
|
$(SOLC) --abi AccountsIndex.sol --evm-version byzantium | awk 'NR>3' > AccountsIndex.json
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
cp -v *{json,bin} ../python/eth_accounts_index/data/
|
cp -v *"json" ../python/eth_accounts_index/data/
|
||||||
|
cp -v *"bin" ../python/eth_accounts_index/data/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user