# -*- 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)
Exemplo n.º 2
0
# passed

import wrapper.client as client
from wrapper import builder
import CONSTANT
from tools import load_json

seed=CONSTANT.SEED
keypairs=load_json.file2json('keys.json')
keypairs=keypairs[101:200]
import time
t=time.time()
builder = builder.Builder(secret=seed)
for key in keypairs:
    builder.append_create_account_op(destination=key['public_key'],starting_balance=66.6666)
    # builder.append_payment_op(destination=key['public_key'],amount=333.44)
builder.sign()
result = builder.submit()
print(result)
print(time.time()-t)
Exemplo n.º 3
0
# -*- coding: UTF-8 -*-

# 该文件测试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个
Exemplo n.º 4
0
def all_in_one(activate_the_distributor=True,
               activate_accounts=True,
               send_native_asset_to_accounts=True,
               issue_asset=True,
               do_trust=True,
               send_LINK_to_accounts=True):

    # 初始化Client实例
    constant = CONSTANT.Constant('test')
    master = CLIENT.Client(constant.SEED, api_server=constant.API_SERVER)
    # 产生100个密钥对
    keypairs = load_json.file2json('keys.json')[201:290]
    distributor = CLIENT.Client(constant.DISTRIBUTOR_SEED)
    builder = BUILDER.Builder(secret=constant.SEED, network='testnet')

    if activate_the_distributor:
        # activate the distributor
        master.fund(destination=distributor.address, amount=100)

    if activate_accounts:
        # activate the above accounts using parallel method
        for keypair in keypairs:
            address = keypair['public_key']
            print(address)
            builder.append_create_account_op(destination=address,
                                             starting_balance=100)
        builder.sign()
        builder.submit()

    if send_native_asset_to_accounts:
        # send native asset to accounts
        builder = BUILDER.Builder(secret=constant.SEED, network='testnet')
        for keypair in keypairs:
            address = keypair['public_key']
            print(address)
            builder.append_payment_op(destination=address, amount=123.456)
        builder.sign()
        builder.submit()

    if issue_asset:
        result = master.issue_asset(distributor.private_key,
                                    asset_code='LINK',
                                    amount=10000000)
        print(result)

    if do_trust:
        for keypair in keypairs:
            try:
                client = CLIENT.Client(private_key=keypair['private_key'],
                                       api_server=constant.API_SERVER)
                client.trust(constant.ISSUER_ADDRESS,
                             asset_code='LINK',
                             limit=1000000)
            except:
                print(client.address)

    if send_LINK_to_accounts:
        # send LINK asset to accounts
        while True:
            builder = BUILDER.Builder(secret=constant.DISTRIBUTOR_SEED,
                                      network='testnet')
            for keypair in keypairs:
                address = keypair['public_key']
                print(address)
                import random
                amount = round(random.random() * 10, 4)
                builder.append_payment_op(destination=address,
                                          amount=amount,
                                          asset_type='LINK',
                                          asset_issuer=constant.ISSUER_ADDRESS)
            builder.sign()
            builder.submit()