Exemple #1
0
def tiat_create_txns(contract, src_acc, dest_accs, amount):
    # Clear any cached sessions. This is needed to ensure multiple processes
    # don't try to reuse the same TCP connection, which would lead to havoc
    LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0)
    chain.set_active_chain(LocalNet)
    src_acc = Account(private_key=src_acc.private_key)
    contract = Contract.load_from_address(contract.address, load_state=False)

    txn_info_list = []
    contract.account = src_acc
    src_addr = src_acc.bech32_address
    orig_nonce = nonces.get(src_addr, src_acc.get_nonce())
    for dest_acc in dest_accs:
        try:
            dest = dest_acc.address0x
            txn_info = contract.call(
                method="Transfer",
                params=[
                    Contract.value_dict("to", "ByStr20", dest),
                    Contract.value_dict("tokens", "Uint128", str(amount))
                ],
                nonce=new_nonce(src_acc),
                confirm=False)
            txn_info_list.append(txn_info)
            print(json.dumps(src_acc.last_params), file=sys.stderr)
            print("Created {} transactions".format(len(txn_info_list)))
        except Exception as e:
            print("Could not send from {} to {}: {}".format(
                src_acc.address0x, dest, e))
    nonce_now = nonces.get(src_addr, src_acc.get_nonce())
    # print("{}: created {} transactions; nonce went from {} to {}".format(src_acc.bech32_address, len(txn_info_list), orig_nonce, nonce_now))
    return txn_info_list, src_acc, nonce_now
Exemple #2
0
def iat_create_txns(src_acc, dest_accs, zils):
    # Clear any cached sessions. This is needed to ensure multiple processes
    # don't try to reuse the same TCP connection, which would lead to havoc
    LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0)
    chain.set_active_chain(LocalNet)
    src_acc = Account(private_key=src_acc.private_key)

    txn_info_list = []
    src_addr = src_acc.bech32_address
    orig_nonce = nonces.get(src_addr, src_acc.get_nonce())
    for dest_acc in dest_accs:
        try:
            dest = dest_acc.bech32_address
            txn_info = src_acc.transfer(to_addr=dest,
                                        zils=zils,
                                        nonce=new_nonce(src_acc),
                                        gas_price=100)
            txn_info_list.append(txn_info)
            print(json.dumps(src_acc.last_params), file=sys.stderr)
            print("Created {} transactions".format(len(txn_info_list)))
        except Exception as e:
            print("Could not send from {} to {}: {}".format(src_addr, dest, e))

    nonce_now = nonces.get(src_addr, src_acc.get_nonce())
    # print("{}: created {} transactions; nonce went from {} to {}".format(src_acc.bech32_address, len(txn_info_list), orig_nonce, nonce_now))
    return txn_info_list, src_acc, nonce_now
Exemple #3
0
    def test_balance(self):
        account = Account(address="b50c2404e699fd985f71b2c3f032059f13d6543b")

        balance = account.get_balance()
        print("balance", balance)
        assert balance > 0

        nonce = account.get_nonce()
        print("nonce", nonce)
        assert nonce >= 0

        account2 = Account(address="b50c2404e699fd985f71b2c3f032059f13d65432")
        balance = account2.get_balance()
        print("balance", balance)
        assert balance == 0

        account3 = Account.from_keystore("zxcvbnm,", path_join("crypto", "zilliqa_keystore.json"))
        balance = account3.get_balance()
        print("balance", balance)
        assert balance > 0
Exemple #4
0
def get_chain_nonce(sender_pubkey):
    acc = Account(public_key=sender_pubkey)
    return acc.get_nonce()