def cli_payout(chain_provider, chain_name, owner, contract_address, abi_path, db_file): """Payout pending tx's in the specified database.""" w3 = get_chain(chain_provider, chain_name) if not owner: owner = default_wallet_account(w3) if chain_name not in ['tester', 'testrpc']: unlock_wallet(w3, owner) instance = get_token_mintage_instance(w3, abi_path, contract_address) assert instance.address.lower() == contract_address.lower() q = """ SELECT id, recipient, amount, bucket FROM txs WHERE txid IS NULL AND success = 0; """ for payout in query_all(db_file, q): id_, recipient, amount, bucket = payout txid = mint_tokens( instance, owner, recipient, amount, bucket, ) update_txid(db_file, id_, txid) print(f'Minted {amount} tokens to {recipient}')
def list_article(): type_id = request.args.get('typeId') sql1 = "select * from t_article_type" results = db.query_all(sql1, ()) sql = "select art.*, type.type_name " \ "from t_article art, t_article_type type " \ "where art.type_id = type.type_id " if type_id: sql += 'and type.type_id=%s' articles = db.query_all(sql, (type_id) if type_id else ()) return render_template('list_article.html', types=results, articles=articles)
def get_articles(): page_no = int(request.args.get('pageNo')) sql = "select art.*, type.type_name " \ "from t_article art, t_article_type type " \ "where art.type_id = type.type_id " \ "limit %s,3" results = db.query_all(sql, (page_no * 3)) return jsonify(results)
def cli_export_txs(chain_name, db_file): """Export the database into a Google Sheet friendly csv.""" q = """ SELECT name, recipient, amount, bucket, txid, success FROM txs; """ click.echo('Name,Address,Amount,Category,Tx,Success') for name, recipient, amount, bucket, txid, success in query_all( db_file, q): subdomain = '' if chain_name == 'mainnet' else f'{chain_name}.' buckets_reverse = {v: k for k, v in buckets.items()} click.echo(f'{name},{recipient},{amount},{buckets_reverse[bucket]},' f'https://{subdomain}etherscan.io/tx/{txid},{success}')
def article(): article_id = request.args.get('articleId') sql1 = "select art.*, type.type_name " \ "from t_article art, t_article_type type " \ "where art.type_id = type.type_id and art.article_id=%s" sql2 = "select comm.*, usr.username,usr.portrait " \ "from t_comment comm, t_user usr " \ "where comm.user_id=usr.user_id and comm.article_id = %s" result = db.query(sql1, (article_id)) results = db.query_all(sql2, (article_id)) return render_template('article.html', comments=results, article=result)
def cli_verify(chain_provider, chain_name, db_file): """Verify paid tx's in the specified database.""" w3 = get_chain(chain_provider, chain_name) q = """ SELECT id, txid FROM txs WHERE success = 0 AND txid IS NOT NULL; """ for id_, txid in query_all(db_file, q): try: success = is_tx_successful(w3, txid) except: print(f'Unable to verify {txid}. Try again later.') continue if success: mark_tx_as_successful(db_file, id_) print(f'{txid} is OK.') else: reason = 'Out of Gas' if is_tx_out_of_gas(w3, txid) else 'Fail' if click.confirm(f'{txid} has failed ({reason}). Retry?'): mark_tx_for_retry(db_file, id_)
def get_user_deck(google_id): try: return to_json(query_all("""SELECT deck_id, json FROM UserDecks WHERE google_id""", google_id)) except: return '{"error":"not found"}'
def index(): sql = "select * from t_article_type" results = db.query_all(sql, ()) return render_template('index.html', types=results)
def mgr_articles(): sql = 'select art.*, type.type_name ' \ 'from t_article art, t_article_type type ' \ 'where art.type_id=type.type_id ' results = db.query_all(sql) return render_template('mgr_articles.html', articles=results)