Compare commits
2 Commits
lash/admin
...
lash/schmi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
412ab5a186
|
||
|
|
bf80443c8d
|
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
||||
.git
|
||||
.cache
|
||||
.dot
|
||||
**/doc
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "apps/cic-cache"]
|
||||
path = apps/cic-cache
|
||||
url = git@gitlab.com:grassrootseconomics/cic-cache.git
|
||||
[submodule "apps/cic-meta"]
|
||||
path = apps/cic-meta
|
||||
url = git@gitlab.com:grassrootseconomics/cic-meta.git
|
||||
|
||||
@@ -2,13 +2,6 @@
|
||||
|
||||
## Getting started
|
||||
|
||||
## Make some keys
|
||||
|
||||
```
|
||||
docker build -t bloxie . && docker run -v "$(pwd)/keys:/root/keys" --rm -it -t bloxie account new --chain /root/bloxberg.json --keys-path /root/keys
|
||||
```
|
||||
|
||||
|
||||
### Prepare the repo
|
||||
|
||||
This is stuff we need to put in makefile but for now...
|
||||
|
||||
5
apps/bloxbergValidatorSetup/.gitignore
vendored
5
apps/bloxbergValidatorSetup/.gitignore
vendored
@@ -1,6 +1,3 @@
|
||||
/validator/bloxbergData
|
||||
/validator/bloxberg.log
|
||||
keys/*
|
||||
!keys/Bloxberg
|
||||
keys/Bloxberg/*
|
||||
!keys/Bloxberg/UTC--2021-02-10T16-57-35Z--03512a62-5334-20cc-4e44-71156f33cff6
|
||||
keys/**/*
|
||||
|
||||
@@ -17,7 +17,7 @@ COPY ./validator/bloxberg.json \
|
||||
./validator/validator.toml \
|
||||
/root/
|
||||
|
||||
COPY keys/ /root/keys/
|
||||
COPY ./keys/ /root/keys/
|
||||
|
||||
# RUN chown -R parity:parity $HOME/ && \
|
||||
# chmod -R 775 $HOME/ && \
|
||||
@@ -25,4 +25,4 @@ COPY keys/ /root/keys/
|
||||
# USER parity
|
||||
|
||||
ENTRYPOINT [ "parity" ]
|
||||
CMD [ "--config", "/root/validator.toml", "--keys-path", "/root/keys/", "--password", "/root/validator.pwd" ]
|
||||
CMD [ "--config", "/root/validator.toml", "--keys-path", "/root/keys/" ]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
The original bloxberg node config was kind of annoying so I am running it more like vanilla parity. This way you can pass command flags directly to parity.
|
||||
## Make some keys
|
||||
```
|
||||
docker build -t bloxie . && docker run -v ${PWD}/keys:/root/keys --rm -it -t bloxie account new --chain /root/bloxberg.json --keys-path /root/keys --password /root/validator.pwd
|
||||
docker build -t bloxie . && docker run -v ${PWD}/keys:/root/keys --rm -it -t bloxie account new --chain /root/bloxberg.json --keys-path /root/keys
|
||||
```
|
||||
|
||||
## Enter the signer address and passwords in the config files
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"id":"03512a62-5334-20cc-4e44-71156f33cff6","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"dc388338c4d4e3203604aeb3d1c6bbfa"},"ciphertext":"8a945775b87089ce94537e011799f3abc1577c5dd1f3fbaebe1cd96dfdfc8b5a","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"e8585836540caca01282381f5c1fe128e53b15b40f9d152fbc5a4f82a7967398"},"mac":"a7c7815e84a632ecf6d8f18c981bea73d50cd2e2a855a3e90477fc84ed14f906"},"address":"4f2a5902158c3969b245247f4154971d393301f2","name":"","meta":"{}"}
|
||||
@@ -7,7 +7,7 @@
|
||||
"maximumUncleCount": 0,
|
||||
"stepDuration": "5",
|
||||
"validators" : {
|
||||
"list": ["0x4f2a5902158c3969b245247f4154971d393301f2"]
|
||||
"list": ["0x6bd4e51b3730576ddc4049654ef60ed7f7436cb5"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ password = ["/root/validator.pwd"]
|
||||
|
||||
[mining]
|
||||
#CHANGE ENGINE SIGNER TO VALIDATOR ADDRESS
|
||||
engine_signer = "0x4f2a5902158c3969b245247f4154971d393301f2"
|
||||
engine_signer = "0x6bd4e51b3730576ddc4049654ef60ed7f7436cb5"
|
||||
reseal_on_txs = "none"
|
||||
force_sealing = true
|
||||
min_gas_price = 1000000
|
||||
|
||||
@@ -98,19 +98,6 @@ class AdminApi:
|
||||
session.close()
|
||||
|
||||
|
||||
def have_account(self, address_hex, chain_str):
|
||||
s_have = celery.signature(
|
||||
'cic_eth.eth.account.have',
|
||||
[
|
||||
address_hex,
|
||||
chain_str,
|
||||
],
|
||||
queue=self.queue,
|
||||
)
|
||||
t = s_have.apply_async()
|
||||
return t.get()
|
||||
|
||||
|
||||
def resend(self, tx_hash_hex, chain_str, in_place=True, unlock=False):
|
||||
logg.debug('resend {}'.format(tx_hash_hex))
|
||||
s_get_tx_cache = celery.signature(
|
||||
|
||||
@@ -35,10 +35,6 @@ def unpack_signed_raw_tx(tx_raw_bytes, chain_id):
|
||||
if chain_id != 0:
|
||||
v = int.from_bytes(d[6], 'big')
|
||||
vb = v - (chain_id * 2) - 35
|
||||
while len(d[7]) < 32:
|
||||
d[7] = b'\x00' + d[7]
|
||||
while len(d[8]) < 32:
|
||||
d[8] = b'\x00' + d[8]
|
||||
s = b''.join([d[7], d[8], bytes([vb])])
|
||||
so = KeyAPI.Signature(signature_bytes=s)
|
||||
|
||||
|
||||
@@ -557,26 +557,27 @@ def get_upcoming_tx(status=StatusEnum.READYSEND, recipient=None, before=None, ch
|
||||
:rtype: dict, with transaction hash as key, signed raw transaction as value
|
||||
"""
|
||||
session = SessionBase.create_session()
|
||||
q_outer = session.query(
|
||||
q = session.query(
|
||||
TxCache.sender,
|
||||
func.min(Otx.nonce).label('nonce'),
|
||||
)
|
||||
q_outer = q_outer.join(TxCache)
|
||||
q_outer = q_outer.join(Lock, isouter=True)
|
||||
q_outer = q_outer.filter(or_(Lock.flags==None, Lock.flags.op('&')(LockEnum.SEND.value)==0))
|
||||
q = q.join(TxCache)
|
||||
q = q.join(Lock, isouter=True)
|
||||
q = q.filter(or_(Lock.flags==None, Lock.flags.op('&')(LockEnum.SEND.value)==0))
|
||||
|
||||
if status >= StatusEnum.SENT:
|
||||
raise ValueError('not a valid non-final tx value: {}'.format(s))
|
||||
q_outer = q_outer.filter(Otx.status==status.value)
|
||||
q = q.filter(Otx.status==status)
|
||||
|
||||
if recipient != None:
|
||||
q_outer = q_outer.filter(TxCache.recipient==recipient)
|
||||
q = q.filter(TxCache.recipient==recipient)
|
||||
|
||||
q_outer = q_outer.group_by(TxCache.sender)
|
||||
q = q.group_by(TxCache.sender)
|
||||
|
||||
txs = {}
|
||||
|
||||
for r in q_outer.all():
|
||||
results = q.all()
|
||||
for r in results:
|
||||
q = session.query(Otx)
|
||||
q = q.join(TxCache)
|
||||
q = q.filter(TxCache.sender==r.sender)
|
||||
@@ -586,6 +587,7 @@ def get_upcoming_tx(status=StatusEnum.READYSEND, recipient=None, before=None, ch
|
||||
q = q.filter(TxCache.date_checked<before)
|
||||
|
||||
q = q.order_by(TxCache.date_created.desc())
|
||||
|
||||
o = q.first()
|
||||
|
||||
# TODO: audit; should this be possible if a row is found in the initial query? If not, at a minimum log error.
|
||||
@@ -600,6 +602,7 @@ def get_upcoming_tx(status=StatusEnum.READYSEND, recipient=None, before=None, ch
|
||||
q = q.filter(TxCache.otx_id==o.id)
|
||||
o = q.first()
|
||||
|
||||
logg.debug('oooo {}'.format(o))
|
||||
o.date_checked = datetime.datetime.now()
|
||||
session.add(o)
|
||||
session.commit()
|
||||
|
||||
@@ -68,7 +68,7 @@ app = celery.Celery(backend=config.get('CELERY_RESULT_URL'), broker=config.get(
|
||||
queue = args.q
|
||||
|
||||
dsn = dsn_from_config(config)
|
||||
SessionBase.connect(dsn, debug=config.true('DATABASE_DEBUG'))
|
||||
SessionBase.connect(dsn)
|
||||
|
||||
|
||||
re_websocket = re.compile('^wss?://')
|
||||
|
||||
@@ -10,7 +10,7 @@ version = (
|
||||
0,
|
||||
10,
|
||||
0,
|
||||
'alpha.26',
|
||||
'alpha.25',
|
||||
)
|
||||
|
||||
version_object = semver.VersionInfo(
|
||||
|
||||
@@ -43,6 +43,7 @@ COPY cic-eth/cic_eth/db/migrations/ /usr/local/share/cic-eth/alembic/
|
||||
COPY cic-eth/crypto_dev_signer_config/ /usr/local/etc/crypto-dev-signer/
|
||||
|
||||
RUN apt-get install -y git && \
|
||||
git clone https://gitlab.com/grassrootseconomics/cic-contracts.git && \
|
||||
mkdir -p /usr/local/share/cic/solidity && \
|
||||
cp -R cic-contracts/abis /usr/local/share/cic/solidity/abi
|
||||
git clone https://gitlab.com/grassrootseconomics/cic-contracts.git &&\
|
||||
mkdir -p /usr/local/share/cic/solidity/abi && \
|
||||
cp cic-contracts/abis/* /usr/local/share/cic/solidity/abi/
|
||||
|
||||
|
||||
@@ -14,9 +14,7 @@ RUN pip install -r $root_requirement_file $pip_extra_index_url_flag
|
||||
COPY cic-notify/setup.cfg \
|
||||
cic-notify/setup.py \
|
||||
./
|
||||
|
||||
COPY cic-notify/cic_notify/ ./cic_notify/
|
||||
|
||||
COPY cic-notify/requirements.txt \
|
||||
cic-notify/test_requirements.txt \
|
||||
./
|
||||
|
||||
13
apps/cic-notify/docker/Dockerfile.service
Normal file
13
apps/cic-notify/docker/Dockerfile.service
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM grassrootseconomics:cic-notify
|
||||
|
||||
#FROM python:3.8.6-alpine
|
||||
|
||||
#RUN apk update && \
|
||||
# apk add gnupg libpq
|
||||
|
||||
#COPY --from=0 /usr/local/ /usr/local/
|
||||
#COPY --from=0 /root/ /root/
|
||||
|
||||
#RUN apk add bash
|
||||
|
||||
WORKDIR /root
|
||||
@@ -18,5 +18,5 @@ build-push-cic-ussd:
|
||||
extends:
|
||||
- .py_build_push
|
||||
- .cic_ussd_variables
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ COPY cic-ussd/docker/db.sh \
|
||||
/root/
|
||||
|
||||
RUN chmod +x /root/*.sh
|
||||
RUN cd cic-ussd && \
|
||||
pip install $pip_extra_index_url_flag .
|
||||
|
||||
|
||||
# copy config and migration files to definitive file so they can be referenced in path definitions for running scripts
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /root/db.sh
|
||||
. ./db.sh
|
||||
|
||||
/usr/local/bin/cic-ussd-tasker -vv "$@"
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /root/db.sh
|
||||
. ./db.sh
|
||||
|
||||
/usr/local/bin/uwsgi --wsgi-file /usr/local/lib/python3.8/site-packages/cic_ussd/runnable/server.py --http :9000 --pyargv "-vv"
|
||||
/usr/local/bin/uwsgi --wsgi-file /usr/local/lib/python3.8/site-packages/cic_ussd/runnable/server.py --http :80 --pyargv "-vv"
|
||||
|
||||
@@ -6,10 +6,10 @@ betterpath==0.2.2
|
||||
billiard==3.6.3.0
|
||||
celery==4.4.7
|
||||
cffi==1.14.3
|
||||
cic-eth~=0.10.0a22
|
||||
cic-eth~=0.10.0a9
|
||||
cic-notify==0.3.1
|
||||
click==7.1.2
|
||||
confini~=0.3.6a1
|
||||
confini==0.3.5
|
||||
cryptography==3.2.1
|
||||
faker==4.17.1
|
||||
iniconfig==1.1.1
|
||||
|
||||
@@ -19,7 +19,7 @@ echo \n
|
||||
# pushd /usr/src
|
||||
|
||||
init_level_file=${CIC_DATA_DIR}/.init
|
||||
echo -n 1 > $init_level_file
|
||||
echo -n 0 > $init_level_file
|
||||
|
||||
# Abort on any error (including if wait-for-it fails).
|
||||
set -e
|
||||
@@ -29,7 +29,7 @@ if [[ -n "${ETH_PROVIDER}" ]]; then
|
||||
echo "waiting for ${ETH_PROVIDER}..."
|
||||
./wait-for-it.sh "${ETH_PROVIDER_HOST}:${ETH_PROVIDER_PORT}"
|
||||
|
||||
DEV_ETH_RESERVE_ADDRESS=`giftable-token-deploy -p $ETH_PROVIDER -y $keystore_file -i $CIC_CHAIN_SPEC --account $DEV_ETH_ACCOUNT_RESERVE_MINTER --minter $DEV_ETH_ACCOUNT_RESERVE_MINTER -v -w --name "Sarafu" --symbol "SRF" --decimals 6 $DEV_ETH_RESERVE_AMOUNT`
|
||||
DEV_ETH_RESERVE_ADDRESS=`giftable-token-deploy -p $ETH_PROVIDER -y $keystore_file -i $CIC_CHAIN_SPEC --account $DEV_ETH_ACCOUNT_RESERVE_MINTER --minter $DEV_ETH_ACCOUNT_RESERVE_MINTER -v -w --name "Sarafu" --symbol "SRF" $DEV_ETH_RESERVE_AMOUNT`
|
||||
|
||||
#BANCOR_REGISTRY_ADDRESS=`cic-bancor-deploy --bancor-dir /usr/local/share/cic/bancor -z $DEV_ETH_RESERVE_ADDRESS -p $ETH_PROVIDER -o $DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER`
|
||||
|
||||
@@ -68,6 +68,6 @@ cat $CIC_DATA_DIR/envlist | bash from_env.sh > $CIC_DATA_DIR/.env_all
|
||||
set +a
|
||||
set +e
|
||||
|
||||
echo -n 2 > $init_level_file
|
||||
echo -n 1 > $init_level_file
|
||||
|
||||
exec "$@"
|
||||
|
||||
220
apps/contract-migration/scripts/generate_users.py
Normal file
220
apps/contract-migration/scripts/generate_users.py
Normal file
@@ -0,0 +1,220 @@
|
||||
#!python3
|
||||
|
||||
# standard imports
|
||||
import json
|
||||
import time
|
||||
import datetime
|
||||
import random
|
||||
import logging
|
||||
import os
|
||||
import base64
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
import vobject
|
||||
|
||||
import celery
|
||||
import web3
|
||||
from faker import Faker
|
||||
import cic_registry
|
||||
import confini
|
||||
from cic_eth.api import Api
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
fake = Faker(['sl', 'en_US', 'no', 'de', 'ro'])
|
||||
|
||||
config_dir = os.environ.get('CONFINI_DIR', '/usr/local/etc/cic')
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-c', type=str, default=config_dir, help='config file')
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, help='chain spec')
|
||||
argparser.add_argument('-z', '--zero-balance', dest='z', action='store_true', help='do not generate initial balances')
|
||||
argparser.add_argument('source', type=str, help='input directory to process')
|
||||
args = argparser.parse_args()
|
||||
|
||||
config = confini.Config(config_dir, os.environ.get('CONFINI_ENV_PREFIX'))
|
||||
config.process()
|
||||
args_override = {
|
||||
'CIC_CHAIN_SPEC': getattr(args, 'i'),
|
||||
'ETH_PROVIDER': getattr(args, 'p'),
|
||||
}
|
||||
config.dict_override(args_override, 'cli flag')
|
||||
logg.info('loaded config\n{}'.format(config))
|
||||
|
||||
|
||||
# registration time generation
|
||||
dt_now = datetime.datetime.utcnow()
|
||||
dt_then = dt_now - datetime.timedelta(weeks=150)
|
||||
ts_now = int(dt_now.timestamp())
|
||||
ts_then = int(dt_then.timestamp())
|
||||
|
||||
celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'))
|
||||
|
||||
api = Api(config.get('CIC_CHAIN_SPEC'))
|
||||
|
||||
gift_activate = not args.z
|
||||
gift_max = 10000
|
||||
gift_factor = (10**9)
|
||||
|
||||
|
||||
categories = [
|
||||
"food/water",
|
||||
"fuel/energy",
|
||||
"education",
|
||||
"health",
|
||||
"shop",
|
||||
"environment",
|
||||
"transport",
|
||||
"farming/labor",
|
||||
"savingsgroup",
|
||||
]
|
||||
|
||||
phone_idx = []
|
||||
|
||||
|
||||
def genPhoneIndex(phone):
|
||||
h = hashlib.new('sha256')
|
||||
h.update(phone.encode('utf-8'))
|
||||
h.update(b'cic.msisdn')
|
||||
return h.digest().hex()
|
||||
|
||||
|
||||
def genId(addr, typ):
|
||||
h = hashlib.new('sha256')
|
||||
h.update(bytes.fromhex(addr[2:]))
|
||||
h.update(typ.encode('utf-8'))
|
||||
return h.digest().hex()
|
||||
|
||||
|
||||
def genDate():
|
||||
|
||||
logg.info(ts_then)
|
||||
ts = random.randint(ts_then, ts_now)
|
||||
return datetime.datetime.fromtimestamp(ts).timestamp()
|
||||
|
||||
|
||||
def genPhone():
|
||||
return fake.msisdn()
|
||||
|
||||
|
||||
def genPersonal(phone):
|
||||
fn = fake.first_name()
|
||||
ln = fake.last_name()
|
||||
e = fake.email()
|
||||
|
||||
v = vobject.vCard()
|
||||
first_name = fake.first_name()
|
||||
last_name = fake.last_name()
|
||||
v.add('n')
|
||||
v.n.value = vobject.vcard.Name(family=last_name, given=first_name)
|
||||
v.add('fn')
|
||||
v.fn.value = '{} {}'.format(first_name, last_name)
|
||||
v.add('tel')
|
||||
v.tel.typ_param = 'CELL'
|
||||
v.tel.value = phone
|
||||
v.add('email')
|
||||
v.email.value = fake.email()
|
||||
|
||||
vcard_serialized = v.serialize()
|
||||
vcard_base64 = base64.b64encode(vcard_serialized.encode('utf-8'))
|
||||
|
||||
return vcard_base64.decode('utf-8')
|
||||
|
||||
|
||||
def genCats():
|
||||
i = random.randint(0, 3)
|
||||
return random.choices(categories, k=i)
|
||||
|
||||
|
||||
def genAmount():
|
||||
return random.randint(0, gift_max) * gift_factor
|
||||
|
||||
|
||||
def gen():
|
||||
old_blockchain_address = '0x' + os.urandom(20).hex()
|
||||
accounts_index_account = config.get('DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER')
|
||||
if not accounts_index_account:
|
||||
accounts_index_account = None
|
||||
logg.debug('accounts indexwriter {}'.format(accounts_index_account))
|
||||
t = api.create_account()
|
||||
new_blockchain_address = t.get()
|
||||
gender = random.choice(['female', 'male', 'other'])
|
||||
phone = genPhone()
|
||||
v = genPersonal(phone)
|
||||
o = {
|
||||
'date_registered': genDate(),
|
||||
'vcard': v,
|
||||
'gender': gender,
|
||||
'key': {
|
||||
'ethereum': [
|
||||
old_blockchain_address,
|
||||
new_blockchain_address,
|
||||
],
|
||||
},
|
||||
'location': {
|
||||
'latitude': str(fake.latitude()),
|
||||
'longitude': str(fake.longitude()),
|
||||
'external': { # add osm lookup
|
||||
}
|
||||
},
|
||||
'selling': genCats(),
|
||||
}
|
||||
uid = genId(new_blockchain_address, 'cic.person')
|
||||
|
||||
#logg.info('gifting {} to {}'.format(amount, new_blockchain_address))
|
||||
|
||||
return (uid, phone, o)
|
||||
|
||||
|
||||
def prepareLocalFilePath(datadir, address):
|
||||
parts = [
|
||||
address[:2],
|
||||
address[2:4],
|
||||
]
|
||||
dirs = '{}/{}/{}'.format(
|
||||
datadir,
|
||||
parts[0],
|
||||
parts[1],
|
||||
)
|
||||
os.makedirs(dirs, exist_ok=True)
|
||||
return dirs
|
||||
|
||||
|
||||
def main():
|
||||
os.makedirs('data/person', exist_ok=True)
|
||||
os.makedirs('data/phone', exist_ok=True)
|
||||
|
||||
fa = open('./data/amounts', 'w')
|
||||
fb = open('./data/addresses', 'w')
|
||||
|
||||
for i in range(int(sys.argv[1])):
|
||||
|
||||
(uid, phone, o) = gen()
|
||||
eth = o['key']['ethereum'][1]
|
||||
|
||||
print(o)
|
||||
|
||||
d = prepareLocalFilePath('./data/person', uid)
|
||||
f = open('{}/{}'.format(d, uid), 'w')
|
||||
json.dump(o, f)
|
||||
f.close()
|
||||
|
||||
pidx = genPhoneIndex(phone)
|
||||
d = prepareLocalFilePath('./data/phone', uid)
|
||||
f = open('{}/{}'.format(d, pidx), 'w')
|
||||
f.write(eth)
|
||||
f.close()
|
||||
|
||||
amount = genAmount()
|
||||
fa.write('{},{}\n'.format(eth,amount))
|
||||
fb.write('{}\n'.format(eth))
|
||||
logg.debug('pidx {}, uid {}, eth {}, amount {}'.format(pidx, uid, eth, amount))
|
||||
|
||||
fb.close()
|
||||
fa.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
115
apps/contract-migration/scripts/import_users.py
Normal file
115
apps/contract-migration/scripts/import_users.py
Normal file
@@ -0,0 +1,115 @@
|
||||
# standard imports
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import logging
|
||||
import argparse
|
||||
import uuid
|
||||
from glob import glob
|
||||
|
||||
# third-party imports
|
||||
import redis
|
||||
import confini
|
||||
import celery
|
||||
from chainlib.eth.address import to_checksum
|
||||
from cic_types.models.person import Person
|
||||
from cic_eth.api.api_task import Api
|
||||
from cic_registry.chain import ChainSpec
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
default_config_dir = '/usr/local/etc/cic'
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-c', type=str, default=default_config_dir, help='config file')
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
||||
argparser.add_argument('--redis-host', dest='redis_host', type=str, help='redis host to use for task submission')
|
||||
argparser.add_argument('--redis-port', dest='redis_port', type=int, help='redis host to use for task submission')
|
||||
argparser.add_argument('--redis-db', dest='redis_db', type=int, help='redis db to use for task submission and callback')
|
||||
argparser.add_argument('--redis-host-callback', dest='redis_host_callback', default='localhost', type=str, help='redis host to use for callback')
|
||||
argparser.add_argument('--redis-port-callback', dest='redis_port_callback', default=6379, type=int, help='redis port to use for callback')
|
||||
argparser.add_argument('--timeout', default=20.0, type=float, help='Callback timeout')
|
||||
argparser.add_argument('-q', type=str, default='cic-eth', help='Task queue')
|
||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||
argparser.add_argument('user_dir', type=str, help='path to users export dir tree')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.v:
|
||||
logg.setLevel(logging.INFO)
|
||||
elif args.vv:
|
||||
logg.setLevel(logging.DEBUG)
|
||||
|
||||
config_dir = args.c
|
||||
config = confini.Config(config_dir, os.environ.get('CONFINI_ENV_PREFIX'))
|
||||
config.process()
|
||||
args_override = {
|
||||
'CIC_CHAIN_SPEC': getattr(args, 'i'),
|
||||
'REDIS_HOST': getattr(args, 'redis_host'),
|
||||
'REDIS_PORT': getattr(args, 'redis_port'),
|
||||
'REDIS_DB': getattr(args, 'redis_db'),
|
||||
}
|
||||
config.dict_override(args_override, 'cli')
|
||||
celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'))
|
||||
|
||||
redis_host = config.get('REDIS_HOST')
|
||||
redis_port = config.get('REDIS_PORT')
|
||||
redis_db = config.get('REDIS_DB')
|
||||
r = redis.Redis(redis_host, redis_port, redis_db)
|
||||
|
||||
ps = r.pubsub()
|
||||
|
||||
user_dir = args.user_dir
|
||||
|
||||
|
||||
def register_eth(u):
|
||||
redis_channel = str(uuid.uuid4())
|
||||
ps.subscribe(redis_channel)
|
||||
ps.get_message()
|
||||
api = Api(
|
||||
config.get('CIC_CHAIN_SPEC'),
|
||||
queue=args.q,
|
||||
callback_param='{}:{}:{}:{}'.format(args.redis_host_callback, args.redis_port_callback, redis_db, redis_channel),
|
||||
callback_task='cic_eth.callbacks.redis.redis',
|
||||
callback_queue=args.q,
|
||||
)
|
||||
t = api.create_account(register=True)
|
||||
|
||||
ps.get_message()
|
||||
m = ps.get_message(timeout=args.timeout)
|
||||
address = json.loads(m['data'])
|
||||
logg.debug('register eth {} {}'.format(u, address))
|
||||
|
||||
return address
|
||||
|
||||
|
||||
def register_ussd(u):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
fi = open(os.path.join(user_dir, 'addresses.csv'), 'a') # old,new
|
||||
|
||||
for x in os.walk(user_dir):
|
||||
for y in x[2]:
|
||||
if y[len(y)-5:] != '.json':
|
||||
continue
|
||||
filepath = os.path.join(x[0], y)
|
||||
f = open(filepath, 'r')
|
||||
try:
|
||||
o = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
f.close()
|
||||
logg.error('load error for {}: {}'.format(y, e))
|
||||
continue
|
||||
f.close()
|
||||
u = Person(o)
|
||||
|
||||
new_address = register_eth(u)
|
||||
|
||||
old_address = u.identities['evm']['bloxberg:8995'][0]
|
||||
fi.write('{}.{}\n'.format(old_address, new_address))
|
||||
|
||||
fi.close()
|
||||
2
apps/contract-migration/scripts/requirements.txt
Normal file
2
apps/contract-migration/scripts/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
cic-types==0.1.0
|
||||
chainlib==0.0.1a4
|
||||
@@ -1,12 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# defaults
|
||||
initlevel=`cat ${CIC_DATA_DIR}/.init`
|
||||
echo $inilevel
|
||||
if [ $initlevel -lt 2 ]; then
|
||||
>&2 echo "initlevel too low $initlevel"
|
||||
exit 1
|
||||
fi
|
||||
source ${CIC_DATA_DIR}/.env
|
||||
source ${CIC_DATA_DIR}/.env_all
|
||||
DEV_PIP_EXTRA_INDEX_URL=${DEV_PIP_EXTRA_INDEX_URL:-https://pip.grassrootseconomics.net:8433}
|
||||
@@ -14,6 +8,7 @@ DEV_DATABASE_NAME_CIC_ETH=${DEV_DATABASE_NAME_CIC_ETH:-"cic-eth"}
|
||||
CIC_DATA_DIR=${CIC_DATA_DIR:-/tmp/cic}
|
||||
|
||||
# Debug flag
|
||||
#debug='-v'
|
||||
DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER=0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C
|
||||
keystore_file=./keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c
|
||||
debug='-vv'
|
||||
@@ -29,7 +24,7 @@ truncate $env_out_file -s 0
|
||||
set -e
|
||||
set -a
|
||||
|
||||
pip install --extra-index-url $DEV_PIP_EXTRA_INDEX_URL cic-eth==0.10.0a25 chainlib==0.0.1a4
|
||||
pip install --extra-index-url $DEV_PIP_EXTRA_INDEX_URL cic-eth==0.10.0a25 cic-tools==0.0.1a4
|
||||
|
||||
>&2 echo "create account for gas gifter"
|
||||
old_gas_provider=$DEV_ETH_ACCOUNT_GAS_PROVIDER
|
||||
@@ -52,7 +47,7 @@ DEV_ETH_ACCOUNT_FAUCET_OWNER=`cic-eth-create $debug --redis-host-callback=$REDIS
|
||||
echo DEV_ETH_ACCOUNT_GAS_GIFTER=$DEV_ETH_ACCOUNT_FAUCET_OWNER >> $env_out_file
|
||||
cic-eth-tag FAUCET_GIFTER $DEV_ETH_ACCOUNT_FAUCET_OWNER
|
||||
|
||||
>&2 echo "create account for accounts index writer"
|
||||
>&2 echo "create account for accounts index owner"
|
||||
DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=`cic-eth-create $debug --redis-host-callback=$REDIS_HOST --redis-port-callback=$REDIS_PORT --no-register`
|
||||
echo DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=$DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER >> $env_out_file
|
||||
cic-eth-tag ACCOUNTS_INDEX_WRITER $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER
|
||||
@@ -141,7 +136,7 @@ token_description_two=0x54686973206973207468652053617261667520746f6b656e00000000
|
||||
>&2 echo "add keystore account $keystore_file to accounts index writers"
|
||||
>&2 eth-accounts-index-add -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -r $CIC_ACCOUNTS_INDEX_ADDRESS --writer $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER -w $debug
|
||||
|
||||
echo -n 0 > $init_level_file
|
||||
echo -n 2 > $init_level_file
|
||||
|
||||
set +a
|
||||
set +e
|
||||
|
||||
@@ -35,11 +35,11 @@ services:
|
||||
context: apps/bloxbergValidatorSetup
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- ${DEV_ETH_PORT_HTTP:-63545}:8545
|
||||
- ${DEV_ETH_PORT_WS-63546}:8546
|
||||
- ${DEV_ETH_PORT_HTTP:-8545}:8545
|
||||
- ${DEV_ETH_PORT_WS-8546}:8546
|
||||
- 30303
|
||||
volumes:
|
||||
- ./apps/bloxbergValidatorSetup/keys:/root/keys # stores the signing key locally
|
||||
#- ./keys:/root/keys # stores the signing key locally
|
||||
- bloxberg-data:/root/.local/share/io.parity.ethereum/
|
||||
|
||||
# See contents of /initdb/create_db.sql for app user, password and databases
|
||||
@@ -49,7 +49,7 @@ services:
|
||||
POSTGRES_HOST_AUTH_METHOD: trust # for postgres user access w/o password. Obvioulsy not safe but allows easy elevated debugging.
|
||||
# PGDATA: /tmp/cic/postgres
|
||||
ports:
|
||||
- ${DEV_POSTGRES_PORT:-63432}:5432
|
||||
- ${DEV_POSTGRES_PORT:-5432}:5432
|
||||
volumes:
|
||||
- ./scripts/initdb/create_db.sql:/docker-entrypoint-initdb.d/1-create_all_db.sql
|
||||
- ./apps/cic-meta/scripts/initdb/postgresql.sh:/docker-entrypoint-initdb.d/2-init-cic-meta.sh
|
||||
@@ -58,7 +58,7 @@ services:
|
||||
redis:
|
||||
image: redis:6.0.9-alpine
|
||||
ports:
|
||||
- ${DEV_REDIS_PORT:-63379}:6379
|
||||
- ${DEV_REDIS_PORT:-6379}:6379
|
||||
command: "--loglevel verbose"
|
||||
|
||||
bee:
|
||||
@@ -68,8 +68,8 @@ services:
|
||||
BEE_NETWORK_ID: ${BEE_NETWORK_ID:-313}
|
||||
BEE_PASSWORD: ${BEE_PASSWORD:-password}
|
||||
ports:
|
||||
- ${DEV_BEE_PORT:-63633}:1633
|
||||
- ${DEV_BEE_PORT_DEBUG:-63635}:1635
|
||||
- ${DEV_BEE_PORT:-1633}:1633
|
||||
- ${DEV_BEE_PORT_DEBUG:-1635}:1635
|
||||
command: "start --swap-enable=false --standalone"
|
||||
volumes:
|
||||
- bee-data:/tmp/cic/bee
|
||||
@@ -117,14 +117,8 @@ services:
|
||||
CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis:6379}
|
||||
DEV_PIP_EXTRA_INDEX_URL: ${DEV_PIP_EXTRA_INDEX_URL:-https://pip.grassrootseconomics.net:8433}
|
||||
command: ["./seed_cic_eth.sh"]
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
depends_on:
|
||||
- eth
|
||||
- postgres
|
||||
- redis
|
||||
- cic-eth-tasker
|
||||
volumes:
|
||||
- contract-config:/tmp/cic/config
|
||||
|
||||
@@ -233,7 +227,7 @@ services:
|
||||
DATABASE_USER: ${DATABASE_USER:-grassroots}
|
||||
DATABASE_HOST: ${DATABASE_HOST:-postgres}
|
||||
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_eth}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_cache}
|
||||
DATABASE_PORT: ${DATABASE_PORT:-5432}
|
||||
DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
|
||||
DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
|
||||
@@ -269,7 +263,7 @@ services:
|
||||
DATABASE_USER: ${DATABASE_USER:-grassroots}
|
||||
DATABASE_HOST: ${DATABASE_HOST:-postgres}
|
||||
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_eth}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_cache}
|
||||
DATABASE_PORT: ${DATABASE_PORT:-5432}
|
||||
DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
|
||||
DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
|
||||
@@ -305,7 +299,7 @@ services:
|
||||
DATABASE_USER: ${DATABASE_USER:-grassroots}
|
||||
DATABASE_HOST: ${DATABASE_HOST:-postgres}
|
||||
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_eth}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_cache}
|
||||
DATABASE_PORT: ${DATABASE_PORT:-5432}
|
||||
DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
|
||||
DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
|
||||
@@ -315,7 +309,6 @@ services:
|
||||
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
|
||||
CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
|
||||
TASKS_TRANSFER_CALLBACKS: $TASKS_TRANSFER_CALLBACKS
|
||||
DATABASE_DEBUG: ${DATABASE_DEBUG:-true}
|
||||
|
||||
depends_on:
|
||||
- eth
|
||||
@@ -344,7 +337,7 @@ services:
|
||||
DATABASE_USER: ${DATABASE_USER:-grassroots}
|
||||
DATABASE_HOST: ${DATABASE_HOST:-postgres}
|
||||
DATABASE_PASSWORD: ${DATABASE_PASSWORD:-tralala}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_eth}
|
||||
DATABASE_NAME: ${DATABASE_NAME_CIC_CACHE:-cic_cache}
|
||||
DATABASE_PORT: ${DATABASE_PORT:-5432}
|
||||
DATABASE_ENGINE: ${DATABASE_ENGINE:-postgres}
|
||||
DATABASE_DRIVER: ${DATABASE_DRIVER:-psycopg2}
|
||||
@@ -354,7 +347,6 @@ services:
|
||||
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
|
||||
CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
|
||||
TASKS_TRANSFER_CALLBACKS: $TASKS_TRANSFER_CALLBACKS
|
||||
CIC_TX_RETRY_DELAY: 15
|
||||
depends_on:
|
||||
- eth
|
||||
- postgres
|
||||
@@ -381,13 +373,11 @@ services:
|
||||
CIC_CHAIN_SPEC: $CIC_CHAIN_SPEC
|
||||
CELERY_BROKER_URL: $CELERY_BROKER_URL
|
||||
CELERY_RESULT_URL: $CELERY_RESULT_URL
|
||||
SERVER_PORT: 8000
|
||||
SERVER_PORT: 80
|
||||
depends_on:
|
||||
- eth
|
||||
- postgres
|
||||
- redis
|
||||
ports:
|
||||
- ${HTTP_PORT_CIC_ETH:-63314}:8000
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
@@ -413,9 +403,7 @@ services:
|
||||
|
||||
|
||||
cic-notify-tasker:
|
||||
build:
|
||||
context: apps/
|
||||
dockerfile: cic-notify/docker/Dockerfile
|
||||
image: grassrootseconomics:cic-notify-service
|
||||
environment:
|
||||
DATABASE_USER: ${DATABASE_USER:-grassroots}
|
||||
DATABASE_HOST: ${DATABASE_HOST:-postgres}
|
||||
@@ -450,8 +438,8 @@ services:
|
||||
DATABASE_USER: ${DATABASE_USER:-grassroots}
|
||||
DATABASE_HOST: ${DATABASE_HOST:-postgres}
|
||||
DATABASE_PORT: ${DATABASE_PORT:-5432}
|
||||
SERVER_HOST: localhost
|
||||
SERVER_PORT: 8000
|
||||
SERVER_HOST: ${SERVER_HOST:-localhost}
|
||||
SERVER_PORT: ${SERVER_HOST:-80}
|
||||
DATABASE_SCHEMA_SQL_PATH: ""
|
||||
PGP_EXPORTS_DIR: /tmp/src/cic-meta/tests/
|
||||
PGP_PRIVATEKEY_FILE: privatekeys.asc
|
||||
@@ -460,7 +448,7 @@ services:
|
||||
PGP_PUBLICKEY_ACTIVE_FILE: publickeys.asc
|
||||
PGP_PUBLICKEY_ENCRYPT_FILE: publickeys.asc
|
||||
ports:
|
||||
- ${HTTP_PORT_CIC_META:-63380}:8000
|
||||
- ${HTTP_PORT_CIC_META:-63380}:${SERVER_PORT:-80}
|
||||
depends_on:
|
||||
- postgres
|
||||
deploy:
|
||||
@@ -470,49 +458,49 @@ services:
|
||||
- ${LOCAL_VOLUME_DIR:-/tmp/cic}/pgp:/tmp/cic/pgp
|
||||
command: "/root/start_server.sh -vv"
|
||||
|
||||
cic-ussd-server:
|
||||
# image: grassrootseconomics:cic-ussd
|
||||
build:
|
||||
context: apps/
|
||||
dockerfile: cic-ussd/docker/Dockerfile
|
||||
environment:
|
||||
DATABASE_USER: grassroots
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_PORT: 5432
|
||||
DATABASE_PASSWORD: tralala
|
||||
DATABASE_NAME: cic_ussd
|
||||
DATABASE_ENGINE: postgresql
|
||||
DATABASE_DRIVER: psycopg2
|
||||
SERVER_PORT: 8000
|
||||
ports:
|
||||
- ${HTTP_PORT_CIC_USSD:-63315}:8000
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
command: "/root/start_uwsgi.sh"
|
||||
|
||||
cic-ussd-tasker:
|
||||
# image: grassrootseconomics:cic-ussd
|
||||
build:
|
||||
context: apps
|
||||
dockerfile: cic-ussd/docker/Dockerfile
|
||||
environment:
|
||||
DATABASE_USER: grassroots
|
||||
DATABASE_HOST: postgres
|
||||
DATABASE_PORT: 5432
|
||||
DATABASE_PASSWORD: tralala
|
||||
DATABASE_NAME: cic_ussd
|
||||
DATABASE_ENGINE: postgresql
|
||||
DATABASE_DRIVER: psycopg2
|
||||
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
|
||||
CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis}
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
command: "/root/start_tasker.sh -q cic-ussd"
|
||||
# cic-ussd-server:
|
||||
# # image: grassrootseconomics:cic-ussd
|
||||
# build:
|
||||
# context: apps/
|
||||
# dockerfile: cic-ussd/docker/Dockerfile
|
||||
# environment:
|
||||
# DATABASE_USER: grassroots
|
||||
# DATABASE_HOST: postgres
|
||||
# DATABASE_PORT: 5432
|
||||
# DATABASE_PASSWORD: tralala
|
||||
# DATABASE_NAME: cic_ussd
|
||||
# DATABASE_ENGINE: postgresql
|
||||
# DATABASE_DRIVER: psycopg2
|
||||
# SERVER_PORT: 80
|
||||
# ports:
|
||||
# - 80:8082
|
||||
# depends_on:
|
||||
# - postgres
|
||||
# - redis
|
||||
# deploy:
|
||||
# restart_policy:
|
||||
# condition: on-failure
|
||||
# command: "/root/start_uwsgi.sh"
|
||||
#
|
||||
# cic-ussd-tasker:
|
||||
# # image: grassrootseconomics:cic-ussd
|
||||
# build:
|
||||
# context: apps
|
||||
# dockerfile: cic-ussd/docker/Dockerfile
|
||||
# environment:
|
||||
# DATABASE_USER: grassroots
|
||||
# DATABASE_HOST: postgres
|
||||
# DATABASE_PORT: 5432
|
||||
# DATABASE_PASSWORD: tralala
|
||||
# DATABASE_NAME: cic_ussd
|
||||
# DATABASE_ENGINE: postgresql
|
||||
# DATABASE_DRIVER: psycopg2
|
||||
# CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
|
||||
# CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis}
|
||||
# depends_on:
|
||||
# - postgres
|
||||
# - redis
|
||||
# deploy:
|
||||
# restart_policy:
|
||||
# condition: on-failure
|
||||
# command: "/root/start_tasker.sh -q cic-ussd"
|
||||
|
||||
Reference in New Issue
Block a user