Remove redundant dev folder

This commit is contained in:
nolash 2021-02-12 17:40:51 +01:00
parent d042ce0dcd
commit 1e148d28c0
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
20 changed files with 0 additions and 1176 deletions

View File

@ -1,58 +0,0 @@
#!python3
"""Gas transfer script
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# standard imports
import os
import json
import argparse
import logging
# third-party imports
import web3
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
logging.getLogger('web3').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
default_abi_dir = os.environ.get('ETH_ABI_DIR', '/usr/share/local/cic/solidity/abi')
default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545')
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default=default_eth_provider, type=str, help='Web3 provider url (http only)')
argparser.add_argument('-t', '--token-address', dest='t', type=str, help='Token address. If not set, will return gas balance')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=default_abi_dir, help='Directory containing bytecode and abi (default {})'.format(default_abi_dir))
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('account', type=str, help='Account address')
args = argparser.parse_args()
if args.v:
logg.setLevel(logging.DEBUG)
def main():
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
balance = None
if args.t != None:
f = open(os.path.join(args.abi_dir, 'ERC20.json'))
abi = json.load(f)
f.close()
c = w3.eth.contract(abi=abi, address=args.t)
balance = c.functions.balanceOf(args.account).call()
else:
balance =w3.eth.getBalance(args.account)
print(balance)
if __name__ == '__main__':
main()

View File

@ -1,47 +0,0 @@
#!/usr/bin/python
import sys
import os
import logging
import celery
from cic_eth.api import Api
import confini
import argparse
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger('create_account_script')
logging.getLogger('confini').setLevel(logging.WARNING)
logging.getLogger('gnupg').setLevel(logging.WARNING)
config_dir = os.environ.get('CONFINI_DIR', '/usr/local/etc/cic')
argparser = argparse.ArgumentParser()
argparser.add_argument('--no-register', dest='no_register', action='store_true', help='Do not register new account in on-chain accounts index')
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:
logg.setLevel(logging.DEBUG)
if args.v:
logg.setLevel(logging.INFO)
config = confini.Config(config_dir, os.environ.get('CONFINI_ENV_PREFIX'))
config.process()
celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'))
api = Api(config.get('CIC_CHAIN_SPEC'))
registration_account = None
#t = api.create_account(registration_account=registration_account)
if len(sys.argv) > 1:
registration_account = config.get('DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER', None)
logg.debug('accounts index writer NOT USED {}'.format(registration_account))
register = not args.no_register
logg.debug('register {}'.format(register))
t = api.create_account(register=register)
print(t.get())

View File

@ -1,48 +0,0 @@
#!python3
"""Decode raw transaction
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# standard imports
import os
import json
import argparse
import logging
# third-party imports
from cic_eth.eth.util import unpack_signed_raw_tx
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
default_abi_dir = os.environ.get('ETH_ABI_DIR', '/usr/share/local/cic/solidity/abi')
default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545')
argparser = argparse.ArgumentParser()
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-i', '--chain-id', dest='i', type=int, help='Numeric network id')
argparser.add_argument('tx', type=str, help='hex-encoded signed raw transaction')
args = argparser.parse_args()
if args.v:
logg.setLevel(logging.DEBUG)
def main():
tx_raw = args.tx
if tx_raw[:2] == '0x':
tx_raw = tx_raw[2:]
tx_raw_bytes = bytes.fromhex(tx_raw)
tx = unpack_signed_raw_tx(tx_raw_bytes, args.i)
for k in tx.keys():
print('{}: {}'.format(k, tx[k]))
if __name__ == '__main__':
main()

View File

@ -1,24 +0,0 @@
#!/bin/bash
cic_data_dir=${CIC_DATA_DIR:-/tmp/cic}
t=${1:-$(mktemp)}
prefix=''
if [ ! -z $2 ]; then
prefix="${2}_"
fi
echo "#!/bin/bash" > $t
echo "set +a" >> $t
cat $cic_data_dir/.env | sed -e "s/^\([A-Z]\)/export ${prefix}\1/g" >> $t
#if [ -f $cic_data_dir/.env ]; then
#cat $cic_data_dir/.env | sed -e "s/^\([A-Z]\)/export ${prefix}\1/g" >> $t
#fi
echo "export CONFINI_DIR=$(dirname $(realpath .))/config_template" >> $t
source $t
echo "export CELERY_BROKER_URL=redis://localhost:${HTTP_PORT_REDIS}" >> $t
echo "export CELERY_RESULT_URL=redis://localhost:${HTTP_PORT_REDIS}" >> $t
echo "export ETH_PROVIDER=http://localhost:${HTTP_PORT_ETH}" >> $t
echo "export META_PROVIDER=http://localhost:${HTTP_PORT_CIC_META}" >> $t
echo "set -a" >> $t
echo $t

View File

@ -1,105 +0,0 @@
#!python3
"""Gas transfer script
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# standard imports
import os
import json
import argparse
import logging
# third-party imports
import web3
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
from crypto_dev_signer.keystore import DictKeystore
from crypto_dev_signer.eth.helper import EthTxExecutor
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
logging.getLogger('web3').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
default_abi_dir = '/usr/share/local/cic/solidity/abi'
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Signing address')
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
argparser.add_argument('recipient', type=str, help='Ethereum address of recipient')
argparser.add_argument('amount', type=int, help='Amount of tokens to mint and gift')
args = argparser.parse_args()
if args.vv:
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
block_last = args.w
block_all = args.ww
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
signer_address = keystore.import_keystore_file(args.y)
logg.debug('now have key for signer address {}'.format(signer_address))
signer = EIP155Signer(keystore)
chain_pair = args.i.split(':')
chain_id = int(chain_pair[1])
helper = EthTxExecutor(
w3,
signer_address,
signer,
chain_id,
block=args.ww,
)
def build_gas_transaction(recipient, value):
def builder(tx):
tx['to'] = recipient
tx['value'] = value
tx['data'] = '0x'
return tx
return builder
def main():
recipient = args.recipient
value = args.amount
logg.debug('sender {} balance before: {}'.format(signer_address, w3.eth.getBalance(signer_address)))
logg.debug('recipient {} balance before: {}'.format(recipient, w3.eth.getBalance(recipient)))
(tx_hash, rcpt) = helper.sign_and_send(
[
build_gas_transaction(recipient, value),
],
)
logg.debug('sender {} balance after: {}'.format(signer_address, w3.eth.getBalance(signer_address)))
logg.debug('recipient {} balance after: {}'.format(recipient, w3.eth.getBalance(recipient)))
if block_last:
helper.wait_for()
print(tx_hash)
if __name__ == '__main__':
main()

View File

@ -1,101 +0,0 @@
const fs = require('fs');
const path = require('path');
const cic = require('cic-client-meta');
const http = require('http');
const confini = require('confini');
console.debug('sorry this script doesnt read cli flags, set all in env vars');
let config_data_dir = process.env.CONFINI_DIR;
if (config_data_dir === undefined) {
config_data_dir = '/usr/local/etc/cic';
}
const config = new confini.Config(config_data_dir, process.env.CONFINI_ENV_PREFIX);
config.process();
Object.keys(config.store).forEach((k) => {
console.debug(k, config.get(k));
});
// flatten file list from directories recursively
// cheekily though gratefully stolen from https://coderrocketfuel.com/article/recursively-list-all-the-files-in-a-directory-using-node-js
const getAllFiles = function(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function(file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
} else {
arrayOfFiles.push(path.join(dirPath, "/", file))
}
})
return arrayOfFiles
}
async function sendit(uid, envelope) {
const d = envelope.toJSON();
const opts = {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Content-Length': d.length,
'X-CIC-AUTOMERGE': 'client',
},
};
let url = config.get('META_PROVIDER'); //['archiveUrl'];
url = url.replace(new RegExp('^(.+://[^/]+)/*$'), '$1/');
const req = http.request(url + uid, opts, (res) => {
res.on('data', process.stdout.write);
res.on('end', () => {
console.log('result', res.statusCode, res.headers);
});
});
req.write(d);
req.end();
}
function doit(keystore) {
dataDir = 'data';
if (process.argv.length > 2) {
dataDir = process.argv[2];
}
console.log('argv', process.argv);
console.log('datadir', path.join(dataDir, 'person'));
getAllFiles(path.join(dataDir, 'person')).forEach((filename) => {
console.debug('person file', filename);
const signer = new cic.PGPSigner(keystore);
const parts = filename.split('.');
const uid = path.basename(parts[0]);
const d = fs.readFileSync(filename, 'utf-8');
const o = JSON.parse(d);
const s = new cic.Syncable(uid, o);
console.log(s);
s.setSigner(signer);
s.onwrap = (env) => {
console.log('env', env);
//console.log('sign', s.m.signature.digest);
sendit(uid, env);
};
s.sign();
});
}
pk = fs.readFileSync(path.join(config.get('PGP_EXPORTS_DIR'), config.get('PGP_PRIVATEKEY_FILE')));
pubk = fs.readFileSync(path.join(config.get('PGP_EXPORTS_DIR'), config.get('DEV_PGP_PUBLICKEYS_ACTIVE_FILE')));
new cic.PGPKeyStore(
process.env['PGP_PASSPHRASE'],
pk,
pubk,
undefined,
undefined,
doit,
);

View File

@ -1,26 +0,0 @@
#!/bin/bash
mkdir -vp .tmp
echo -n '' > .tmp/.env_accounts
account_labels=(
DEV_ETH_ACCOUNT_BANCOR_DEPLOYER
DEV_ETH_ACCOUNT_GAS_PROVIDER
DEV_ETH_ACCOUNT_RESERVE_OWNER
DEV_ETH_ACCOUNT_RESERVE_MINTER
DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_OWNER
DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER
DEV_ETH_ACCOUNT_SARAFU_OWNER
DEV_ETH_ACCOUNT_SARAFU_GIFTER
DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER
DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER
)
bip39gen -n ${#account_labels[@]} "$DEV_MNEMONIC"
i=0
for a in `bip39gen -n ${#account_labels[@]} "$DEV_MNEMONIC" | jq -r .address[]`; do
exportline=${account_labels[$i]}=$a
export $exportline
echo $exportline >> .tmp/.env_accounts
echo exportline $exportline
i=$(($i+1))
done

View File

@ -1,4 +0,0 @@
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && source "$NVM_DIR/bash_completion"

View File

@ -1,4 +0,0 @@
from setuptools import setup
setup(
)

View File

@ -1,150 +0,0 @@
# 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)

View File

@ -1,51 +0,0 @@
#!/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()

View File

@ -1,212 +0,0 @@
#!/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()

View File

@ -1,40 +0,0 @@
[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

View File

@ -1,4 +0,0 @@
from setuptools import setup
setup(
)

View File

@ -1,10 +0,0 @@
cryptocurrency-cli-tools~=0.0.4
giftable-erc20-token~=0.0.7b1
eth-accounts-index~=0.0.10a2
erc20-single-shot-faucet~=0.2.0a1
erc20-approval-escrow~=0.3.0a1
cic-eth==0.10.0a5
vobject==0.9.6.1
faker==4.17.1
eth-address-index~=0.1.0a1
crypto-dev-signer~=0.4.13b9

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -1,138 +0,0 @@
#!/bin/bash
# Debug flag
#debug='-v'
keystore_file=../keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c
debug=''
abi_dir=${ETH_ABI_DIR:-/usr/local/share/cic/solidity/abi}
# Determine token amount
token_amount=${DEV_ETH_RESERVE_AMOUNT:0:-1}
# Determine gas amount
#gas_amount=20000000000000000000
gas_amount=2000000000000000000
export DATABASE_NAME=$DATABASE_NAME_CIC_ETH
export DATABASE_PORT=$HTTP_PORT_POSTGRES
export DATABASE_HOST=localhost
set -e
set -a
old_gas_provider=$DEV_ETH_ACCOUNT_GAS_PROVIDER
DEV_ETH_ACCOUNT_GAS_GIFTER=`python ./create.py --no-register`
echo DEV_ETH_ACCOUNT_GAS_GIFTER=$DEV_ETH_ACCOUNT_GAS_GIFTER
export DEV_ETH_ACCOUNT_GAS_GIFTER=$DEV_ETH_ACCOUNT_GAS_GIFTER
cic-eth-tag GAS_GIFTER $DEV_ETH_ACCOUNT_GAS_GIFTER
DEV_ETH_ACCOUNT_SARAFU_GIFTER=`python ./create.py --no-register`
echo DEV_ETH_ACCOUNT_SARAFU_GIFTER=$DEV_ETH_ACCOUNT_SARAFU_GIFTER
export DEV_ETH_ACCOUNT_SARAFU_GIFTER=$DEV_ETH_ACCOUNT_SARAFU_GIFTER
cic-eth-tag SARAFU_GIFTER $DEV_ETH_ACCOUNT_SARAFU_GIFTER
DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER=`python ./create.py --no-register`
echo DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER=$DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER
export DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER=$DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER
cic-eth-tag TRANSFER_APPROVAL_OWNER $DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER
DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER=`python ./create.py --no-register`
echo DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER=$DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER
export DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER=$DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER
cic-eth-tag FAUCET_OWNER $DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER
DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=`python ./create.py --no-register`
echo DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=$DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER
export DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=$DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER
cic-eth-tag ACCOUNTS_INDEX_WRITER $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER
# Transfer gas to custodial gas provider adddress
#echo $old_gas_provider
>&2 echo gift gas to gas gifter
>&2 echo "python gas.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_GAS_GIFTER $gas_amount"
>&2 python gas.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_GAS_GIFTER $gas_amount
>&2 echo gift gas to sarafu token owner
>&2 echo "python gas.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_SARAFU_OWNER $gas_amount"
>&2 python gas.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_SARAFU_OWNER $gas_amount
>&2 echo gift gas to account index owner
>&2 echo "python gas.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_OWNER $gas_amount"
>&2 python gas.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_OWNER $gas_amount
# Send reserve to token creator
>&2 giftable-token-gift -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -a $DEV_ETH_RESERVE_ADDRESS --recipient $DEV_ETH_ACCOUNT_SARAFU_OWNER -w $debug $token_amount
# Create token
#DEV_ETH_SARAFU_TOKEN_ADDRESS=`cic-bancor-token -p $ETH_PROVIDER -r $CIC_REGISTRY_ADDRESS -z $DEV_ETH_RESERVE_ADDRESS -o $DEV_ETH_ACCOUNT_SARAFU_OWNER -n $DEV_ETH_SARAFU_TOKEN_NAME -s $DEV_ETH_SARAFU_TOKEN_SYMBOL -d $DEV_ETH_SARAFU_TOKEN_DECIMALS -i $CIC_CHAIN_SPEC $debug $token_amount`
DEV_ETH_SARAFU_TOKEN_ADDRESS=$DEV_ETH_RESERVE_ADDRESS
echo DEV_ETH_SARAFU_TOKEN_ADDRESS=$DEV_ETH_SARAFU_TOKEN_ADDRESS
export DEV_ETH_SARAFU_TOKEN_ADDRESS=$DEV_ETH_SARAFU_TOKEN_ADDRESS
# Transfer tokens to gifter address
>&2 python transfer.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --token-address $DEV_ETH_SARAFU_TOKEN_ADDRESS --abi-dir $abi_dir -w $debug $DEV_ETH_ACCOUNT_SARAFU_GIFTER ${token_amount:0:-1}
# Deploy transfer approval contract
CIC_APPROVAL_ESCROW_ADDRESS=`erc20-approval-escrow-deploy -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --approver $DEV_ETH_ACCOUNT_APPROVAL_ESCROW_OWNER -w $debug`
echo CIC_APPROVAL_ESCROW_ADDRESS=$CIC_APPROVAL_ESCROW_ADDRESS
export CIC_APPROVAL_ESCROW_ADDRESS=$CIC_APPROVAL_ESCROW_ADDRESS
# Register transfer approval contract
>&2 cic-registry-set -y $keystore_file -r $CIC_REGISTRY_ADDRESS -k TransferApproval -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $CIC_APPROVAL_ESCROW_ADDRESS
# Deploy one-time token faucet for newly created token
DEV_ETH_SARAFU_FAUCET_ADDRESS=`erc20-single-shot-faucet-deploy -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --token-address $DEV_ETH_SARAFU_TOKEN_ADDRESS --editor $DEV_ETH_ACCOUNT_SINGLE_SHOT_FAUCET_OWNER --set-amount 1048576 -w $debug`
echo DEV_ETH_SARAFU_FAUCET_ADDRESS=$DEV_ETH_SARAFU_FAUCET_ADDRESS
export DEV_ETH_SARAFU_FAUCET_ADDRESS=$DEV_ETH_SARAFU_FAUCET_ADDRESS
# Transfer tokens to faucet contract
>&2 python transfer.py -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --token-address $DEV_ETH_SARAFU_TOKEN_ADDRESS --abi-dir $abi_dir -w $debug $DEV_ETH_SARAFU_FAUCET_ADDRESS ${token_amount:0:-1}
# Registry faucet entry
>&2 cic-registry-set -y $keystore_file -r $CIC_REGISTRY_ADDRESS -k Faucet -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $DEV_ETH_SARAFU_FAUCET_ADDRESS
# Deploy token endorser registry
#DEV_ETH_TOKEN_ENDORSER_ADDRESS=`eth-token-endorser-deploy -p $ETH_PROVIDER -o $DEV_ETH_ACCOUNT_SARAFU_OWNER $debug`
#echo DEV_ETH_TOKEN_ENDORSER_ADDRESS=$DEV_ETH_TOKEN_ENDORSER_ADDRESS
#export DEV_ETH_TOKEN_ENDORSER_ADDRESS=$DEV_ETH_TOKEN_ENDORSER_ADDRESS
#ENDORSEMENT_MSG=`echo -n 'very cool token' | sha256sum | awk '{print $1;}'`
#>&2 eth-token-endorser-add -p $ETH_PROVIDER -a $DEV_ETH_TOKEN_ENDORSER_ADDRESS -t $DEV_ETH_SARAFU_TOKEN_ADDRESS -o $DEV_ETH_ACCOUNT_SARAFU_OWNER $debug $ENDORSEMENT_MSG
CIC_TOKEN_INDEX_ADDRESS=`eth-token-index-deploy -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug`
echo CIC_TOKEN_INDEX_ADDRESS=$CIC_TOKEN_INDEX_ADDRESS
export CIC_TOKEN_INDEX_ADDRESS=$CIC_TOKEN_INDEX_ADDRESS
>&2 eth-token-index-add -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -r $CIC_TOKEN_INDEX_ADDRESS -w $debug $DEV_ETH_SARAFU_TOKEN_ADDRESS
# Register token registry
>&2 cic-registry-set -y $keystore_file -r $CIC_REGISTRY_ADDRESS -k TokenRegistry -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER $CIC_TOKEN_INDEX_ADDRESS
# Deploy address declarator registry
declarator_description=0x546869732069732074686520434943206e6574776f726b000000000000000000
CIC_DECLARATOR_ADDRESS=`eth-address-declarator-deploy -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w $debug $declarator_description`
echo CIC_DECLARATOR_ADDRESS=$CIC_DECLARATOR_ADDRESS
export CIC_DECLARATOR_ADDRESS=$CIC_DECLARATOR_ADDRESS
token_description_one=`sha256sum sarafu_declaration.json | awk '{ print $1; }'`
token_description_two=0x54686973206973207468652053617261667520746f6b656e0000000000000000
>&2 eth-address-declarator-add -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -r $CIC_DECLARATOR_ADDRESS -w $debug $DEV_ETH_SARAFU_TOKEN_ADDRESS $token_description_one
>&2 eth-address-declarator-add -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -r $CIC_DECLARATOR_ADDRESS -w $debug $DEV_ETH_SARAFU_TOKEN_ADDRESS $token_description_two
# Register address declarator
>&2 cic-registry-set -y $keystore_file -r $CIC_REGISTRY_ADDRESS -k AddressDeclarator -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER $CIC_DECLARATOR_ADDRESS
# We're done with the registry at this point, seal it off
>&2 cic-registry-seal -y $keystore_file -i $CIC_CHAIN_SPEC -r $CIC_REGISTRY_ADDRESS -p $ETH_PROVIDER
# Add accounts index writer with key from keystore
>&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
set +a
set +e

View File

@ -1,31 +0,0 @@
#!python3
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
# SPDX-License-Identifier: GPL-3.0-or-later
# File-version: 1
# Description: Smoke test for cic-eth create account api
# standard imports
import os
import logging
# third-party imports
import celery
import confini
# platform imports
from cic_eth import Api
script_dir = os.path.dirname(__file__)
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
config_dir = os.environ.get('CONFINI_DIR', '/usr/local/etc/cic/')
config = confini.Config(config_dir)
config.process()
a = Api()
t = a.create_account()
logg.debug('create account task uuid {}'.format(t))

View File

@ -1,105 +0,0 @@
#!python3
"""Token transfer script
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# standard imports
import os
import json
import argparse
import logging
# third-party imports
import web3
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
from crypto_dev_signer.keystore import DictKeystore
from crypto_dev_signer.eth.helper import EthTxExecutor
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
logging.getLogger('web3').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
default_abi_dir = '/usr/share/local/cic/solidity/abi'
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
argparser.add_argument('--token-address', required='True', dest='t', type=str, help='Token address')
argparser.add_argument('-a', '--sender-address', dest='s', type=str, help='Sender account address')
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=default_abi_dir, help='Directory containing bytecode and abi (default {})'.format(default_abi_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('recipient', type=str, help='Recipient account address')
argparser.add_argument('amount', type=int, help='Amount of tokens to mint and gift')
args = argparser.parse_args()
if args.vv:
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
block_last = args.w
block_all = args.ww
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
signer_address = keystore.import_keystore_file(args.y)
logg.debug('now have key for signer address {}'.format(signer_address))
signer = EIP155Signer(keystore)
chain_pair = args.i.split(':')
chain_id = int(chain_pair[1])
helper = EthTxExecutor(
w3,
signer_address,
signer,
chain_id,
block=args.ww,
)
def main():
# TODO: Add pure ERC20 abi to collection
f = open(os.path.join(args.abi_dir, 'ERC20.json'), 'r')
abi = json.load(f)
f.close()
c = w3.eth.contract(abi=abi, address=args.t)
recipient = args.recipient
value = args.amount
logg.debug('sender {} balance before: {}'.format(signer_address, c.functions.balanceOf(signer_address).call()))
logg.debug('recipient {} balance before: {}'.format(recipient, c.functions.balanceOf(recipient).call()))
(tx_hash, rcpt) = helper.sign_and_send(
[
c.functions.transfer(recipient, value).buildTransaction,
],
)
logg.debug('sender {} balance after: {}'.format(signer_address, c.functions.balanceOf(signer_address).call()))
logg.debug('recipient {} balance after: {}'.format(recipient, c.functions.balanceOf(recipient).call()))
if block_last:
helper.wait_for()
print(tx_hash)
if __name__ == '__main__':
main()