コード例 #1
0
ファイル: wallet.py プロジェクト: zhanjiahuan/digrccy
 def get_account_ram_cup_net(self, account_name, user_digiccy_secret):
     creator = consul_clinet.get_digiccy_base_account(COIN_NAME,
                                                      is_seed=False)
     creator_privkey = consul_clinet.get_digiccy_base_privatekey(COIN_NAME)
     creator_privkey = eval(decryptSeed(creator_privkey)).get("seed")
     try:
         url = f"https://api.eospark.com/api?module=account&action=get_account_resource_info" \
             f"&apikey=a9564ebc3289b7a14551baf8ad5ec60a&account={account_name}"
         ret = requests.get(url)
         data_obj = ret.text
         data_json = json.loads(data_obj)
         data = data_json.get("data")
         ram = data.get("ram").get("available")
         cpu = data.get("cpu").get("available")
         net = data.get("net").get("available")
         if ram < 3000:
             self.system_buy_ram(creator=creator,
                                 creator_privkey=creator_privkey,
                                 acct_name=account_name)
             self.payment(user_digiccy_secret, account_name, creator, 0.1)
         elif cpu < 2000 or net < 3000:
             self.system_buy_cpu_net(creator=creator,
                                     creator_privkey=creator_privkey,
                                     acct_name=account_name)
             self.payment(user_digiccy_secret, account_name, creator, 0.03)
         elif ram == 0 and cpu == 0 and net == 0:
             logging.error("error for get account ram,cup,net")
         print(f"RAM可用:{ram},CPU可用:{cpu},NET口可用:{net}")
         return ram, cpu, net
     except:
         logging.error("error for get account ram,cup,net")
コード例 #2
0
ファイル: wallet.py プロジェクト: zhanjiahuan/digrccy
 def create_account(self):
     try:
         creator_privkey = consul_clinet.get_digiccy_base_privatekey(
             COIN_NAME)
         creator = consul_clinet.get_digiccy_base_account(COIN_NAME,
                                                          is_seed=False)
         creator_privkey = eval(decryptSeed(creator_privkey)).get("seed")
         # 创建账号名
         acct_name = self.randomString(12)
         eosKey = EOSKey()
         privKey = eosKey.to_wif()
         owner_key = str(eosKey)
         # 创建账号
         self.ce.create_account(creator,
                                creator_privkey,
                                acct_name,
                                owner_key,
                                active_key='',
                                stake_net='0.0500 EOS',
                                stake_cpu='0.1500 EOS',
                                ramkb=2,
                                permission='active',
                                transfer=False,
                                broadcast=True,
                                timeout=30)
         print("私钥:", privKey, "用户:", acct_name)
         return privKey, acct_name
     except Exception as e:
         logging.error("error for create account")
         print(str(e))
         return '', e
コード例 #3
0
 def get(self):
     parser_ = CoverRequestParser()
     parser_.add_argument("chain_type", type=int, required=True)
     parser_.add_argument("coin_name", type=str, required=True)
     params = parser_.parse_args()
     chain_type = params['chain_type']
     coin_name = params.get('coin_name')
     base_balance = None
     try:
         coin_types = get_coin_types()
     except Exception as e:
         logging.error('find coin_types error:{}'.format(e))
         return create_response(CodeMsg.CM(1030, '获取币种失败'))
     if coin_name not in coin_types:
         return create_response(CodeMsg.CM(1031, '币种名错误'))
     if chain_type not in (1, 2):
         return create_response(CodeMsg.CM(1031, '链类型错误'))
     if chain_type == 2:
         base_address = consul_clinet.get_digiccy_base_account(
             coin_name, is_seed=False)
         wallet_str = "{}_wallet".format(coin_name.lower())
         wallet = getattr(app, wallet_str)
         try:
             base_balance = wallet.get_balance(base_address)
             print("-----------------", base_balance)
         except Exception as e:
             return create_response(CodeMsg.CM(1030, '链外余额查询错误'))
     else:
         stellar_address = consul_clinet.get_stellar_base_account(
             coin_name, is_seed=False)
         stellar_node = app.stellar_service.stellar_node()
         url = stellar_node + '/accounts/{}'.format(stellar_address)
         try:
             response = requests.get(url).json()
             balances = response.get('balances')
             for balance_info in balances:
                 if balance_info.get("asset_code") == coin_name:
                     base_balance = balance_info.get("balance")
                     break
         except Exception as e:
             return create_response(CodeMsg.CM(1030, '链内余额查询错误'))
     if base_balance is None:
         return create_response(CodeMsg.CM(1030, '余额查询错误'))
     base_balance = str(base_balance)
     return create_response(CodeMsg.CM(200, '余额查询成功'), data=base_balance)
コード例 #4
0
def task_chain_out_withdraw():
    """提现链外转账"""
    with db.app.app_context():

        # VPC base账户address
        vpc_base_address = consul_clinet.get_digiccy_base_account(
            COIN_NAME, is_seed=False)
        # vpc_base_seed = consul_clinet.get_digiccy_base_account(COIN_NAME)
        #
        # gas_limit, gas_price = consul_clinet.get_digiccy_collect_fee(COIN_NAME)

        # 待链外转账订单
        orders = Order.chain_out_withdraw(COIN_NAME, 100)
        for order in orders:
            # 定时任务开关
            if not consul_clinet.get_task_switch():
                logging.warning('{}链内充值定时任务被手动关闭!'.format(COIN_NAME))
                return

            # 本地节点是否链接,是否同步
            if not vpc_wallet.is_connected():
                logging.error('{}节点离线!'.format(COIN_NAME))
                return
            if vpc_wallet.is_syncing():
                logging.error('{}节点同步未完成!'.format(COIN_NAME))
                return

            # 订单收款账户,数量
            order_to = order.order_to
            amount = order.amount

            # 链外账户余额
            base_account_balance = vpc_wallet.get_balance(
                vpc_base_address)  # decimal.Decimal
            minerfee = vpc_wallet.get_minerFee(vpc_base_address)
            if minerfee < 0.0001:
                logging.error('base账户矿工费余额不足,余额{}'.format(str(minerfee)))
                return

            if amount + Decimal('0.002') > base_account_balance:
                logging.error('base账户余额不足,支付金额{}'.format(str(amount)))
                print('base账户余额不足,支付金额{}'.format(str(amount)))
                continue

            # 付款账户信息
            # 当前区块
            block_num = vpc_wallet.get_block_num()
            nonce_num = vpc_wallet.get_nonce(vpc_base_address)

            # 改变订单状态
            order.order_from = vpc_base_address
            order.status = 0

            order_detail = OrderDetail(id=str(uuid.uuid1()),
                                       order_id=order.id,
                                       act_type=2,
                                       query_json=json.dumps(
                                           dict(addrfrom=vpc_base_address,
                                                addrto=order_to,
                                                block_num=block_num,
                                                nonce_num=nonce_num)),
                                       response_json='',
                                       status=-1)
            try:
                db.session.add_all([order, order_detail])
                db.session.commit()
            except Exception as e:
                logging.error(
                    'chain_out_withdraw update order error:{}'.format(str(e)))
                return
            is_success, msg = vpc_wallet.payment(vpc_base_address, order_to,
                                                 amount)
            print('定时任务链外转账结果', is_success, msg)
            if is_success:
                order_detail.status = 1  # 订单请求成功
                order_detail.response_json = msg
                order.order_hash = msg
                order.status = 2  # 转账发起成功待确认
                try:
                    db.session.add_all([order, order_detail])
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'chain_out_withdraw update order error:{}'.format(
                            str(e)))
                    return
            else:
                order_detail.status = 0  # 订单请求失败
                order_detail.response_json = json.dumps(msg)
                try:
                    db.session.add(order_detail)
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'chain_out_withdraw update order error:{}'.format(
                            str(e)))
                    return
コード例 #5
0
def task_chain_out_withdraw():
    """提现链外转账"""
    with db.app.app_context():

        # 从consul获取BTC base账户address
        btc_base_address = consul_clinet.get_digiccy_base_account(
            COIN_NAME, is_seed=False)
        # 根据address得到BTC base账户的account
        btc_base_account = btc_wallet.get_accounts(btc_base_address)
        if btc_base_account is None:
            return
        # 查询链外status为-1的订单
        orders = Order.chain_out_withdraw(COIN_NAME, 100)
        for order in orders:
            # 定时任务开关
            if not consul_clinet.get_task_switch():
                logging.warning('{}链内充值定时任务被手动关闭!'.format(COIN_NAME))
                return

            # 节点是否链接,是否同步
            if not btc_wallet.is_connected():
                logging.error('{}节点离线!'.format(COIN_NAME))
                return
            if not btc_wallet.is_sync():
                logging.error('{}节点同步未完成!'.format(COIN_NAME))
                return

            # 链外账户的收款地址
            order_to = order.order_to
            # 转账数量
            amount = order.amount

            # 检查财务账户链外余额, 即付款账户余额
            base_account_balance = btc_wallet.get_balance_by_account(
                btc_base_account)  # decimal.Decimal
            # 链外转账手续费
            fee = btc_wallet.estimate_fee()
            if base_account_balance or fee is None:
                return
            if amount + fee > base_account_balance:
                logging.error('base账户余额不足,支付金额{}'.format(str(amount)))
                print('base账户余额不足,支付金额{}'.format(str(amount)))
                continue

            # 当前区块信息
            block_num = btc_wallet.get_block_num()

            # 改变订单状态
            order.order_from = btc_base_account
            order.status = 0

            order_detail = OrderDetail(id=str(uuid.uuid1()),
                                       order_id=order.id,
                                       act_type=2,
                                       query_json=json.dumps(
                                           dict(addrfrom=btc_base_account,
                                                addrto=order_to,
                                                block_num=block_num)),
                                       response_json='',
                                       status=-1)
            try:
                db.session.add_all([order, order_detail])
                db.session.commit()
            except Exception as e:
                logging.error(
                    'chain_out_withdraw update order error:{}'.format(str(e)))
                return

            # 链外转账
            is_success, txid = btc_wallet.payment(btc_base_account, order_to,
                                                  amount)
            print('定时任务链外转账结果', is_success, txid)
            if is_success:
                order_detail.status = 1  # 订单请求成功
                order_detail.response_json = txid
                order.order_hash = txid
                order.status = 2  # 成功发起转账,转账是否成功,待确认
                try:
                    db.session.add_all([order, order_detail])
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'chain_out_withdraw update order error:{}'.format(
                            str(e)))
                    return
            else:
                order_detail.status = 0  # 订单请求失败
                order_detail.response_json = json.dumps(txid)
                try:
                    db.session.add(order_detail)
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'chain_out_withdraw update order error:{}'.format(
                            str(e)))
                    return
コード例 #6
0
def task_chain_out_withdraw():
    """提现链外转账"""
    with db.app.app_context():

        # EOS base账户address
        eos_base_address = consul_clinet.get_digiccy_base_account(COIN_NAME, is_seed=False)
        privKey = consul_clinet.get_digiccy_base_privatekey(COIN_NAME)
        # privKey = digiccy_base.stellar_keypair(stellar_encrypt_seed=privKey)

        privKey = eval(decryptSeed(privKey)).get("seed")
        # privKey = "5Jb46jpSGwuXJXcom6e5PdLsaW1rMwc3MUqhZnVTApqVynMcXxA"
        # 待链外转账订单
        orders = Order.chain_out_withdraw(COIN_NAME, 100)
        for order in orders:
            # 定时任务开关
            if not consul_clinet.get_task_switch():
                logging.warning('{}链内充值定时任务被手动关闭!'.format(COIN_NAME))
                return

            # 本地节点是否链接,是否同步
            if not eos_wallet.init_consul("", ""):
                logging.error('{}节点离线!'.format(COIN_NAME))
                return
            if not eos_wallet.is_syncing():
                logging.error('{}节点同步未完成!'.format(COIN_NAME))
                return

            # 订单收款账户,数量
            order_to = order.order_to
            amount = order.amount

            # 链外账户余额
            base_account_balance = eos_wallet.get_balance(eos_base_address)  # decimal.Decimal
            if base_account_balance < amount:
                logging.error('eos base账户余额不足,支付金额{}'.format(str(amount)))

            # 当前区块
            block_num = eos_wallet.get_block_num()

            # 改变订单状态
            order.order_from = eos_base_address
            order.status = 0

            order_detail = OrderDetail(
                id=str(uuid.uuid1()),
                order_id=order.id,
                act_type=2,
                query_json=json.dumps(
                    dict(addrfrom=eos_base_address, addrto=order_to, block_num=block_num)),
                response_json='',
                status=-1
            )
            try:
                db.session.add_all([order, order_detail])
                db.session.commit()
            except Exception as e:
                logging.error('chain_out_withdraw update order error:{}'.format(str(e)))
                return
            is_success, msg = eos_wallet.payment(privKey, eos_base_address, order_to, amount)
            print('定时任务链外转账结果', is_success, msg)
            if is_success:
                order_detail.status = 1  # 订单请求成功
                order_detail.response_json = msg
                order.order_hash = msg
                order.status = 2  # 转账发起成功待确认
                try:
                    db.session.add_all([order, order_detail])
                    db.session.commit()
                except Exception as e:
                    logging.error('chain_out_withdraw update order error:{}'.format(str(e)))
                    return
            else:
                order_detail.status = 0  # 订单请求失败
                order_detail.response_json = json.dumps(msg)
                try:
                    db.session.add(order_detail)
                    db.session.commit()
                except Exception as e:
                    logging.error('chain_out_withdraw update order error:{}'.format(str(e)))
                    return