mirror of
git://holbrook.no/eth-accounts-index
synced 2024-12-22 04:17:32 +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"}]
|
||||
|
@ -5,22 +5,22 @@ import os
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.tx import (
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
)
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractDecoder,
|
||||
ABIContractType,
|
||||
abi_decode_single,
|
||||
)
|
||||
ABIContractEncoder,
|
||||
ABIContractDecoder,
|
||||
ABIContractType,
|
||||
abi_decode_single,
|
||||
)
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.eth.error import RequestMismatchException
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
@ -35,13 +35,14 @@ class AccountsIndex(TxFactory):
|
||||
data = enc.get()
|
||||
tx = self.template(sender_address, contract_address, use_nonce=True)
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
@ -57,8 +58,7 @@ class AccountsIndex(TxFactory):
|
||||
o['params'].append(self.normalize(tx))
|
||||
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)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
@ -70,11 +70,9 @@ class AccountsIndex(TxFactory):
|
||||
o['params'].append(self.normalize(tx))
|
||||
return o
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def entry(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
@ -89,22 +87,18 @@ class AccountsIndex(TxFactory):
|
||||
o['params'].append(self.normalize(tx))
|
||||
return o
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_account(self, v):
|
||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_entry_count(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_have(self, v):
|
||||
return abi_decode_single(ABIContractType.BOOLEAN, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_add_request(self, v):
|
||||
v = strip_0x(v)
|
||||
@ -121,6 +115,6 @@ class AccountsIndex(TxFactory):
|
||||
|
||||
dec = ABIContractDecoder()
|
||||
dec.typ(ABIContractType.ADDRESS)
|
||||
dec.val(v[cursor:cursor+64])
|
||||
dec.val(v[cursor:cursor + 64])
|
||||
r = dec.decode()
|
||||
return r
|
||||
return r
|
||||
|
@ -1,14 +1,16 @@
|
||||
# standard imports
|
||||
import os
|
||||
import json
|
||||
|
||||
import pathlib
|
||||
# external imports
|
||||
from chainlib.eth.tx import (
|
||||
TxFormat,
|
||||
)
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
)
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from .interface import AccountsIndex
|
||||
@ -18,40 +20,34 @@ datadir = os.path.join(moddir, 'data')
|
||||
|
||||
|
||||
class AccountRegistry(AccountsIndex):
|
||||
|
||||
__abi = None
|
||||
__bytecode = None
|
||||
|
||||
@staticmethod
|
||||
def abi():
|
||||
if AccountRegistry.__abi == None:
|
||||
f = open(os.path.join(datadir, 'AccountsIndex.json'), 'r')
|
||||
AccountRegistry.__abi = json.load(f)
|
||||
f.close()
|
||||
if AccountRegistry.__abi is None:
|
||||
with open(os.path.join(datadir, 'AccountsIndex.json'), 'r') as f:
|
||||
AccountRegistry.__abi = json.load(f)
|
||||
return AccountRegistry.__abi
|
||||
|
||||
|
||||
@staticmethod
|
||||
def bytecode():
|
||||
if AccountRegistry.__bytecode == None:
|
||||
f = open(os.path.join(datadir, 'AccountsIndex.bin'))
|
||||
AccountRegistry.__bytecode = f.read()
|
||||
f.close()
|
||||
if AccountRegistry.__bytecode is None:
|
||||
AccountRegistry.__bytecode = pathlib.Path(
|
||||
os.path.join(datadir, 'AccountsIndex.bin')
|
||||
).read_text()
|
||||
return AccountRegistry.__bytecode
|
||||
|
||||
|
||||
@staticmethod
|
||||
def gas(code=None):
|
||||
return 1200000
|
||||
|
||||
|
||||
def constructor(self, sender_address):
|
||||
code = AccountRegistry.bytecode()
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
tx = self.set_code(tx, code)
|
||||
return self.build(tx)
|
||||
|
||||
|
||||
def __single_address_method(self, method, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||
enc = ABIContractEncoder()
|
||||
enc.method(method)
|
||||
@ -60,13 +56,11 @@ class AccountRegistry(AccountsIndex):
|
||||
data = enc.get()
|
||||
tx = self.template(sender_address, contract_address, use_nonce=True)
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = eth-accounts-index
|
||||
version = 0.3.0
|
||||
version = 0.3.1
|
||||
description = Accounts index evm contract tooling with permissioned writes
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -50,8 +50,8 @@ class Test(EthTesterCase):
|
||||
(tx_hash, o) = c.constructor(self.accounts[0])
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
r = self.conn.do(o)
|
||||
logg.debug('deployed with hash {}'.format(r))
|
||||
|
||||
logg.debug(f'deployed with hash {r}')
|
||||
|
||||
o = receipt(r)
|
||||
r = self.conn.do(o)
|
||||
self.address = to_checksum_address(r['contract_address'])
|
||||
@ -133,6 +133,37 @@ class Test(EthTesterCase):
|
||||
|
||||
#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
|
||||
|
@ -5,7 +5,7 @@ pragma solidity >0.6.11;
|
||||
|
||||
contract CustodialAccountIndex {
|
||||
|
||||
address[] entries;
|
||||
uint256 public entryCount;
|
||||
mapping(address => uint256) entryIndex;
|
||||
mapping(address => bool) writers;
|
||||
address public owner;
|
||||
@ -16,8 +16,6 @@ contract CustodialAccountIndex {
|
||||
|
||||
constructor() public {
|
||||
owner = msg.sender;
|
||||
entries.push(address(0));
|
||||
count = 1;
|
||||
}
|
||||
|
||||
function addWriter(address _writer) public returns (bool) {
|
||||
@ -36,9 +34,18 @@ contract CustodialAccountIndex {
|
||||
function add(address _account) external returns (bool) {
|
||||
require(writers[msg.sender]);
|
||||
require(entryIndex[_account] == 0);
|
||||
entryIndex[_account] = entries.length;
|
||||
entries.push(_account);
|
||||
emit AddressAdded(_account, entries.length-1);
|
||||
entryIndex[_account] = block.timestamp;
|
||||
entryCount = entryCount + 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;
|
||||
}
|
||||
|
||||
@ -47,16 +54,6 @@ contract CustodialAccountIndex {
|
||||
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
|
||||
function transferOwnership(address _newOwner) public returns (bool) {
|
||||
require(msg.sender == owner);
|
||||
@ -93,4 +90,11 @@ contract CustodialAccountIndex {
|
||||
}
|
||||
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
|
||||
|
||||
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