mirror of
git://holbrook.no/eth-accounts-index
synced 2024-12-22 12:27:31 +01:00
Initial commit
This commit is contained in:
commit
9336d813ed
1
registry.abi.json
Normal file
1
registry.abi.json
Normal file
@ -0,0 +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":"AccountAdded","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"accounts","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accountsIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[],"stateMutability":"nonpayable","type":"function"}]
|
1
registry.bin
Normal file
1
registry.bin
Normal file
@ -0,0 +1 @@
|
||||
608060405234801561001057600080fd5b5033600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061054f806100616000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806306661abd146100675780630a3b0a4f146100855780634c2ebc6b146100c95780635ae06f7e14610121578063da2824a814610165578063f2a40db8146101a9575b600080fd5b61006f610201565b6040518082815260200191505060405180910390f35b6100c76004803603602081101561009b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610207565b005b61010b600480360360208110156100df57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610364565b6040518082815260200191505060405180910390f35b6101636004803603602081101561013757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061037c565b005b6101a76004803603602081101561017b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610428565b005b6101d5600480360360208110156101bf57600080fd5b81019080803590602001909291905050506104dd565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661025d57600080fd5b6000819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600254600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506002600081548092919060010191905055506001600254038173ffffffffffffffffffffffffffffffffffffffff167f5ed3bdd47b9af629827a8d129aa39c870b10c03f0153fe9ddb8e84b665061acd60405160405180910390a350565b60016020528060005260406000206000915090505481565b3373ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146103d657600080fd5b600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81549060ff021916905550565b3373ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461048257600080fd5b6001600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600081815481106104ea57fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea2646970667358221220d0c43ebb44ba788ac3723dd1aa1293f073f92c8f6e68a8dd975553f67976555264736f6c63430007030033
|
36
registry.sol
Normal file
36
registry.sol
Normal file
@ -0,0 +1,36 @@
|
||||
pragma solidity ^0.7.3;
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
contract CustodialAccountIndex {
|
||||
|
||||
address[] public accounts;
|
||||
mapping(address => uint256) public accountsIndex;
|
||||
uint256 public count;
|
||||
mapping(address => bool) writers;
|
||||
address owner;
|
||||
|
||||
event AccountAdded(address indexed addedAccount, uint256 indexed accountIndex);
|
||||
|
||||
constructor() {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
function addWriter(address _writer) public {
|
||||
require(owner == msg.sender);
|
||||
writers[_writer] = true;
|
||||
}
|
||||
|
||||
function deleteWriter(address _writer) public {
|
||||
require(owner == msg.sender);
|
||||
delete writers[_writer];
|
||||
}
|
||||
|
||||
function add(address _account) public {
|
||||
require(writers[msg.sender]);
|
||||
accounts.push(_account);
|
||||
accountsIndex[_account] = count;
|
||||
count++;
|
||||
emit AccountAdded(_account, count-1);
|
||||
}
|
||||
}
|
42
test.py
Normal file
42
test.py
Normal file
@ -0,0 +1,42 @@
|
||||
import web3
|
||||
import eth_tester
|
||||
import json
|
||||
|
||||
|
||||
eth_params = eth_tester.backends.pyevm.main.get_default_genesis_params({
|
||||
'gas_limit': 9000000,
|
||||
})
|
||||
backend = eth_tester.PyEVMBackend(eth_params)
|
||||
instance = eth_tester.EthereumTester(backend)
|
||||
provider = web3.Web3.EthereumTesterProvider(instance)
|
||||
w3 = web3.Web3(provider)
|
||||
|
||||
|
||||
f = open('registry.bin', 'r')
|
||||
bytecode = f.read()
|
||||
f.close()
|
||||
|
||||
f = open('registry.abi.json', 'r')
|
||||
abi = json.load(f)
|
||||
f.close()
|
||||
|
||||
c = w3.eth.contract(abi=abi, bytecode=bytecode)
|
||||
tx_hash = c.constructor().transact({'from': w3.eth.accounts[0]})
|
||||
|
||||
r = w3.eth.getTransactionReceipt(tx_hash)
|
||||
|
||||
c = w3.eth.contract(abi=abi, address=r.contractAddress)
|
||||
fail = False
|
||||
try:
|
||||
c.functions.add(w3.eth.accounts[2]).transact({'from': w3.eth.accounts[1]})
|
||||
except:
|
||||
fail = True
|
||||
assert fail
|
||||
|
||||
c.functions.addWriter(w3.eth.accounts[1]).transact({'from': w3.eth.accounts[0]})
|
||||
c.functions.add(w3.eth.accounts[2]).transact({'from': w3.eth.accounts[1]})
|
||||
c.functions.add(w3.eth.accounts[3]).transact({'from': w3.eth.accounts[1]})
|
||||
|
||||
assert c.functions.count().call() == 2
|
||||
assert c.functions.accountsIndex(w3.eth.accounts[3]).call() == 1
|
||||
assert c.functions.accounts(1).call() == w3.eth.accounts[3]
|
Loading…
Reference in New Issue
Block a user