Compare commits
15 Commits
lash/custo
...
master
Author | SHA1 | Date | |
---|---|---|---|
6ac1dc88d2 | |||
a3a3f55234 | |||
6e637ce04e | |||
0db8e56603 | |||
1dba2d09d1 | |||
618aa7716e | |||
17ae29887f | |||
fbb5168b40 | |||
c269318528 | |||
c3e8883f15 | |||
5f62287913 | |||
28d7699a4a | |||
05224a9dd6 | |||
2f65aa37ff | |||
|
be7dea24ac |
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@ __pycache__
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
build/
|
build/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
.venv
|
||||||
|
.clicada
|
||||||
|
dist/
|
||||||
|
.vscode/
|
@ -1,3 +1,5 @@
|
|||||||
|
- 0.0.7
|
||||||
|
* fix: make store_path relative to the users home
|
||||||
- 0.0.6
|
- 0.0.6
|
||||||
* Add cache encryption, with AES-CTR-128
|
* Add cache encryption, with AES-CTR-128
|
||||||
- 0.0.5
|
- 0.0.5
|
||||||
|
87
README.md
Normal file
87
README.md
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
## Clicada
|
||||||
|
|
||||||
|
> Admin Command Line Interface to interact with cic-meta and cic-cache
|
||||||
|
|
||||||
|
### Pre-requisites
|
||||||
|
|
||||||
|
- Public key uploaded to `cic-auth-helper`
|
||||||
|
- PGP Keyring for your key
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
Use either of the following installation methods:
|
||||||
|
|
||||||
|
1. Install from git release (recommended)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget https://git.grassecon.net/grassrootseconomics/clicada/archive/v0.0.6.zip
|
||||||
|
unzip clicada-v0.0.6.zip
|
||||||
|
cd clicada
|
||||||
|
python3 -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
pip install -r requirements.txt --extra-index-url=https://pip.grassrootseconomics.net
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Install from pip to path (non sudo)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install -UI --extra-index-url=https://pip.grassrootseconomics.net clicada
|
||||||
|
```
|
||||||
|
|
||||||
|
### GPG Keyring setup
|
||||||
|
|
||||||
|
PGP uses the default keyring, you can however pass in a custom keyring path.
|
||||||
|
|
||||||
|
To create a keyring from a specific key and get its path for `AUTH_KEYRING_PATH`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# In some dir
|
||||||
|
gpg --homedir .gnupg --import private.pgp
|
||||||
|
pwd
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
usage: clicada [...optional arguments] [...positional arguments]
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
{user,u,tag,t}
|
||||||
|
user (u) retrieve transactions for a user
|
||||||
|
tag (t) locally assign a display value to an identifier
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--no-logs Turn off all logging
|
||||||
|
-v Be verbose
|
||||||
|
-vv Be very verbose
|
||||||
|
-c CONFIG, --config CONFIG
|
||||||
|
Configuration directory
|
||||||
|
-n NAMESPACE, --namespace NAMESPACE
|
||||||
|
Configuration namespace
|
||||||
|
--dumpconfig {env,ini}
|
||||||
|
Output configuration and quit. Use with --raw to omit values and output schema only.
|
||||||
|
--env-prefix ENV_PREFIX
|
||||||
|
environment prefix for variables to overwrite configuration
|
||||||
|
-p P, --rpc-provider P
|
||||||
|
RPC HTTP(S) provider url
|
||||||
|
--rpc-dialect RPC_DIALECT
|
||||||
|
RPC HTTP(S) backend dialect
|
||||||
|
--height HEIGHT Block height to execute against
|
||||||
|
-i I, --chain-spec I Chain specification string
|
||||||
|
-u, --unsafe Do not verify address checksums
|
||||||
|
--seq Use sequential rpc ids
|
||||||
|
-y Y, --key-file Y Keystore file to use for signing or address
|
||||||
|
--raw Do not decode output
|
||||||
|
--fee-price FEE_PRICE
|
||||||
|
override fee price
|
||||||
|
--fee-limit FEE_LIMIT
|
||||||
|
override fee limit
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```bash
|
||||||
|
AUTH_PASSPHRASE=queenmarlena AUTH_KEYRING_PATH=/home/kamikaze/grassroots/usumbufu/tests/testdata/pgp/.gnupg/ AUTH_KEY=CCE2E1D2D0E36ADE0405E2D0995BB21816313BD5 CHAIN_SPEC=evm:byzantium:8996:bloxberg CIC_REGISTRY_ADDRESS=0xcf60ebc445b636a5ab787f9e8bc465a2a3ef8299 RPC_PROVIDER=https://rpc.grassecon.net TX_CACHE_URL=https://cache.grassecon.net HTTP_CORS_ORIGIN=https://auth.grassecon.net META_HTTP_ORIGIN=https://auth.grassecon.net:443 PYTHONPATH=. python clicada/runnable/view.py u --meta-url https://auth.grassecon.net +254711000000
|
||||||
|
```
|
@ -1,46 +1,43 @@
|
|||||||
# import notifier
|
# import notifier
|
||||||
from clicada.cli.notify import NotifyWriter
|
from clicada.cli.notify import NotifyWriter
|
||||||
|
|
||||||
notifier = NotifyWriter()
|
notifier = NotifyWriter()
|
||||||
#notifier.notify('loading script')
|
# notifier.notify('loading script')
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
import logging
|
||||||
|
|
||||||
# standard imports
|
# standard imports
|
||||||
import os
|
import os
|
||||||
import logging
|
|
||||||
import importlib
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# external imports
|
|
||||||
import confini
|
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
from chainlib.chain import ChainSpec
|
import clicada.cli.tag as cmd_tag
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
import clicada.cli.user as cmd_user
|
import clicada.cli.user as cmd_user
|
||||||
import clicada.cli.tag as cmd_tag
|
|
||||||
|
# external imports
|
||||||
|
import confini
|
||||||
|
from chainlib.chain import ChainSpec
|
||||||
from clicada.cli.auth import PGPAuthCrypt
|
from clicada.cli.auth import PGPAuthCrypt
|
||||||
from clicada.cli.http import (
|
from clicada.cli.http import HTTPSession, PGPClientSession
|
||||||
HTTPSession,
|
|
||||||
PGPClientSession,
|
|
||||||
)
|
|
||||||
from clicada.crypt.aes import AESCTREncrypt
|
from clicada.crypt.aes import AESCTREncrypt
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
data_dir = os.path.join(script_dir, '..', 'data')
|
data_dir = os.path.join(script_dir, "..", "data")
|
||||||
base_config_dir = os.path.join(data_dir, 'config')
|
base_config_dir = os.path.join(data_dir, "config")
|
||||||
|
|
||||||
|
|
||||||
class NullWriter:
|
class NullWriter:
|
||||||
|
|
||||||
def notify(self, v):
|
def notify(self, v):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def ouch(self, v):
|
def ouch(self, v):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def write(self, v):
|
def write(self, v):
|
||||||
sys.stdout.write(str(v))
|
sys.stdout.write(str(v))
|
||||||
|
|
||||||
@ -48,12 +45,12 @@ class NullWriter:
|
|||||||
class CmdCtrl:
|
class CmdCtrl:
|
||||||
|
|
||||||
__cmd_alias = {
|
__cmd_alias = {
|
||||||
'u': 'user',
|
"u": "user",
|
||||||
't': 'tag',
|
"t": "tag",
|
||||||
}
|
}
|
||||||
|
|
||||||
__auth_for = [
|
__auth_for = [
|
||||||
'user',
|
"user",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, argv=None, description=None, logger=None, *args, **kwargs):
|
def __init__(self, argv=None, description=None, logger=None, *args, **kwargs):
|
||||||
@ -72,40 +69,36 @@ class CmdCtrl:
|
|||||||
self.blockchain()
|
self.blockchain()
|
||||||
|
|
||||||
self.remote_openers = {}
|
self.remote_openers = {}
|
||||||
if self.get('META_URL') != None:
|
if self.get("META_URL") != None:
|
||||||
sctx = None
|
|
||||||
if self.cmd_args.cafile != None:
|
|
||||||
import ssl
|
|
||||||
sctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
||||||
sctx.load_verify_locations(self.cmd_args.cafile)
|
|
||||||
|
|
||||||
auth_client_session = PGPClientSession(self.__auth)
|
auth_client_session = PGPClientSession(self.__auth)
|
||||||
self.remote_openers['meta'] = HTTPSession(
|
self.remote_openers["meta"] = HTTPSession(
|
||||||
self.get('META_URL'),
|
self.get("META_URL"),
|
||||||
auth=auth_client_session,
|
auth=auth_client_session,
|
||||||
origin=self.config.get('META_HTTP_ORIGIN'),
|
origin=self.config.get("META_HTTP_ORIGIN"),
|
||||||
ssl_context=sctx,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def blockchain(self):
|
def blockchain(self):
|
||||||
self.chain_spec = ChainSpec.from_chain_str(self.config.get('CHAIN_SPEC'))
|
self.chain_spec = ChainSpec.from_chain_str(self.config.get("CHAIN_SPEC"))
|
||||||
self.rpc = chainlib.eth.cli.Rpc()
|
self.rpc = chainlib.eth.cli.Rpc()
|
||||||
self.__conn = self.rpc.connect_by_config(self.config)
|
self.__conn = self.rpc.connect_by_config(self.config)
|
||||||
|
|
||||||
|
|
||||||
def args(self, argv):
|
def args(self, argv):
|
||||||
self.argparser = chainlib.eth.cli.ArgumentParser(chainlib.eth.cli.argflag_std_read)
|
self.argparser = chainlib.eth.cli.ArgumentParser(
|
||||||
|
chainlib.eth.cli.argflag_std_read
|
||||||
|
)
|
||||||
sub = self.argparser.add_subparsers()
|
sub = self.argparser.add_subparsers()
|
||||||
sub.dest = 'command'
|
sub.dest = "command"
|
||||||
sub_user = sub.add_parser('user', aliases=['u'], help='retrieve transactions for a user')
|
sub_user = sub.add_parser(
|
||||||
|
"user", aliases=["u"], help="retrieve transactions for a user"
|
||||||
|
)
|
||||||
cmd_user.process_args(sub_user)
|
cmd_user.process_args(sub_user)
|
||||||
sub_tag = sub.add_parser('tag', aliases=['t'], help='locally assign a display value to an identifier')
|
sub_tag = sub.add_parser(
|
||||||
|
"tag", aliases=["t"], help="locally assign a display value to an identifier"
|
||||||
|
)
|
||||||
cmd_tag.process_args(sub_tag)
|
cmd_tag.process_args(sub_tag)
|
||||||
|
|
||||||
self.cmd_args = self.argparser.parse_args(argv)
|
self.cmd_args = self.argparser.parse_args(argv)
|
||||||
|
|
||||||
|
|
||||||
def module(self):
|
def module(self):
|
||||||
self.cmd_string = self.cmd_args.command
|
self.cmd_string = self.cmd_args.command
|
||||||
cmd_string_translate = self.__cmd_alias.get(self.cmd_string)
|
cmd_string_translate = self.__cmd_alias.get(self.cmd_string)
|
||||||
@ -113,13 +106,12 @@ class CmdCtrl:
|
|||||||
self.cmd_string = cmd_string_translate
|
self.cmd_string = cmd_string_translate
|
||||||
|
|
||||||
if self.cmd_string == None:
|
if self.cmd_string == None:
|
||||||
self.cmd_string = 'none'
|
self.cmd_string = "none"
|
||||||
|
|
||||||
modname = 'clicada.cli.{}'.format(self.cmd_string)
|
modname = "clicada.cli.{}".format(self.cmd_string)
|
||||||
self.logger.debug('using module {}'.format(modname))
|
self.logger.debug("using module {}".format(modname))
|
||||||
self.cmd_mod = importlib.import_module(modname)
|
self.cmd_mod = importlib.import_module(modname)
|
||||||
|
|
||||||
|
|
||||||
def logging(self, logger):
|
def logging(self, logger):
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
if self.logger == None:
|
if self.logger == None:
|
||||||
@ -129,69 +121,74 @@ class CmdCtrl:
|
|||||||
elif self.cmd_args.v:
|
elif self.cmd_args.v:
|
||||||
self.logger.setLevel(logging.INFO)
|
self.logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def config(self):
|
def config(self):
|
||||||
override_dir = self.cmd_args.config
|
override_dir = self.cmd_args.config
|
||||||
if override_dir == None:
|
if override_dir == None:
|
||||||
p = os.environ.get('HOME')
|
p = os.environ.get("HOME")
|
||||||
if p != None:
|
if p != None:
|
||||||
p = os.path.join(p, '.config', 'cic', 'clicada')
|
p = os.path.join(p, ".config", "cic", "clicada")
|
||||||
try:
|
try:
|
||||||
os.stat(p)
|
os.stat(p)
|
||||||
override_dir = p
|
override_dir = p
|
||||||
logg.info('applying user config override from standard location: {}'.format(p))
|
logg.info(
|
||||||
|
"applying user config override from standard location: {}".format(
|
||||||
|
p
|
||||||
|
)
|
||||||
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
extra_args = self.cmd_mod.extra_args()
|
extra_args = self.cmd_mod.extra_args()
|
||||||
self.config = chainlib.eth.cli.Config.from_args(self.cmd_args, base_config_dir=base_config_dir, extra_args=extra_args, default_config_dir=override_dir)
|
self.config = chainlib.eth.cli.Config.from_args(
|
||||||
|
self.cmd_args,
|
||||||
|
base_config_dir=base_config_dir,
|
||||||
|
extra_args=extra_args,
|
||||||
|
default_config_dir=override_dir,
|
||||||
|
)
|
||||||
|
|
||||||
self.config.add(False, '_SEQ')
|
self.config.add(False, "_SEQ")
|
||||||
|
|
||||||
self.config.censor('AUTH_PASSPHRASE')
|
self.config.censor("AUTH_PASSPHRASE")
|
||||||
|
|
||||||
self.logger.debug('loaded config:\n{}'.format(self.config))
|
|
||||||
|
|
||||||
|
self.logger.debug("loaded config:\n{}".format(self.config))
|
||||||
|
|
||||||
def auth(self):
|
def auth(self):
|
||||||
typ = self.get('AUTH_TYPE')
|
typ = self.get("AUTH_TYPE")
|
||||||
if typ != 'gnupg':
|
if typ != "gnupg":
|
||||||
raise NotImplementedError('Valid aut implementations are: gnupg')
|
raise NotImplementedError("Valid aut implementations are: gnupg")
|
||||||
default_auth_db_path = None
|
default_auth_db_path = None
|
||||||
if os.environ.get('HOME') != None:
|
if os.environ.get("HOME") != None:
|
||||||
default_auth_db_path = os.path.join(os.environ['HOME'], '.local/share/cic/clicada')
|
default_auth_db_path = os.path.join(
|
||||||
auth_db_path = self.get('AUTH_DB_PATH', default_auth_db_path)
|
os.environ["HOME"], ".local/share/cic/clicada"
|
||||||
self.__auth = PGPAuthCrypt(auth_db_path, self.get('AUTH_KEY'), self.get('AUTH_KEYRING_PATH'))
|
)
|
||||||
self.__auth.get_secret(self.get('AUTH_PASSPHRASE'))
|
auth_db_path = self.get("AUTH_DB_PATH", default_auth_db_path)
|
||||||
|
self.__auth = PGPAuthCrypt(
|
||||||
|
auth_db_path, self.get("AUTH_KEY"), self.get("AUTH_KEYRING_PATH")
|
||||||
|
)
|
||||||
|
self.__auth.get_secret(self.get("AUTH_PASSPHRASE"))
|
||||||
self.encrypter = AESCTREncrypt(auth_db_path, self.__auth.secret)
|
self.encrypter = AESCTREncrypt(auth_db_path, self.__auth.secret)
|
||||||
|
|
||||||
|
|
||||||
def get(self, k, default=None):
|
def get(self, k, default=None):
|
||||||
r = self.config.get(k, default)
|
r = self.config.get(k, default)
|
||||||
if k in [
|
if k in [
|
||||||
'_FORCE',
|
"_FORCE",
|
||||||
]:
|
]:
|
||||||
if r == None:
|
if r == None:
|
||||||
return False
|
return False
|
||||||
return self.config.true(k)
|
return self.config.true(k)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def chain(self):
|
def chain(self):
|
||||||
return self.chain_spec
|
return self.chain_spec
|
||||||
|
|
||||||
|
|
||||||
def conn(self):
|
def conn(self):
|
||||||
return self.__conn
|
return self.__conn
|
||||||
|
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
self.cmd_mod.execute(self)
|
self.cmd_mod.execute(self)
|
||||||
|
|
||||||
|
|
||||||
def opener(self, k):
|
def opener(self, k):
|
||||||
return self.remote_openers[k]
|
return self.remote_openers[k]
|
||||||
|
|
||||||
|
|
||||||
def notifier(self):
|
def notifier(self):
|
||||||
if logg.root.level >= logging.WARNING:
|
if logg.root.level >= logging.WARNING:
|
||||||
logging.disable()
|
logging.disable()
|
||||||
@ -199,18 +196,12 @@ class CmdCtrl:
|
|||||||
else:
|
else:
|
||||||
self.writer = NullWriter()
|
self.writer = NullWriter()
|
||||||
|
|
||||||
|
|
||||||
def notify(self, v):
|
def notify(self, v):
|
||||||
self.writer.notify(v)
|
if logg.root.level <= logging.INFO:
|
||||||
|
print("\033[96m" + v + "\033[0m")
|
||||||
|
|
||||||
def ouch(self, v):
|
def ouch(self, v):
|
||||||
self.writer.ouch(v)
|
print("\033[91m" + v + "\033[0m")
|
||||||
print()
|
|
||||||
|
|
||||||
|
|
||||||
def write(self, v):
|
def write(self, v):
|
||||||
self.writer.write("")
|
print(v)
|
||||||
self.writer.write(v)
|
|
||||||
print()
|
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ from usumbufu.client.base import (
|
|||||||
)
|
)
|
||||||
from usumbufu.client.bearer import BearerClientSession
|
from usumbufu.client.bearer import BearerClientSession
|
||||||
from usumbufu.client.hoba import HobaClientSession
|
from usumbufu.client.hoba import HobaClientSession
|
||||||
from urlybird.host import url_apply_port_string
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -22,7 +21,6 @@ class PGPClientSession(HobaClientSession):
|
|||||||
alg = '969'
|
alg = '969'
|
||||||
|
|
||||||
def __init__(self, auth):
|
def __init__(self, auth):
|
||||||
super(PGPClientSession, self).__init__()
|
|
||||||
self.auth = auth
|
self.auth = auth
|
||||||
self.origin = None
|
self.origin = None
|
||||||
self.fingerprint = self.auth.fingerprint()
|
self.fingerprint = self.auth.fingerprint()
|
||||||
@ -48,12 +46,23 @@ class HTTPSession:
|
|||||||
|
|
||||||
token_dir = '/run/user/{}/clicada/usumbufu/.token'.format(os.getuid())
|
token_dir = '/run/user/{}/clicada/usumbufu/.token'.format(os.getuid())
|
||||||
|
|
||||||
def __init__(self, url, auth=None, origin=None, ssl_context=None):
|
def __init__(self, url, auth=None, origin=None):
|
||||||
self.base_url = url
|
self.base_url = url
|
||||||
|
url_parts = urllib.parse.urlsplit(self.base_url)
|
||||||
|
url_parts_origin_host = url_parts[1].split(":")
|
||||||
|
host = url_parts_origin_host[0]
|
||||||
|
try:
|
||||||
|
host = host + ':' + url_parts_origin_host[1]
|
||||||
|
except IndexError:
|
||||||
|
host = host + ':' + str(getservbyname(url_parts[0]))
|
||||||
|
logg.info('changed origin with missing port number from {} to {}'.format(url_parts[1], host))
|
||||||
|
url_parts_origin = (url_parts[0], host, '', '', '',)
|
||||||
|
|
||||||
if origin == None:
|
|
||||||
origin = url_apply_port_string(url, as_origin=True)
|
|
||||||
self.origin = origin
|
self.origin = origin
|
||||||
|
if self.origin == None:
|
||||||
|
self.origin = urllib.parse.urlunsplit(url_parts_origin)
|
||||||
|
else:
|
||||||
|
logg.debug('overriding http origin for {} with {}'.format(url, self.origin))
|
||||||
|
|
||||||
h = hashlib.sha256()
|
h = hashlib.sha256()
|
||||||
h.update(self.base_url.encode('utf-8'))
|
h.update(self.base_url.encode('utf-8'))
|
||||||
@ -63,7 +72,7 @@ class HTTPSession:
|
|||||||
os.makedirs(token_store_dir, exist_ok=True)
|
os.makedirs(token_store_dir, exist_ok=True)
|
||||||
self.token_store = BaseTokenStore(path=token_store_dir)
|
self.token_store = BaseTokenStore(path=token_store_dir)
|
||||||
|
|
||||||
self.session = ClientSession(self.origin, token_store=self.token_store, ssl_context=ssl_context)
|
self.session = ClientSession(self.origin, token_store=self.token_store)
|
||||||
|
|
||||||
bearer_handler = BearerClientSession(self.origin, token_store=self.token_store)
|
bearer_handler = BearerClientSession(self.origin, token_store=self.token_store)
|
||||||
self.session.add_subhandler(bearer_handler)
|
self.session.add_subhandler(bearer_handler)
|
||||||
@ -79,9 +88,6 @@ class HTTPSession:
|
|||||||
url = urllib.parse.urljoin(self.base_url, endpoint)
|
url = urllib.parse.urljoin(self.base_url, endpoint)
|
||||||
logg.debug('open {} with opener {}'.format(url, self))
|
logg.debug('open {} with opener {}'.format(url, self))
|
||||||
r = self.opener.open(url)
|
r = self.opener.open(url)
|
||||||
logg.debug('response code {} for {}'.format(r.code, endpoint))
|
|
||||||
if r.code == 404:
|
|
||||||
raise FileNotFoundError()
|
|
||||||
return r.read().decode('utf-8')
|
return r.read().decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@ import json
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from clicada.user import FileUserStore
|
from clicada.user import FileUserStore
|
||||||
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
categories = [
|
categories = [
|
||||||
'phone',
|
'phone',
|
||||||
@ -35,7 +36,7 @@ def validate(config, args):
|
|||||||
|
|
||||||
|
|
||||||
def execute(ctrl):
|
def execute(ctrl):
|
||||||
store_path = '.clicada'
|
store_path = os.path.join(str(Path.home()), '.clicada')
|
||||||
user_store = FileUserStore(None, ctrl.chain(), ctrl.get('_CATEGORY'), store_path, int(ctrl.get('FILESTORE_TTL')))
|
user_store = FileUserStore(None, ctrl.chain(), ctrl.get('_CATEGORY'), store_path, int(ctrl.get('FILESTORE_TTL')))
|
||||||
user_store.put(ctrl.get('_IDENTIFIER'), json.dumps(ctrl.get('_TAG')), force=True)
|
user_store.put(ctrl.get('_IDENTIFIER'), json.dumps(ctrl.get('_TAG')), force=True)
|
||||||
user_store.stick(ctrl.get('_IDENTIFIER'))
|
user_store.stick(ctrl.get('_IDENTIFIER'))
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import sys
|
|
||||||
import logging
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from chainlib.encode import TxHexNormalizer
|
||||||
|
from chainlib.eth.address import is_address, to_checksum_address
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from cic_eth_registry import CICRegistry
|
from cic_eth_registry import CICRegistry
|
||||||
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
|
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
|
||||||
from cic_types.models.person import Person
|
from cic_types.models.person import Person
|
||||||
from chainlib.eth.address import to_checksum_address
|
from clicada.error import MetadataNotFoundError
|
||||||
from chainlib.encode import TxHexNormalizer
|
from clicada.token import FileTokenStore, token_balance
|
||||||
from hexathon import add_0x
|
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from clicada.tx import TxGetter
|
from clicada.tx import ResolvedTokenTx, TxGetter
|
||||||
from clicada.user import FileUserStore
|
from clicada.user import FileUserStore
|
||||||
from clicada.token import (
|
from hexathon import add_0x
|
||||||
FileTokenStore,
|
|
||||||
token_balance,
|
|
||||||
)
|
|
||||||
from clicada.tx import ResolvedTokenTx
|
|
||||||
from clicada.error import MetadataNotFoundError
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -27,25 +26,36 @@ tx_normalizer = TxHexNormalizer()
|
|||||||
|
|
||||||
|
|
||||||
def process_args(argparser):
|
def process_args(argparser):
|
||||||
argparser.add_argument('-m', '--method', type=str, help='lookup method')
|
argparser.add_argument("-m", "--method", type=str, help="lookup method")
|
||||||
argparser.add_argument('--meta-url', dest='meta_url', type=str, help='Url to retrieve metadata from')
|
argparser.add_argument(
|
||||||
argparser.add_argument('--cafile', type=str, help='CA certificate chain file to use for verifying SSL session')
|
"--meta-url", dest="meta_url", type=str, help="Url to retrieve metadata from"
|
||||||
argparser.add_argument('-f', '--force-update', dest='force_update', action='store_true', help='Update records of mutable entries')
|
)
|
||||||
argparser.add_argument('identifier', type=str, help='user identifier')
|
argparser.add_argument(
|
||||||
|
"-f",
|
||||||
|
"--force-update",
|
||||||
|
dest="force_update",
|
||||||
|
action="store_true",
|
||||||
|
help="Update records of mutable entries",
|
||||||
|
)
|
||||||
|
argparser.add_argument(
|
||||||
|
"identifier", type=str, help="user identifier (phone_number or address)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def extra_args():
|
def extra_args():
|
||||||
return {
|
return {
|
||||||
'force_update': '_FORCE',
|
"force_update": "_FORCE",
|
||||||
'method': 'META_LOOKUP_METHOD',
|
"method": "META_LOOKUP_METHOD",
|
||||||
'meta_url': 'META_URL',
|
"meta_url": "META_URL",
|
||||||
'identifier': '_IDENTIFIER',
|
"identifier": "_IDENTIFIER",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def apply_args(config, args):
|
def apply_args(config, args):
|
||||||
if config.get('META_LOOKUP_METHOD'):
|
if config.get("META_LOOKUP_METHOD"):
|
||||||
raise NotImplementedError('Sorry, currently only "phone" lookup method is implemented')
|
raise NotImplementedError(
|
||||||
|
'Sorry, currently only "phone" lookup method is implemented'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate(config, args):
|
def validate(config, args):
|
||||||
@ -53,79 +63,101 @@ def validate(config, args):
|
|||||||
|
|
||||||
|
|
||||||
def execute(ctrl):
|
def execute(ctrl):
|
||||||
tx_getter = TxGetter(ctrl.get('TX_CACHE_URL'), 10)
|
tx_getter = TxGetter(ctrl.get("TX_CACHE_URL"), 10)
|
||||||
|
|
||||||
store_path = '.clicada'
|
store_path = os.path.join(str(Path.home()), ".clicada")
|
||||||
user_phone_file_label = 'phone'
|
user_phone_file_label = "phone"
|
||||||
user_phone_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_phone_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
|
user_phone_store = FileUserStore(
|
||||||
|
ctrl.opener("meta"),
|
||||||
|
ctrl.chain(),
|
||||||
|
user_phone_file_label,
|
||||||
|
store_path,
|
||||||
|
int(ctrl.get("FILESTORE_TTL")),
|
||||||
|
encrypter=ctrl.encrypter,
|
||||||
|
)
|
||||||
|
|
||||||
ctrl.notify('resolving identifier {} to wallet address'.format(ctrl.get('_IDENTIFIER')))
|
identifier = ctrl.get("_IDENTIFIER")
|
||||||
user_address = user_phone_store.by_phone(ctrl.get('_IDENTIFIER'), update=ctrl.get('_FORCE'))
|
ctrl.notify("resolving identifier {} to wallet address".format(identifier))
|
||||||
|
if is_address(identifier):
|
||||||
|
user_address = identifier
|
||||||
|
else:
|
||||||
|
user_address = user_phone_store.by_phone(identifier, update=ctrl.get("_FORCE"))
|
||||||
if user_address == None:
|
if user_address == None:
|
||||||
ctrl.ouch('unknown identifier: {}\n'.format(ctrl.get('_IDENTIFIER')))
|
ctrl.ouch("unknown identifier: {}\n".format(identifier))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
user_address = to_checksum_address(user_address)
|
user_address = to_checksum_address(user_address)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
ctrl.ouch('invalid response "{}" for {}\n'.format(user_address, ctrl.get('_IDENTIFIER')))
|
ctrl.ouch('invalid response "{}" for {}\n'.format(user_address, identifier))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logg.debug('loaded user address {} for {}'.format(user_address, ctrl.get('_IDENTIFIER')))
|
logg.debug("loaded user address {} for {}".format(user_address, identifier))
|
||||||
|
|
||||||
user_address_normal = tx_normalizer.wallet_address(user_address)
|
user_address_normal = tx_normalizer.wallet_address(user_address)
|
||||||
ctrl.notify('retrieving txs for address {}'.format(user_address_normal))
|
ctrl.notify("retrieving txs for address {}".format(user_address_normal))
|
||||||
txs = tx_getter.get(user_address)
|
txs = tx_getter.get(user_address)
|
||||||
|
|
||||||
token_store = FileTokenStore(ctrl.chain(), ctrl.conn(), 'token', store_path)
|
token_store = FileTokenStore(ctrl.chain(), ctrl.conn(), "token", store_path)
|
||||||
|
|
||||||
user_address_file_label = 'address'
|
user_address_file_label = "address"
|
||||||
user_address_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
|
user_address_store = FileUserStore(
|
||||||
|
ctrl.opener("meta"),
|
||||||
ctrl.notify('resolving metadata for address {}'.format(user_address_normal))
|
ctrl.chain(),
|
||||||
try:
|
user_address_file_label,
|
||||||
r = user_address_store.by_address(user_address_normal, update=ctrl.get('_FORCE'))
|
store_path,
|
||||||
except MetadataNotFoundError as e:
|
int(ctrl.get("FILESTORE_TTL")),
|
||||||
ctrl.ouch('could not resolve metadata for user: {}'.format(e))
|
encrypter=ctrl.encrypter,
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
ctrl.write("""Phone: {}
|
|
||||||
Network address: {}
|
|
||||||
Chain: {}
|
|
||||||
Name: {}
|
|
||||||
Registered: {}
|
|
||||||
Gender: {}
|
|
||||||
Location: {}
|
|
||||||
Products: {}
|
|
||||||
Tags: {}""".format(
|
|
||||||
ctrl.get('_IDENTIFIER'),
|
|
||||||
add_0x(user_address),
|
|
||||||
ctrl.chain().common_name(),
|
|
||||||
str(r),
|
|
||||||
datetime.datetime.fromtimestamp(r.date_registered).ctime(),
|
|
||||||
r.gender,
|
|
||||||
r.location['area_name'],
|
|
||||||
','.join(r.products),
|
|
||||||
','.join(r.tags),
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
r = None
|
||||||
|
ctrl.write(
|
||||||
|
f"""
|
||||||
|
Phone: {ctrl.get("_IDENTIFIER")}
|
||||||
|
Network address: {add_0x(user_address)}
|
||||||
|
Chain: {ctrl.chain().common_name()}"""
|
||||||
|
)
|
||||||
|
ctrl.notify("resolving metadata for address {}".format(user_address_normal))
|
||||||
|
try:
|
||||||
|
r = user_address_store.by_address(
|
||||||
|
user_address_normal, update=ctrl.get("_FORCE")
|
||||||
|
)
|
||||||
|
if r:
|
||||||
|
ctrl.write(
|
||||||
|
f"""
|
||||||
|
Name: { str(r)}
|
||||||
|
Registered: {datetime.datetime.fromtimestamp(r.date_registered).ctime()}
|
||||||
|
Gender: {r.gender}
|
||||||
|
Location: {r.location["area_name"]}
|
||||||
|
Products: {",".join(r.products)}
|
||||||
|
Tags: {",".join(r.tags)}"""
|
||||||
|
)
|
||||||
|
except MetadataNotFoundError as e:
|
||||||
|
ctrl.ouch(f"MetadataNotFoundError: Could not resolve metadata for user {e}\n")
|
||||||
|
|
||||||
tx_lines = []
|
tx_lines = []
|
||||||
seen_tokens = {}
|
seen_tokens = {}
|
||||||
for tx_src in txs['data']:
|
for tx_src in txs["data"]:
|
||||||
ctrl.notify('resolve details for tx {}'.format(tx_src['tx_hash']))
|
ctrl.notify("resolve details for tx {}".format(tx_src["tx_hash"]))
|
||||||
tx = ResolvedTokenTx.from_dict(tx_src)
|
tx = ResolvedTokenTx.from_dict(tx_src)
|
||||||
tx.resolve(token_store, user_address_store, show_decimals=True, update=ctrl.get('_FORCE'))
|
tx.resolve(
|
||||||
|
token_store,
|
||||||
|
user_address_store,
|
||||||
|
show_decimals=True,
|
||||||
|
update=ctrl.get("_FORCE"),
|
||||||
|
)
|
||||||
tx_lines.append(tx)
|
tx_lines.append(tx)
|
||||||
seen_tokens[tx.source_token_label] = tx.source_token
|
seen_tokens[tx.source_token_label] = tx.source_token
|
||||||
seen_tokens[tx.destination_token_label] = tx.destination_token
|
seen_tokens[tx.destination_token_label] = tx.destination_token
|
||||||
|
|
||||||
for k in seen_tokens.keys():
|
for k in seen_tokens.keys():
|
||||||
ctrl.notify('resolve token {}'.format(seen_tokens[k]))
|
ctrl.notify("resolve token {}".format(seen_tokens[k]))
|
||||||
(token_symbol, token_decimals) = token_store.by_address(seen_tokens[k])
|
(token_symbol, token_decimals) = token_store.by_address(seen_tokens[k])
|
||||||
ctrl.notify('get token balance for {} => {}'.format(token_symbol, seen_tokens[k]))
|
ctrl.notify(
|
||||||
|
"get token balance for {} => {}".format(token_symbol, seen_tokens[k])
|
||||||
|
)
|
||||||
balance = token_balance(ctrl.chain(), ctrl.conn(), seen_tokens[k], user_address)
|
balance = token_balance(ctrl.chain(), ctrl.conn(), seen_tokens[k], user_address)
|
||||||
fmt = '{:.' + str(token_decimals) + 'f}'
|
fmt = "{:." + str(token_decimals) + "f}"
|
||||||
decimal_balance = fmt.format(balance / (10 ** token_decimals))
|
decimal_balance = fmt.format(balance / (10**token_decimals))
|
||||||
ctrl.write("Balances:\n {} {}".format(token_symbol, decimal_balance))
|
ctrl.write("Balances:\n {} {}".format(token_symbol, decimal_balance))
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
@ -12,7 +12,7 @@ from cic_types.condiments import MetadataPointer
|
|||||||
from cic_types.models.person import Person
|
from cic_types.models.person import Person
|
||||||
from cic_types.ext.requests import make_request
|
from cic_types.ext.requests import make_request
|
||||||
from cic_types.processor import generate_metadata_pointer
|
from cic_types.processor import generate_metadata_pointer
|
||||||
import requests.exceptions
|
from requests.exceptions import HTTPError
|
||||||
import phonenumbers
|
import phonenumbers
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
@ -222,7 +222,7 @@ class FileUserStore:
|
|||||||
try:
|
try:
|
||||||
r = getter.open(ptr)
|
r = getter.open(ptr)
|
||||||
user_address = json.loads(r)
|
user_address = json.loads(r)
|
||||||
except requests.exceptions.HTTPError as e:
|
except HTTPError as e:
|
||||||
logg.debug('no address found for phone {}: {}'.format(phone, e))
|
logg.debug('no address found for phone {}: {}'.format(phone, e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ class FileUserStore:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logg.debug('no metadata found for {}: {}'.format(address, e))
|
logg.debug('no metadata found for {}: {}'.format(address, e))
|
||||||
|
|
||||||
if r == None:
|
if not r:
|
||||||
self.failed_entities[address] = True
|
self.failed_entities[address] = True
|
||||||
raise MetadataNotFoundError()
|
raise MetadataNotFoundError()
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
usumbufu~=0.3.6
|
usumbufu~=0.3.8
|
||||||
confini~=0.5.4
|
confini~=0.6.0
|
||||||
cic-eth-registry~=0.6.1
|
cic-eth-registry~=0.6.9
|
||||||
cic-types~=0.2.1a8
|
cic-types~=0.2.2
|
||||||
phonenumbers==8.12.12
|
phonenumbers==8.12.12
|
||||||
eth-erc20~=0.1.2
|
eth-erc20~=0.3.0
|
||||||
hexathon~=0.1.0
|
hexathon~=0.1.0
|
||||||
pycryptodome~=3.10.1
|
pycryptodome~=3.10.1
|
||||||
chainlib-eth~=0.0.21
|
chainlib-eth~=0.1.0
|
||||||
chainlib~=0.0.17
|
chainlib~=0.1.0
|
||||||
urlybird~=0.0.2
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = clicada
|
name = clicada
|
||||||
version = 0.0.6a2
|
version = 0.1.3
|
||||||
description = CLI CRM tool for the cic-stack custodial wallet system
|
description = CLI CRM tool for the cic-stack custodial wallet system
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
Loading…
Reference in New Issue
Block a user