def inquire_accounts_in_key_dot_json(): seed = CONSTANT.SEED client = Client(private_key=seed, api_server=CONSTANT.API_SERVER) import tools.load_json keys = tools.load_json.file2json('keys.json')[0:1] for key in keys: address = key['public_key'] balance = client.get_balances(address)[0]['balance'] print("%s\t%s" % (address, balance))
def inquire(): # 定义一个client,实际上也可以不定义,但通用方法,先定义一个client seed = CONSTANT.SEED client = Client(private_key=seed, api_server=CONSTANT.API_SERVER) # 查询任意一个地址的所有信息: balances = client.get_balances( 'GAFRGA77FLN4JIWG7P7TXUDS5RX2475V5CTVKQJOFMXKBE5AJ25I6HRA' )[0]['balance'] print(balances) balances = client.get_info( 'GCHZDZXYLZ76XADS7735LK3OJUFZ2TBSXAR23YXKXCXXHUEEVT5C37PY') print(balances) balances = client.get_info() print(balances)
'GDJJB2QA7XZSBHCGIRUAIUC5RJ6MJGV2DG5THNNJOTUQWXEDKXLVFZMI', 'GCKEZY2FW2MLANNJTQZIKFISGP2MZ57MZWMGECG3WD2FJHEQAGAA7ZUA' ] # key_pairs=[] # for key in private_keys: # key_pair=Keypair.from_seed(seed=key) # key_pairs.append(key_pair) # # issuer_priv=private_keys[0] # distributor_priv=private_keys[1] # # issuer=key_pairs[0].address().decode() # distributor=key_pairs[1].address().decode() # # # # sdk.issue_asset(issuer_priv,distributor_priv,'eth',100,'testnet') # # builder = Builder(secret=distributor_priv, network='testnet') # builder.append_payment_op(destination=issuer, amount=(84000000-1), asset_type='ltc', asset_issuer=issuer) # builder.sign() # result = builder.submit() client = Client(private_key=private_keys[0], api_server=api_server) client.pay_to(addresses[1], 123.45) client.pay_to(addresses[1], 543.21, asset_code='ltc', asset_issuer=addresses[0])
# -*- coding: UTF-8 -*- # 该模块给出了一个查询账户联金的例子 import CONSTANT from wrapper.client import Client # 定义一个client,实际上也可以不定义,但通用方法,先定义一个client seed=CONSTANT.SEED client=Client(private_key=seed, api_server=CONSTANT.API_SERVER) # 临时定义一个遍历balaneces列表的方法,用于查询联金数量 def get_link(balances): if not balances: return 0 balance=0 for item in balances: item=dict(item) if item.has_key('asset_code') and item['asset_code']=='LINK' and item['asset_issuer']==CONSTANT.ISSUER_ADDRESS: balance=item['balance'] return balance else: return 0 # 查询任意一个地址的所有信息: balance_of_link=get_link(client.get_balances('GA4OP7NMIWWLKSCIXRYKVQC5L36OPIJHDYKW25EF5BWSR3P2MOHY4REZ')) print(balance_of_link) balance_of_link=get_link(client.get_balances('GAFRGA77FLN4JIWG7P7TXUDS5RX2475V5CTVKQJOFMXKBE5AJ25I6HRA')) print(balance_of_link) balance_of_link=get_link(client.get_balances()) print(balance_of_link)
# -*- coding:utf-8 -*- # 该模块给出了一个单线程发币的例子,多线程发币见 *** import CONSTANT from wrapper.client import Client from tools import load_json constant = CONSTANT.Constant('local') # trustee trustee = constant.ISSUER_ADDRESS keys = load_json.file2json('keys.json')[102:103] for keypair in keys: client = Client(private_key=keypair['private_key'], api_server=constant.API_SERVER) client.trust(constant.ISSUER_ADDRESS, 'LINK', 1000)
# passed from wrapper.client import Client api_server='testnet' private_keys=['SBHTQEEKVTF2E3MQ6WCSFN725D73AELT2NSHS3PI7JASZLEJ4LT6MPD4', 'SBTCFAL73MPCPIPLSIUTRQDLQQAXYCM4TILA26PGBL6QXXEU5SAGLYEU'] addresses=['GDJJB2QA7XZSBHCGIRUAIUC5RJ6MJGV2DG5THNNJOTUQWXEDKXLVFZMI', 'GCKEZY2FW2MLANNJTQZIKFISGP2MZ57MZWMGECG3WD2FJHEQAGAA7ZUA', 'GCKEZY2FW2MLANNJTQZIKFISGP2MZ57MZWMGECG3WD2FJHEQAGAA7ZUA'] client0=Client(private_key=private_keys[0],api_server=api_server) client1=Client(private_key=private_keys[1],api_server=api_server) client2=Client(address=addresses[0],api_server=api_server) client3=Client(address=addresses[1],api_server=api_server) balance0=client0.get_balances() balance1=client1.get_balances() balance2=client2.get_balances() balance3=client3.get_balances() a=1
from wrapper.client import Client def op(source, destination, amount): builder = Builder(secret=source) builder.append_payment_op(destination=destination, amount=amount) builder.sign() builder.submit() # master account: master_private_key = 'SDSSWWPCGGRDB6SVVOJUWFQ3ODQFX62GVTKCPELNULO5PXVCFE67L7HO' kp = Keypair.from_seed(seed=master_private_key) master_public_key = str(kp.address().decode()) client = Client(master_private_key, api_server='test') balance = float(client.get_balances()[0]["balance"]) # create 10000 accounts: # cnt=0 # key_pairs=[] # while cnt<10000: # key_pair=Keypair.random() # publickey = key_pair.address().decode() # seed = key_pair.seed().decode() # key_pair={'private_key':seed,'public_key':publickey} # key_pairs.append(key_pair) # cnt+=1 # # write to a json file # json_string=json.dumps(key_pairs) # f=open('keys.json','w')
# -*- coding:utf-8 -*- # 该模块给出了一个单线程发币的例子,多线程发币见 *** import CONSTANT from wrapper.client import Client from tools import load_json constant = CONSTANT.Constant('test') # 定义一个发币端 seed = constant.SEED client = Client(private_key=constant.SEED, api_server=constant.API_SERVER) # 定义一个收币端,of Client destination = Client(address=constant.DISTRIBUTOR_ADDRESS) # 发币 keys = load_json.file2json('keys.json')[102:103] for keypair in keys: client.pay_to(constant.DISTRIBUTOR_ADDRESS, 1000000) # client.pay_to(keypair['public_key'], 800, asset_code='LINK', asset_issuer=constant.ISSUER_ADDRESS)
# -*- coding:utf-8 -*- import sqlite3 from wrapper.client import Client seed = 'SDSSWWPCGGRDB6SVVOJUWFQ3ODQFX62GVTKCPELNULO5PXVCFE67L7HO' client = Client(seed, api_server='test') # 连接sqlite conn = sqlite3.connect('/home/cc5985/key_pairs.db') cursor = conn.cursor() sql_str = 'select * from key_pairs_2018_3_17' data = cursor.execute(sql_str).fetchall() cnt = 0 for line in data: if cnt >= 100: break address = str(line[2]) client.fund(destination=address, amount=1000000000 - 0.00001) cnt += 1 print "Operation done successfully" conn.close()
# 该文件测试wrapper文件夹下Client类 from wrapper.client import Client import CONSTANT import unittest import tools.load_json as TOOLS import time from wrapper.utils import * # 定义一些常数 master_seed=CONSTANT.SEED keypairs=TOOLS.file2json('keys.json') # 为了形象化,我们给4个主要的测试账户起了个名字 Odin = Client(master_seed) Heimdar = Client(keypairs[0]['private_key']) Heimdar = Client(keypairs[1]['private_key']) Loki = Client(keypairs[2]['private_key']) # 这个瓦力是专门用来做balance测试的 Vale = Client(keypairs[-1]['private_key']) class TestClient(unittest.TestCase): def test_init(self): self.assertTrue(isinstance(Odin, Client)) def test_fund(self): # 我们要确定的事情有: # 1. 奥丁账户的钱少了123.345个 # 2. 洛基的账户被激活了,并且他的钱多了123.345个 # 3. 这个测试只能做一次,因为fund函数是一次性的
# test funding function import time from wrapper.client import Client from wrapper.keypair import Keypair seed='SDSSWWPCGGRDB6SVVOJUWFQ3ODQFX62GVTKCPELNULO5PXVCFE67L7HO' client=Client(seed,api_server='test') key_pairs=[] t1=time.time() for i in range(0,5): key_pair=Keypair.random() secret_key=key_pair.seed().decode() address=key_pair.address().decode() client.fund(address,1000) print(secret_key+' '+address) key_pairs.append(key_pair) t2=time.time() print('\n' + str(t2-t1))