def update_address(public_key, last_block): account = session.query(EthereumAccount).filter( EthereumAccount.public_key == public_key).one() account.balance = web3.fromWei(web3.eth.getBalance(account.public_key), values.eth_base_unit) account.last_block = last_block session.commit()
def reset_data(): print('1GOT RESET REQUEST') session.query(Account).delete() print('2GOT RESET REQUEST') session.commit() print('3GOT RESET REQUEST') payment.create_user('hotwallet') print('4GOT RESET REQUEST') return ''
def create_address_ethereum(username): private_key = utils.sha3(os.urandom(4096)) raw_address = utils.privtoaddr(private_key) public_key = utils.checksum_encode(raw_address) new_account = EthereumAccount(public_key=public_key, private_key=private_key, balance=0, username=username) session.add(new_account) session.commit() print('created ethereum address')
def get_accounts(wallet): #load accounts from SQL and add those to the Node wallet accounts = session.query(NanoAccount).all() loaded_accounts = rpc.account_list(wallet) #print('loaded accounts', loaded_accounts) balances = rpc.wallet_balances(wallet) for account in accounts: if account.account_id not in loaded_accounts: rpc.wallet_add(wallet, account.private_key) print('Added to wallet:', account.private_key) session.commit() return accounts
def create_address_nano(username): keys = rpc.key_create() new_account = NanoAccount( public_key=keys['public'], private_key=keys['private'], account=keys['account'], balance=0, username=username, last_block=0, ) session.add(new_account) session.commit()
def initialize_account(account, wallet): if account.username != 'hotwallet': hotwallet_account = session.query(NanoAccount).filter(NanoAccount.username == 'hotwallet').one() rpc.send( wallet = wallet, source = hotwallet_account.account_id, destination = account.account_id, amount = 0, ) pending = rpc.accounts_pending([account.account_id], count = 10, threshold=0) #print('Pending:', pending) for account_id, blocks in pending.items(): for block in blocks: rpc.receive(wallet, account_id, block) account.last_block = rpc.account_info(account.account_id)['frontier'] session.commit() return
def update_account(account, wallet): if account.last_block == '0': #rpc.block_create('open', account=account.account_id, wallet=wallet) initialize_account(account, wallet) #print(account.last_block) latest_block = rpc.account_info(account.account_id)['frontier'] #print(account.account_id, rpc.account_info(account.account_id)) #print('latest_block', latest_block) if latest_block != account.last_block: blocks = get_blocks_between(account.last_block, latest_block) #print(blocks) for curr_block in blocks: #print(latest_block, curr_block) #print('block:', curr_block) #print(frontier) block = rpc.blocks_info([curr_block])[curr_block] #print(block) if block['contents']['type'] != 'receive': #print('type', block['type']) account.last_block = curr_block session.commit() continue if not block.get('amount', False): print('amount was 0 for block', curr_block) account.last_block = curr_block session.commit() continue print("RECEIVED") #print(curr_block, block) amount = convert(block['amount'], from_unit='raw', to_unit='xrb') add_balance(account.username, amount) account.balance = int(convert(rpc.account_balance(account.account_id)['balance'], from_unit='raw', to_unit='krai')) log(account, amount) send_to_hot_wallet(account, wallet) account.last_block = curr_block session.commit()