init
This commit is contained in:
4
apps/contract-migration/dev/python/scripts/setup.py
Normal file
4
apps/contract-migration/dev/python/scripts/setup.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
)
|
||||
150
apps/contract-migration/dev/python/scripts/tx_driver.py
Normal file
150
apps/contract-migration/dev/python/scripts/tx_driver.py
Normal file
@@ -0,0 +1,150 @@
|
||||
# standard imports
|
||||
import os
|
||||
import logging
|
||||
import argparse
|
||||
import re
|
||||
import json
|
||||
import signal
|
||||
import random
|
||||
import time
|
||||
|
||||
# third-party imports
|
||||
import confini
|
||||
import web3
|
||||
from cic_registry.chain import ChainSpec
|
||||
from cic_registry.chain import ChainRegistry
|
||||
from cic_registry import CICRegistry
|
||||
from eth_token_index import TokenUniqueSymbolIndex as TokenIndex
|
||||
from eth_accounts_index import AccountRegistry
|
||||
|
||||
from cic_eth.api import Api
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
logging.getLogger('websockets.protocol').setLevel(logging.CRITICAL)
|
||||
logging.getLogger('web3.RequestManager').setLevel(logging.CRITICAL)
|
||||
logging.getLogger('web3.providers.WebsocketProvider').setLevel(logging.CRITICAL)
|
||||
logging.getLogger('web3.providers.HTTPProvider').setLevel(logging.CRITICAL)
|
||||
|
||||
default_data_dir = '/usr/local/share/cic/solidity/abi'
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-c', type=str, default='./config', help='config file')
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, help='chain spec')
|
||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
||||
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=default_data_dir, help='Directory containing bytecode and abi (default: {})'.format(default_data_dir))
|
||||
argparser.add_argument('-v', action='store_true', help='be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='be more verbose')
|
||||
argparser.add_argument('--wait-max', dest='wait_max', default=2.0, type=float, help='maximum time in decimal seconds to wait between transactions')
|
||||
argparser.add_argument('--account-index-address', dest='account_index', type=str, help='Contract address of accounts index')
|
||||
argparser.add_argument('--token-index-address', dest='token_index', type=str, help='Contract address of token index')
|
||||
argparser.add_argument('--approval-escrow-address', dest='approval_escrow', type=str, help='Contract address for transfer approvals')
|
||||
argparser.add_argument('--declarator-address', dest='declarator', type=str, help='Address of declarations contract to perform lookup against')
|
||||
argparser.add_argument('-a', '--accounts-index-writer', dest='a', type=str, help='Address of account with access to add to accounts index')
|
||||
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.vv:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
elif args.v:
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
config = confini.Config(args.c, args.env_prefix)
|
||||
config.process()
|
||||
args_override = {
|
||||
'ETH_ABI_DIR': getattr(args, 'abi_dir'),
|
||||
'CIC_CHAIN_SPEC': getattr(args, 'i'),
|
||||
'DEV_ETH_ACCOUNTS_INDEX_ADDRESS': getattr(args, 'account_index'),
|
||||
'DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER': getattr(args, 'a'),
|
||||
'DEV_ETH_ERC20_APPROVAL_ESCROW_ADDRESS': getattr(args, 'approval_escrow'),
|
||||
'DEV_ETH_TOKEN_INDEX_ADDRESS': getattr(args, 'token_index'),
|
||||
}
|
||||
config.dict_override(args_override, 'cli flag')
|
||||
config.validate()
|
||||
config.censor('PASSWORD', 'DATABASE')
|
||||
config.censor('PASSWORD', 'SSL')
|
||||
logg.debug('config:\n{}'.format(config))
|
||||
|
||||
re_websocket = r'^wss?:'
|
||||
re_http = r'^https?:'
|
||||
blockchain_provider = None
|
||||
if re.match(re_websocket, config.get('ETH_PROVIDER')):
|
||||
blockchain_provider = web3.Web3.WebsocketProvider(config.get('ETH_PROVIDER'))
|
||||
elif re.match(re_http, config.get('ETH_PROVIDER')):
|
||||
blockchain_provider = web3.Web3.HTTPProvider(config.get('ETH_PROVIDER'))
|
||||
w3 = web3.Web3(blockchain_provider)
|
||||
|
||||
|
||||
chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
|
||||
CICRegistry.init(w3, config.get('CIC_REGISTRY_ADDRESS'), chain_spec)
|
||||
CICRegistry.add_path(config.get('ETH_ABI_DIR'))
|
||||
|
||||
chain_registry = ChainRegistry(chain_spec)
|
||||
CICRegistry.add_chain_registry(chain_registry, True)
|
||||
|
||||
run = True
|
||||
|
||||
def inthandler(name, frame):
|
||||
logg.warning('got {}, stopping'.format(name))
|
||||
global run
|
||||
run = False
|
||||
|
||||
signal.signal(signal.SIGTERM, inthandler)
|
||||
signal.signal(signal.SIGINT, inthandler)
|
||||
|
||||
api = Api(str(chain_spec))
|
||||
|
||||
f = open(os.path.join(config.get('ETH_ABI_DIR'), 'ERC20.json'))
|
||||
erc20_abi = json.load(f)
|
||||
f.close()
|
||||
|
||||
def get_tokens():
|
||||
tokens = []
|
||||
token_index = TokenIndex(w3, config.get('CIC_TOKEN_INDEX_ADDRESS'))
|
||||
token_count = token_index.count()
|
||||
for i in range(token_count):
|
||||
tokens.append(token_index.get_index(i))
|
||||
logg.debug('tokens {}'.format(tokens))
|
||||
return tokens
|
||||
|
||||
def get_addresses():
|
||||
address_index = AccountRegistry(w3, config.get('CIC_ACCOUNTS_INDEX_ADDRESS'))
|
||||
address_count = address_index.count()
|
||||
addresses = address_index.last(address_count-1)
|
||||
logg.debug('addresses {} {}'.format(address_count, addresses))
|
||||
return addresses
|
||||
|
||||
random.seed()
|
||||
|
||||
while run:
|
||||
n = random.randint(0, 255)
|
||||
|
||||
# some of the time do other things than transfers
|
||||
if n & 0xf8 == 0xf8:
|
||||
t = api.create_account()
|
||||
logg.info('create account {}'.format(t))
|
||||
|
||||
else:
|
||||
tokens = get_tokens()
|
||||
addresses = get_addresses()
|
||||
address_pair = random.choices(addresses, k=2)
|
||||
sender = address_pair[0]
|
||||
recipient = address_pair[1]
|
||||
token = random.choice(tokens)
|
||||
|
||||
c = w3.eth.contract(abi=erc20_abi, address=token)
|
||||
sender_balance = c.functions.balanceOf(sender).call()
|
||||
token_symbol = c.functions.symbol().call()
|
||||
amount = int(random.random() * (sender_balance / 2))
|
||||
|
||||
n = random.randint(0, 255)
|
||||
|
||||
if n & 0xc0 == 0xc0:
|
||||
t = api.transfer_request(sender, recipient, config.get('CIC_APPROVAL_ESCROW_ADDRESS'), amount, token_symbol)
|
||||
logg.info('transfer REQUEST {} {} from {} to {} => {}'.format(amount, token_symbol, sender, recipient, t))
|
||||
else:
|
||||
t = api.transfer(sender, recipient, amount, token_symbol)
|
||||
logg.info('transfer {} {} from {} to {} => {}'.format(amount, token_symbol, sender, recipient, t))
|
||||
|
||||
time.sleep(random.random() * args.wait_max)
|
||||
51
apps/contract-migration/dev/python/scripts/tx_seed.py
Normal file
51
apps/contract-migration/dev/python/scripts/tx_seed.py
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import csv
|
||||
import logging
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
|
||||
import web3
|
||||
import confini
|
||||
|
||||
from cic_registry import CICRegistry
|
||||
from cic_eth.api import Api
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logg = logging.getLogger()
|
||||
|
||||
confini_default_dir = os.environ.get('CONFINI_DIR', '/usr/local/etc/cic')
|
||||
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-c', type=str, default=confini_default_dir, help='config data dir')
|
||||
argparser.add_argument('-a', '--token-gifter-address', dest='a', type=str, help='Token gifter address')
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, help='chain spec')
|
||||
argparser.add_argument('-s', '--token-symbol', dest='s', type=str, help='Token symbol')
|
||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
||||
argparser.add_argument('-v', action='store_true', help='be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='be more verbose')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.vv:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
elif args.v:
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
config = confini.Config(args.c, args.env_prefix)
|
||||
config.process()
|
||||
args_override = {
|
||||
'CIC_CHAIN_SPEC': getattr(args, 'i'),
|
||||
}
|
||||
cic_eth_api = Api(config.get('CIC_CHAIN_SPEC'))
|
||||
|
||||
token_gifter_address = args.a
|
||||
|
||||
if __name__ == '__main__':
|
||||
f = open('./data/amounts', 'r')
|
||||
cr = csv.reader(f)
|
||||
for r in cr:
|
||||
logg.info('sending {} {} from {} to {}'.format(r[1], args.s, token_gifter_address, r[0]))
|
||||
cic_eth_api.transfer(token_gifter_address, r[0], int(r[1]), args.s)
|
||||
f.close()
|
||||
212
apps/contract-migration/dev/python/scripts/users.py
Normal file
212
apps/contract-migration/dev/python/scripts/users.py
Normal file
@@ -0,0 +1,212 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
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'])
|
||||
|
||||
#f = open('cic.conf', 'r')
|
||||
#config = json.load(f)
|
||||
#f.close()
|
||||
#
|
||||
|
||||
config_dir = os.environ.get('CONFINI_DIR', '/usr/local/etc/cic')
|
||||
|
||||
config = confini.Config(config_dir, os.environ.get('CONFINI_ENV_PREFIX'))
|
||||
config.process()
|
||||
logg.info('loaded config\n{}'.format(config))
|
||||
|
||||
|
||||
w3s = None
|
||||
w3s = web3.Web3(web3.Web3.IPCProvider(config.get('SIGNER_SOCKET_PATH')))
|
||||
#w3s = web3.Web3(web3.Web3.IPCProvider(config['signer']['provider']))
|
||||
#w3 = web3.Web3(web3.Web3.WebsocketProvider(config['eth']['provider']))
|
||||
|
||||
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_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
|
||||
|
||||
|
||||
if __name__ == '__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(10):
|
||||
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()
|
||||
40
apps/contract-migration/dev/python/setup.cfg
Normal file
40
apps/contract-migration/dev/python/setup.cfg
Normal file
@@ -0,0 +1,40 @@
|
||||
[metadata]
|
||||
name = cic-dev-fake
|
||||
version = 0.0.1
|
||||
description = Fake data generator tools
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
url = https://gitlab.com/nolash/simple-multisig
|
||||
keywords =
|
||||
ethereum
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
Operating System :: OS Independent
|
||||
Development Status :: 3 - Alpha
|
||||
Environment :: No Input/Output (Daemon)
|
||||
Intended Audience :: Developers
|
||||
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
||||
Topic :: Internet
|
||||
#Topic :: Blockchain :: EVM
|
||||
license = GPL3
|
||||
licence_files =
|
||||
LICENSE
|
||||
|
||||
[options]
|
||||
python_requires = >= 3.6
|
||||
install_requires =
|
||||
web3==5.12.2
|
||||
vobject==0.9.6.1
|
||||
faker==4.17.1
|
||||
tests_require =
|
||||
eth-tester==0.5.0b2
|
||||
py-evm==0.3.0a20
|
||||
scripts =
|
||||
scripts/users.py
|
||||
scripts/tx_generator.py
|
||||
scripts/tx_seed.py
|
||||
|
||||
[options.extras_require]
|
||||
testing =
|
||||
eth-tester==0.5.0b2
|
||||
py-evm==0.3.0a20
|
||||
4
apps/contract-migration/dev/python/setup.py
Normal file
4
apps/contract-migration/dev/python/setup.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
)
|
||||
Reference in New Issue
Block a user