def getBalance_of_all_address_list(api_name, address): ''' 返回所有余额不为0的账号与账户余额 :param api_name: :param address: :return:返回所有余额不为0的账号与账户余额 ''' result_list = [] # 余额list getBalance_account_list = [] # 余额不为0的账号list for i in range(len(address)): params = [address[i]] try: result = request_Api(api_name, params) except Exception as e: logging.error("查询地址中所有账号余额失败,{}".format(e)) continue logging.info("业务请求: {},result:{}".format(api_name, result)) print("查询账号: {},查询结果: {}".format(params, result)) result = int(result["result"]) #print(result) #result = int(result / pow(10, 18)) #print("除以18后{}".format(result)) if result > 0: print("比较后{}".format(result)) result_list.append(result) #print("比较后{}".format(result_list)) getBalance_account_list.append(params) else: logging.info("结果为:{}".format(result)) logging.info("有余额的账户为:{},共有{}余额".format(getBalance_account_list, result_list)) print(getBalance_account_list, getBalance_account_list) return getBalance_account_list, result_list
def getAB_list(all_list): ''' :param all_list: :return: ''' num_address_list = [] zero_address_list = [] for add in all_list: try: result = request_Api("chain_getBalance", [add]) # print("resule",result) result = int(result["result"]) if result > 100000: unlockAccount("account_unlockAccount", [add]) num_address_list.append(add) else: zero_address_list.append(add) except Exception as e: print("查询账户余额".format(e)) print("num——address: {}".format(num_address_list)) print("*" * 10) print("zreo-address: {}".format(zero_address_list)) return num_address_list, zero_address_list
def random_transaction(api_name, send_account, receive_account): ''' :param api_name: :param receive_account: :return: ''' logging.info(receive_account) price = [ "0x168000000000000", "0x18800000000", "0x16600000000", '0x1580000000', "0x368000000000", "0x66800000000" ] for i in range(len(receive_account)): logging.info(receive_account[i]) receive_account = np.array(receive_account) logging.info(receive_account[i]) price = price[random.randint(0, len(price) - 1)] logging.info(price) logging.info("ra:{},reac{},pri{}".format(send_account, receive_account[i], price)) try: api_params = [ send_account, receive_account[i], price, "0x110", "0x30000", "" ] logging.info("api_params:{} ".format(api_params)) result = request_Api(api_name, api_params) # print("业务需求: 发送交易 transaction of 120,result:{}".format(result)) except Exception as e: logging.info("随机发送多笔交易失败{}".format(e)) continue return result
def chain_jiaoyi(A_add, B_add, price): ''' :param A_add: :param B_add: :param price: :return: ''' params = [A_add, B_add, price, "0x110", "0x30000", ""] result = request_Api("account_transfer", params) return result
def chain_transaction(A_add, B_add, price): ''' 发送交易 :param A_add:发地址 :param B_add:收地址 :param price:金额 :return: ''' params = [A_add, B_add, price, "0x110", "0x30000", ""] result = request_Api("account_transfer", params) return result
def chain_getBalance(api_name, params): ''' :return: 查询对应账户的余额 ''' logging.info("业务 请求 chain_getBalance") try: result = request_Api(api_name, params) result = result["result"] logging.info(result) except: logging.error("查询余额失败,{}".format(result)) return result return result
def get_address_list(api_name, param): ''' 得到系统中的当前所有账户地址 :param api_name: :param param: :return: ''' print("业务需求: 查询地址list account_listAddress") try: address = request_Api(api_name, param) # print(address) address_list = address["result"] # print("当前系统中所有地址为:{},共有{}个".format(address_list, len(address_list))) except Exception as e: return e # 调用接口报错 return address_list
def unlockAccount(api_name, params): ''' 解锁账号 :param api_name: account_unlockAccount :param params:账号地址 :return: 失败返回错误原因,成功不返回任何信息 示例代码 curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"account_unlockAccount","params":["0x518b3fefa3fb9a72753c6ad10a2b68cc034ec391"], "id": 3}' -H "Content-Type:application/json" ''' result = request_Api(api_name, params) try: #result =result["result"] print("解锁成功{}".format(result)) return result except: logging.error("解锁失败,api返回错误,返回值为{}".format(result)) #print("解锁失败,api返回错误,返回值为{}".format(e)) return
def transaction_one(send_account, receive_account, price): ''' :param rootAccount: 发送账户 :param receive_account: 接收账户 :return: 1个账户的交易结果 ''' api_name = "account_transfer" try: api_params = [ send_account, receive_account, price, "0x110", "0x30000", "" ] result = request_Api(api_name, api_params) result = result['result'] return result except: print("发送一笔交易失败{}".format(result)) logging.info("发送一笔交易失败{}".format(result)) return result