commit 6ad28661732f2c4e48252ddb847925b2852b8e19
parent 22544ceb232b60b74f9dc6c10ac4a2a3b75e6b01
Author: nolash <dev@holbrook.no>
Date: Sat, 14 Nov 2020 00:09:43 +0100
Add javascript interface
Diffstat:
4 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/js/src/registry.ts b/js/src/registry.ts
@@ -0,0 +1,39 @@
+class AccountRegistry {
+
+ contract: any
+
+ constructor(w3:any, abi:object, address:string) {
+ this.contract = new w3.eth.Contract(abi, address);
+ }
+
+
+ public async count(): Promise<number> {
+ return this.contract.methods.count().call();
+ }
+
+
+ public async have(address:string): Promise<boolean> {
+ return await this.contract.methods.accountsIndex(address).call() != 0;
+ }
+
+
+ public async last(n:number): Promise<Array<string>> {
+ const c = await this.count();
+ let lo = c - n - 1;
+ if (lo < 0) {
+ lo = 0;
+ }
+ let accounts = [];
+ for (let i = c - 1; i > lo; i--) {
+ console.log('i', i);
+ console.log('foo', i, await this.contract.methods.accounts(i).call());
+ const a = await this.contract.methods.accounts(i).call();
+ accounts.push(a);
+ }
+ return accounts;
+ }
+}
+
+export {
+ AccountRegistry,
+}
diff --git a/python/eth_accounts_index/registry.py b/python/eth_accounts_index/registry.py
@@ -4,7 +4,7 @@ import os
logg = logging.getLogger()
-class Registry:
+class AccountRegistry:
abi = None
diff --git a/python/setup.cfg b/python/setup.cfg
@@ -1,5 +1,5 @@
[metadata]
-name = accounts-index
+name = eth-accounts-index
version = 0.0.1
description = Accounts index evm contract tooling with permissioned writes
author = Louis Holbrook
diff --git a/python/tests/test_app.py b/python/tests/test_app.py
@@ -5,7 +5,7 @@ import json
import web3
import eth_tester
-from eth_accounts_index import Registry
+from eth_accounts_index import AccountRegistry
testdir = os.path.dirname(__file__)
@@ -45,18 +45,18 @@ class Test(unittest.TestCase):
def test_basic(self):
- registry = Registry(self.w3, self.address)
+ registry = AccountRegistry(self.w3, self.address)
self.assertEqual(registry.count(), 1); # count starts at 1, first addess is always 0x0
def test_access(self):
- registry = Registry(self.w3, self.address, self.w3.eth.accounts[1])
+ registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[1])
registry.add(self.w3.eth.accounts[2])
self.eth_tester.mine_block()
self.assertEqual(registry.count(), 2)
# account 0 does not have access
- registry = Registry(self.w3, self.address, self.w3.eth.accounts[2])
+ registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[2])
registry.add(self.w3.eth.accounts[2])
self.eth_tester.mine_block()
self.assertEqual(registry.count(), 2)
@@ -75,7 +75,7 @@ class Test(unittest.TestCase):
def test_indices(self):
- registry = Registry(self.w3, self.address, self.w3.eth.accounts[1])
+ registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[1])
registry.add(self.w3.eth.accounts[2])
self.assertTrue(registry.have(self.w3.eth.accounts[2]))
@@ -83,7 +83,7 @@ class Test(unittest.TestCase):
def test_list(self):
- registry = Registry(self.w3, self.address, self.w3.eth.accounts[1])
+ registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[1])
for i in range(2, 10):
registry.add(self.w3.eth.accounts[i])