Exemplo n.º 1
0
def prepare_for_debug(filename):
    TG = TrxGenerator('http://127.0.0.1:8897', payer=None)
    Api = api.Api('http://127.0.0.1:8897')
    boss = base.User()
    # issue fungible
    DBG_Symbol = base.Symbol('DBG', 666, 5)
    DBG_Asset = base.new_asset(DBG_Symbol)
    act_newf = AG.new_action('newfungible', name='DBG', sym_name='DBG',
                             sym=DBG_Symbol, creator=boss.pub_key, total_supply=DBG_Asset(1000000))
    trx = TG.new_trx()
    trx.add_action(act_newf)
    trx.add_sign(boss.priv_key)
    trx.set_payer(boss.pub_key.to_string())
    resp = Api.push_transaction(trx.dumps())
    print(resp)

    with open(filename, 'r') as f:
        tmp = json.load(f)
    users = [base.User.from_string(
        each['pub_key'], each['priv_key']) for each in tmp]

    trx = TG.new_trx()
    for user in users:
        act_issue = AG.new_action('issuefungible', address=base.Address(
        ).set_public_key(user.pub_key), number=DBG_Asset(1000), memo='')
        trx.add_action(act_issue)
    trx.add_sign(boss.priv_key)
    trx.set_payer(boss.pub_key.to_string())
    resp = Api.push_transaction(trx.dumps())
    print(resp)
Exemplo n.º 2
0
def run(path):
    if(verify(path)):
        global child
        child = pexpect.spawn('python3 -i '+path+'/main.py')
        # print(read())
        # child.readline()
        # print(process)
        global token_name
        token_name = '{}{}'.format(path, int(time.time()))
        issuetoken = AG.new_action('issuetoken', domain=domain_name, names=[
                               token_name], owner=[base.Address().set_public_key(root_pub)])

        trx = TG.new_trx()
        # trx.add_action(prodvote)
        trx.add_action(issuetoken)
        trx.add_sign(root_key)
        trx.set_payer(root_pub.to_string())
        resp = api.push_transaction(trx.dumps())
        # print(resp.content)
        # print(resp)
        if(resp.status_code == 202):
            print('token name on chain is {}'.format(token_name))
        else:
            print('data to chain fialed')
    else:
        print('authority verify faild')
Exemplo n.º 3
0
def pre_action():
    newdomain = AG.new_action(
        'newdomain', name=domain_name, creator=user.pub_key)

    issuetoken = AG.new_action('issuetoken', domain=domain_name, names=[
                               token1_name, token2_name, token3_name], owner=[base.Address().set_public_key(user.pub_key)])

    destroytoken = AG.new_action(
        'destroytoken', domain=domain_name, name=token2_name)

    pass_link = evt_link.EvtLink()
    pass_link.set_header(evt_link.HeaderType.version1.value |
                         evt_link.HeaderType.everiPass.value | evt_link.HeaderType.destroy.value)
    pass_link.set_domain(domain_name)
    pass_link.set_token(token3_name)
    pass_link.set_timestamp(int(time.time()))
    pass_link.sign(user.priv_key)

    everipass = AG.new_action(
        'everipass', link=pass_link.to_string())

    group_json = json.loads(group_json_raw)
    group_json['name'] = group_name
    group_json['group']['name'] = group_name
    group_json['group']['key'] = str(user.pub_key)
    newgroup = AG.new_action_from_json('newgroup', json.dumps(group_json))

    symbol = base.Symbol(
        sym_name=sym_name, sym_id=sym_id, precision=sym_prec)
    asset = base.new_asset(symbol)
    newfungible = AG.new_action(
        'newfungible', name=sym_name, sym_name=sym_name, sym=symbol, creator=user.pub_key, total_supply=asset(10000000))

    issuefungible1 = AG.new_action(
        'issuefungible', address=base.Address().set_public_key(user.pub_key), number=asset(100), memo='goodluck')

    asset_evt = base.new_asset(base.Symbol(
        sym_name=sym_name, sym_id=1, precision=5))
    issuefungible2 = AG.new_action(
        'issuefungible', address=base.Address().set_public_key(user.pub_key), number=asset_evt(100), memo='goodluck')

    e2p = AG.new_action(
        'evt2pevt', _from=base.Address().set_public_key(user.pub_key), to=base.Address().set_public_key(user.pub_key), number=asset_evt(100), memo='goodluck')

    pay_link = evt_link.EvtLink()
    pay_link.set_max_pay(999999999)
    pay_link.set_header(evt_link.HeaderType.version1.value |
                        evt_link.HeaderType.everiPay.value)
    pay_link.set_symbol_id(sym_id)
    pay_link.set_link_id_rand()
    pay_link.sign(user.priv_key)

    everipay = AG.new_action('everipay', payee=pub2, number=asset(
        1), link=pay_link.to_string())

    trx = TG.new_trx()
    trx.add_action(newdomain)
    trx.add_sign(user.priv_key)
    trx.add_action(newgroup)
    trx.add_action(newfungible)
    api.push_transaction(trx.dumps())

    trx = TG.new_trx()
    trx.add_action(issuetoken)
    trx.add_action(issuefungible1)
    trx.add_sign(user.priv_key)
    api.push_transaction(trx.dumps())

    trx = TG.new_trx()
    trx.add_action(issuefungible2)
    trx.add_sign(priv_evt)
    api.push_transaction(trx.dumps())

    trx = TG.new_trx()
    trx.add_action(e2p)
    trx.add_sign(user.priv_key)
    api.push_transaction(trx.dumps())

    trx = TG.new_trx()
    trx.add_action(destroytoken)
    trx.add_action(everipass)
    trx.add_action(everipay)
    trx.add_sign(user.priv_key)
    api.push_transaction(trx.dumps())
    time.sleep(2)
Exemplo n.º 4
0
def pre_action():
    prodvote = AG.new_action('prodvote',
                             producer='evt',
                             key="action-everipay",
                             value=2)

    newdomain = AG.new_action('newdomain',
                              name=domain_name,
                              creator=user.pub_key)

    auth_A = base.AuthorizerWeight(base.AuthorizerRef('A', evt_pub), 1)
    updatedomain = AG.new_action('updatedomain',
                                 name=domain_name,
                                 manage=base.PermissionDef(
                                     'manage', 1, [auth_A]))

    issuetoken = AG.new_action(
        'issuetoken',
        domain=domain_name,
        names=[token1_name, token2_name, token3_name],
        owner=[base.Address().set_public_key(user.pub_key)])

    destroytoken = AG.new_action('destroytoken',
                                 domain=domain_name,
                                 name=token2_name)

    pass_link = evt_link.EvtLink()
    pass_link.set_header(evt_link.HeaderType.version1.value
                         | evt_link.HeaderType.everiPass.value
                         | evt_link.HeaderType.destroy.value)
    pass_link.set_domain(domain_name)
    pass_link.set_token(token3_name)
    pass_link.set_timestamp(int(time.time()))
    pass_link.sign(user.priv_key)

    everipass = AG.new_action('everipass', link=pass_link.to_string())

    group_json = json.loads(group_json_raw)
    group_json['name'] = group_name
    group_json['group']['name'] = group_name
    group_json['group']['key'] = str(user.pub_key)
    newgroup = AG.new_action_from_json('newgroup', json.dumps(group_json))

    group_json['group']['root']['threshold'] = 5
    updategroup = AG.new_action_from_json('updategroup',
                                          json.dumps(group_json))

    symbol = base.Symbol(sym_name=sym_name, sym_id=sym_id, precision=sym_prec)
    asset = base.new_asset(symbol)
    newfungible = AG.new_action('newfungible',
                                name=sym_name,
                                sym_name=sym_name,
                                sym=symbol,
                                creator=user.pub_key,
                                total_supply=asset(10000000))

    issuefungible1 = AG.new_action('issuefungible',
                                   address=base.Address().set_public_key(
                                       user.pub_key),
                                   number=asset(100),
                                   memo='goodluck')

    issuefungible2 = AG.new_action('issuefungible',
                                   address=base.Address().set_public_key(
                                       user.pub_key),
                                   number=base.EvtAsset(1000),
                                   memo='goodluck')

    e2p = AG.new_action('evt2pevt',
                        _from=base.Address().set_public_key(user.pub_key),
                        to=base.Address().set_public_key(user.pub_key),
                        number=base.EvtAsset(100),
                        memo='goodluck')

    pay_link = evt_link.EvtLink()
    pay_link.set_timestamp(int(time.time()))
    pay_link.set_max_pay(999999999)
    pay_link.set_header(evt_link.HeaderType.version1.value
                        | evt_link.HeaderType.everiPay.value)
    pay_link.set_symbol_id(sym_id)
    pay_link.set_link_id_rand()
    pay_link.sign(user.priv_key)

    everipay = AG.new_action('everipay',
                             payee=pub2,
                             number=asset(1),
                             link=pay_link.to_string())

    bonus_json = json.loads(bonus_json_raw)
    setpsvbonus = AG.new_action_from_json('setpsvbonus',
                                          json.dumps(bonus_json))

    addmeta = AG.new_action('addmeta',
                            meta_key='sdf',
                            meta_value='sdfsadf',
                            creator=base.AuthorizerRef('A', user.pub_key),
                            domain=domain_name,
                            key=token1_name)

    trx = TG.new_trx()
    trx.add_action(issuefungible2)
    trx.add_sign(priv_evt)
    trx.add_sign(user.priv_key)

    newsuspend = AG.new_action('newsuspend',
                               name='suspend',
                               proposer=user.pub_key,
                               trx=trx)

    newsuspend2 = AG.new_action('newsuspend',
                                name='suspend2',
                                proposer=user.pub_key,
                                trx=trx)

    cancelsuspend = AG.new_action('cancelsuspend', name='suspend2')

    aprvsuspend = AG.new_action('aprvsuspend',
                                name='suspend',
                                signatures=json.loads(
                                    trx.dumps())['signatures'])

    execsuspend = AG.new_action('execsuspend',
                                name='suspend',
                                executor=user.pub_key)

    lock_json = json.loads(lock_json_raw)
    lock_json['proposer'] = str(user.pub_key)
    lock_json['assets'][0]['data']['from'] = str(user.pub_key)
    lock_json['condition']['data']['cond_keys'] = [str(user.pub_key)]
    lock_json['succeed'] = [str(user.pub_key)]
    lock_json['failed'] = [str(user.pub_key)]
    newlock = AG.new_action_from_json('newlock', json.dumps(lock_json))

    trx = TG.new_trx()
    trx.add_action(issuefungible2)
    trx.add_sign(priv_evt)
    trx.add_sign(user.priv_key)
    trx.set_payer(user.pub_key.to_string())
    resp = api.push_transaction(trx.dumps())
    print(resp)

    trx = TG.new_trx()
    # trx.add_action(prodvote)
    trx.add_action(newdomain)
    trx.add_action(newsuspend)
    trx.add_action(newsuspend2)
    trx.add_action(newgroup)
    trx.add_action(newfungible)
    trx.add_sign(user.priv_key)
    trx.add_sign(priv_evt)
    trx.set_payer(user.pub_key.to_string())
    resp = api.push_transaction(trx.dumps())
    print(resp)

    trx = TG.new_trx()
    trx.add_action(updatedomain)
    trx.add_action(cancelsuspend)
    trx.add_action(aprvsuspend)
    trx.add_action(updategroup)
    trx.add_action(issuetoken)
    trx.add_action(issuefungible1)
    trx.add_sign(user.priv_key)
    trx.set_payer(user.pub_key.to_string())
    resp = api.push_transaction(trx.dumps())
    print(resp)

    trx = TG.new_trx()
    trx.add_action(e2p)
    trx.add_action(addmeta)
    trx.add_action(execsuspend)
    trx.add_sign(user.priv_key)
    trx.set_payer(user.pub_key.to_string())
    resp = api.push_transaction(trx.dumps())
    print(resp)

    trx = TG.new_trx()
    trx.add_action(setpsvbonus)
    trx.add_sign(priv_evt)
    trx.add_sign(user.priv_key)
    trx.set_payer(user.pub_key.to_string())
    resp = api.push_transaction(trx.dumps())
    print(resp)

    trx = TG.new_trx()
    trx.add_action(destroytoken)
    trx.add_action(everipass)
    trx.add_action(everipay)
    trx.add_sign(user.priv_key)
    trx.set_payer(user.pub_key.to_string())
    resp = api.push_transaction(trx.dumps())
    print(resp)

    trx = TG.new_trx()
    trx.add_action(newlock)
    trx.add_sign(user.priv_key)
    trx.set_payer(user.pub_key.to_string())
    resp = api.push_transaction(trx.dumps())
    print(resp)

    time.sleep(2)