mirror of
git://holbrook.no/eth-accounts-index
synced 2024-11-21 16:46:46 +01:00
Add time added
This commit is contained in:
parent
a30614efed
commit
9a8fb62113
@ -1,6 +1,8 @@
|
|||||||
* 0.3.3
|
* 0.3.3
|
||||||
- Rename cli script from deploy to publish
|
- Rename cli script from deploy to publish
|
||||||
- Refactor cli scripts to use current chainlib setup
|
- Refactor cli scripts to use current chainlib setup
|
||||||
|
- Add time added entry
|
||||||
|
- Add activate and deactivate option
|
||||||
* 0.3.2
|
* 0.3.2
|
||||||
- Add remove option
|
- Add remove option
|
||||||
* 0.3.0
|
* 0.3.0
|
||||||
|
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":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressActive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":true,"internalType":"uint256","name":"_accountIndex","type":"uint256"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressInactive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressRemoved","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":[{"internalType":"address","name":"_account","type":"address"}],"name":"activate","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":"_account","type":"address"}],"name":"deactivate","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":"","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"entryIndex","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":"isActive","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":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressActive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressInactive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressRemoved","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":[{"internalType":"address","name":"_account","type":"address"}],"name":"activate","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":"_account","type":"address"}],"name":"deactivate","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":"_i","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":"","type":"address"}],"name":"entryIndex","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":"isActive","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":"_account","type":"address"}],"name":"time","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
@ -41,12 +41,32 @@ class AccountsIndex(TxFactory):
|
|||||||
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 activate(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def activate(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
return self.__single_address_method('activate', contract_address, sender_address, address, tx_format)
|
return self.__single_address_method('activate', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
def deactivate(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def deactivate(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
return self.__single_address_method('deactivate', contract_address, sender_address, address, tx_format)
|
return self.__single_address_method('deactivate', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
|
|
||||||
|
def time(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
|
j = JSONRPCRequest(id_generator)
|
||||||
|
o = j.template()
|
||||||
|
o['method'] = 'eth_call'
|
||||||
|
enc = ABIContractEncoder()
|
||||||
|
enc.method('time')
|
||||||
|
enc.typ(ABIContractType.ADDRESS)
|
||||||
|
enc.address(address)
|
||||||
|
data = add_0x(enc.get())
|
||||||
|
tx = self.template(sender_address, contract_address)
|
||||||
|
tx = self.set_code(tx, data)
|
||||||
|
o['params'].append(self.normalize(tx))
|
||||||
|
return o
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
@ -90,7 +110,7 @@ class AccountsIndex(TxFactory):
|
|||||||
|
|
||||||
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()
|
||||||
|
@ -4,7 +4,7 @@ version = 0.3.3
|
|||||||
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
|
||||||
url = https://gitlab.com/cicnet/eth-accounts-index
|
url = https://holbrook.no/src/eth-accounts-index
|
||||||
keywords =
|
keywords =
|
||||||
ethereum
|
ethereum
|
||||||
classifiers =
|
classifiers =
|
||||||
|
@ -20,13 +20,6 @@ f.close()
|
|||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
package_data={
|
|
||||||
'': [
|
|
||||||
'data/*.abi.json',
|
|
||||||
'data/*.bin',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
include_package_data=True,
|
|
||||||
install_requires=requirements,
|
install_requires=requirements,
|
||||||
tests_require=test_requirements,
|
tests_require=test_requirements,
|
||||||
)
|
)
|
||||||
|
@ -18,6 +18,10 @@ from chainlib.eth.contract import (
|
|||||||
abi_decode_single,
|
abi_decode_single,
|
||||||
ABIContractType,
|
ABIContractType,
|
||||||
)
|
)
|
||||||
|
from chainlib.eth.block import (
|
||||||
|
block_latest,
|
||||||
|
block_by_number,
|
||||||
|
)
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from eth_accounts_index.registry import AccountRegistry
|
from eth_accounts_index.registry import AccountRegistry
|
||||||
@ -186,5 +190,77 @@ class Test(EthTesterCase):
|
|||||||
self.assertEqual(int(r, 16), 1)
|
self.assertEqual(int(r, 16), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_6_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)
|
||||||
|
self.assertEqual(int(r, 16), 1)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.remove(self.address, self.accounts[0], a)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
o = receipt(r)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(int(r, 16), 0)
|
||||||
|
|
||||||
|
addrs = []
|
||||||
|
for i in range(8):
|
||||||
|
b = os.urandom(20)
|
||||||
|
addrs.append(to_checksum_address(b.hex()))
|
||||||
|
(tx_hash, o) = c.add(self.address, self.accounts[0], addrs[i])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(int(r, 16), 8)
|
||||||
|
|
||||||
|
(tx_hash, o) = c.remove(self.address, self.accounts[0], addrs[4])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
o = receipt(r)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
|
r = []
|
||||||
|
for i in range(7):
|
||||||
|
o = c.entry(self.address, i, sender_address=self.accounts[0])
|
||||||
|
r.append(self.conn.do(o))
|
||||||
|
|
||||||
|
self.assertEqual(len(r), 7)
|
||||||
|
self.assertNotIn(addrs[4], r)
|
||||||
|
|
||||||
|
|
||||||
|
def test_7_time(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)
|
||||||
|
self.conn.do(o)
|
||||||
|
|
||||||
|
o = block_latest()
|
||||||
|
r = self.conn.do(o)
|
||||||
|
o = block_by_number(r)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
t = r['timestamp']
|
||||||
|
|
||||||
|
o = c.time(self.address, a, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(t, int(r, 16))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -5,14 +5,14 @@ pragma solidity >0.6.12;
|
|||||||
|
|
||||||
contract CustodialAccountIndex {
|
contract CustodialAccountIndex {
|
||||||
|
|
||||||
uint256 constant blockedField = 1 << 64;
|
uint256 constant blockedField = 1 << 128;
|
||||||
address[] public entry;
|
address[] entryList;
|
||||||
mapping(address => uint256) public entryIndex;
|
mapping(address => uint256) public entryIndex;
|
||||||
mapping(address => bool) writers;
|
mapping(address => bool) writers;
|
||||||
address public owner;
|
address public owner;
|
||||||
address newOwner;
|
address newOwner;
|
||||||
|
|
||||||
event AddressAdded(address indexed _executor, uint256 indexed _accountIndex, address _account); // AccountsIndex
|
event AddressAdded(address indexed _executor, address _account); // AccountsIndex
|
||||||
event AddressActive(address indexed _executor, address _account);
|
event AddressActive(address indexed _executor, address _account);
|
||||||
event AddressInactive(address indexed _executor, address _account);
|
event AddressInactive(address indexed _executor, address _account);
|
||||||
event AddressRemoved(address indexed _executor, address _account);
|
event AddressRemoved(address indexed _executor, address _account);
|
||||||
@ -20,10 +20,11 @@ contract CustodialAccountIndex {
|
|||||||
|
|
||||||
constructor() public {
|
constructor() public {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
|
entryList.push(address(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
function entryCount() external returns (uint256) {
|
function entryCount() external returns (uint256) {
|
||||||
return entry.length;
|
return entryList.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addWriter(address _writer) public returns (bool) {
|
function addWriter(address _writer) public returns (bool) {
|
||||||
@ -41,25 +42,38 @@ contract CustodialAccountIndex {
|
|||||||
// Implements AccountsIndex
|
// Implements AccountsIndex
|
||||||
function add(address _account) external returns (bool) {
|
function add(address _account) external returns (bool) {
|
||||||
uint256 i;
|
uint256 i;
|
||||||
|
uint256 _entry;
|
||||||
|
|
||||||
require(writers[msg.sender]);
|
require(writers[msg.sender]);
|
||||||
require(entryIndex[_account] == 0);
|
require(entryIndex[_account] == 0);
|
||||||
require(entry.length < (1 << 128));
|
require(entryList.length < (1 << 64));
|
||||||
i = entry.length;
|
i = entryList.length;
|
||||||
entry.push(_account);
|
entryList.push(_account);
|
||||||
entryIndex[_account] = i;
|
_entry = uint64(i);
|
||||||
emit AddressAdded(msg.sender, i, _account);
|
_entry |= block.timestamp << 64;
|
||||||
|
entryIndex[_account] = _entry;
|
||||||
|
emit AddressAdded(msg.sender, _account);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements AccountsIndex
|
// Implements AccountsIndex
|
||||||
// Deactivate account, without removing the entry. The entry will still be part of the entry count.
|
function remove(address _account) external returns (bool) {
|
||||||
function deactivate(address _account) external returns (bool) {
|
uint256 i;
|
||||||
|
uint256 l;
|
||||||
|
|
||||||
require(writers[msg.sender]);
|
require(writers[msg.sender]);
|
||||||
require(entryIndex[_account] > 0 && entryIndex[_account] & blockedField == 0);
|
require(this.have(_account));
|
||||||
entryIndex[_account] <<= 65;
|
|
||||||
entryIndex[_account] |= blockedField;
|
l = entryList.length - 1;
|
||||||
emit AddressInactive(msg.sender, _account);
|
|
||||||
|
i = entryIndex[_account];
|
||||||
|
if (i < l) {
|
||||||
|
entryList[i] = entryList[l];
|
||||||
|
}
|
||||||
|
entryList.pop();
|
||||||
|
entryIndex[_account] = 0;
|
||||||
|
emit AddressRemoved(msg.sender, _account);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements AccountsIndex
|
// Implements AccountsIndex
|
||||||
@ -67,10 +81,33 @@ contract CustodialAccountIndex {
|
|||||||
function activate(address _account) external returns (bool) {
|
function activate(address _account) external returns (bool) {
|
||||||
require(writers[msg.sender]);
|
require(writers[msg.sender]);
|
||||||
require(entryIndex[_account] > 0 && entryIndex[_account] & blockedField == blockedField);
|
require(entryIndex[_account] > 0 && entryIndex[_account] & blockedField == blockedField);
|
||||||
entryIndex[_account] >>= 65;
|
entryIndex[_account] >>= 129;
|
||||||
emit AddressActive(msg.sender, _account);
|
emit AddressActive(msg.sender, _account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements AccountsIndex
|
||||||
|
// Deactivate account, without removing the entry. The entry will still be part of the entry count.
|
||||||
|
function deactivate(address _account) external returns (bool) {
|
||||||
|
require(writers[msg.sender]);
|
||||||
|
require(entryIndex[_account] > 0 && entryIndex[_account] & blockedField == 0);
|
||||||
|
entryIndex[_account] <<= 129;
|
||||||
|
entryIndex[_account] |= blockedField;
|
||||||
|
emit AddressInactive(msg.sender, _account);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements AccountsIndex
|
||||||
|
function entry(uint256 _i) external returns (address) {
|
||||||
|
return entryList[_i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements AccountsIndex
|
||||||
|
function time(address _account) external returns (uint256) {
|
||||||
|
require(entryIndex[_account] > 0);
|
||||||
|
return entryIndex[_account] >> 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implements AccountsIndex
|
// Implements AccountsIndex
|
||||||
function have(address _account) external view returns (bool) {
|
function have(address _account) external view returns (bool) {
|
||||||
return entryIndex[_account] > 0;
|
return entryIndex[_account] > 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user