14 Commits

8 changed files with 139 additions and 54 deletions

4
.gitignore vendored
View File

@@ -2,3 +2,7 @@ __pycache__
*.egg-info
build/
*.pyc
.venv
.clicada
dist/
.vscode/

View File

@@ -1,3 +1,5 @@
- 0.0.7
* fix: make store_path relative to the users home
- 0.0.6
* Add cache encryption, with AES-CTR-128
- 0.0.5

87
README.md Normal file
View 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
```

View File

@@ -3,7 +3,8 @@ import json
# external imports
from clicada.user import FileUserStore
from pathlib import Path
import os
categories = [
'phone',
@@ -35,7 +36,7 @@ def validate(config, args):
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.put(ctrl.get('_IDENTIFIER'), json.dumps(ctrl.get('_TAG')), force=True)
user_store.stick(ctrl.get('_IDENTIFIER'))

View File

@@ -1,25 +1,22 @@
# standard imports
import sys
import logging
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
from cic_eth_registry import CICRegistry
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
from cic_types.models.person import Person
from chainlib.eth.address import to_checksum_address
from chainlib.encode import TxHexNormalizer
from hexathon import add_0x
# local imports
from clicada.tx import TxGetter
from clicada.user import FileUserStore
from clicada.token import (
FileTokenStore,
token_balance,
)
from clicada.tx import ResolvedTokenTx
from clicada.error import MetadataNotFoundError
from clicada.token import FileTokenStore, token_balance
# local imports
from clicada.tx import ResolvedTokenTx, TxGetter
from clicada.user import FileUserStore
from hexathon import add_0x
logg = logging.getLogger(__name__)
@@ -30,7 +27,7 @@ def process_args(argparser):
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('-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('identifier', type=str, help='user identifier (phone_number or address)')
def extra_args():
@@ -54,22 +51,26 @@ def validate(config, args):
def execute(ctrl):
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_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')))
user_address = user_phone_store.by_phone(ctrl.get('_IDENTIFIER'), update=ctrl.get('_FORCE'))
identifier = ctrl.get('_IDENTIFIER')
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:
ctrl.ouch('unknown identifier: {}\n'.format(ctrl.get('_IDENTIFIER')))
ctrl.ouch('unknown identifier: {}\n'.format(identifier))
sys.exit(1)
try:
user_address = to_checksum_address(user_address)
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)
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)
ctrl.notify('retrieving txs for address {}'.format(user_address_normal))
@@ -81,31 +82,21 @@ def execute(ctrl):
user_address_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
ctrl.notify('resolving metadata for address {}'.format(user_address_normal))
r = None
try:
r = user_address_store.by_address(user_address_normal, update=ctrl.get('_FORCE'))
except MetadataNotFoundError as e:
ctrl.ouch('could not resolve metadata for user: {}'.format(e))
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),
)
ctrl.write(f"""Phone: {ctrl.get('_IDENTIFIER')}
Network address: {add_0x(user_address)}
Chain: {ctrl.chain().common_name()}
Name: {str(r)}
Registered: {r and datetime.datetime.fromtimestamp(r).ctime()}
Gender: {r and r.gender}
Location: {r and r.location['area_name']}
Products: {r and ','.join(r.products)}
Tags: {r and ','.join(r.tags)}"""
)
tx_lines = []

View File

@@ -12,7 +12,7 @@ from cic_types.condiments import MetadataPointer
from cic_types.models.person import Person
from cic_types.ext.requests import make_request
from cic_types.processor import generate_metadata_pointer
import requests.exceptions
from requests.exceptions import HTTPError
import phonenumbers
# local imports
@@ -222,7 +222,7 @@ class FileUserStore:
try:
r = getter.open(ptr)
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))
return None
@@ -269,7 +269,7 @@ class FileUserStore:
except Exception as e:
logg.debug('no metadata found for {}: {}'.format(address, e))
if r == None:
if not r:
self.failed_entities[address] = True
raise MetadataNotFoundError()

View File

@@ -1,10 +1,10 @@
usumbufu~=0.3.5
confini~=0.5.3
cic-eth-registry~=0.6.1
cic-types~=0.2.1a8
usumbufu~=0.3.8
confini~=0.6.0
cic-eth-registry~=0.6.9
cic-types~=0.2.2
phonenumbers==8.12.12
eth-erc20~=0.1.2
eth-erc20~=0.3.0
hexathon~=0.1.0
pycryptodome~=3.10.1
chainlib-eth~=0.0.21
chainlib~=0.0.17
chainlib-eth~=0.1.0
chainlib~=0.1.0

View File

@@ -1,6 +1,6 @@
[metadata]
name = clicada
version = 0.0.6a2
version = 0.1.1
description = CLI CRM tool for the cic-stack custodial wallet system
author = Louis Holbrook
author_email = dev@holbrook.no