Beispiel #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
Beispiel #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
Beispiel #3
0
def main():
    args = parse_arguments()
    pprint(args)

    frequency = int(args['frequency']) * 60

    # Set active chain
    chain.set_active_chain(
        chain.BlockChain(args['apiurl'], version=65537, network_id=1))

    while True:
        print('Check started at: ' + str(datetime.datetime.now()))

        global ERROR_MESSAGE
        ERROR_MESSAGE = ''

        try:
            test_txn(args)
        except Exception as e:
            ERROR_MESSAGE = '[' + os.path.basename(
                __file__) + '] Error: ' + str(e)

        if (ERROR_MESSAGE != ''):
            print(ERROR_MESSAGE)
            if args['webhook'] != '':
                send_report(ERROR_MESSAGE, args['webhook'])

        sys.stdout.flush()

        if frequency == 0:
            break

        time.sleep(frequency)
Beispiel #4
0
def contract_create_txns(contract, src_accs, method):
    # 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)
    contract = Contract.load_from_address(contract.address, load_state=False)

    txn_info_list = []
    for src_acc in src_accs:
        contract.account = src_acc
        src_addr = src_acc.bech32_address
        try:
            txn_info = None
            if method == 'registerOwnership':
                txn_info = contract.call(method="registerOwnership",
                                         params=[
                                             Contract.value_dict(
                                                 "ipfs_cid", "String",
                                                 src_addr)
                                         ],
                                         nonce=1,
                                         confirm=False)
            elif method == 'configureResolver':
                label = src_addr
                txn_info = contract.call(
                    method="configureResolver",
                    params=[
                        Contract.value_dict("recordOwner", "ByStr20",
                                            src_acc.address0x),
                        Contract.value_dict("node", "ByStr32",
                                            parentLabelToNode(rootNode,
                                                              label)),
                        Contract.value_dict("resolver", "ByStr20",
                                            src_acc.address0x)
                    ],
                    nonce=1,
                    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("Crowdfund exception: {}".format(e))
    # nonce_now = nonces.get(src_addr, src_acc.get_nonce())
    return txn_info_list, src_acc, None
Beispiel #5
0
def nft_create_txns(contract, src_acc, dest_accs, type='mint'):
    # 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
    for dest_acc in dest_accs:
        try:
            src = src_acc.address0x
            dest = dest_acc.address0x
            txn_info = None
            if type == 'mint':
                txn_info = contract.call(
                    method="mint",
                    params=[
                        Contract.value_dict("to", "ByStr20", dest),
                        Contract.value_dict("tokenId", "Uint256",
                                            get_token_id(dest))
                    ],
                    nonce=1,
                    confirm=False)
            elif type == 'transfer':
                txn_info = contract.call(
                    method="transfer",
                    params=[
                        Contract.value_dict("tokenOwner", "ByStr20", src),
                        Contract.value_dict("to", "ByStr20", dest),
                        Contract.value_dict("tokenId", "Uint256",
                                            get_token_id(src))
                    ],
                    nonce=1,
                    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))
    return txn_info_list, src_acc, None
Beispiel #6
0
def contract_create_multidest_txns(contract, src_acc, dest_accs, method):
    # 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
    for dest_acc in dest_accs:
        try:
            dest = dest_acc.address0x
            txn_info = None
            if method == 'bestow':
                label = dest_acc.bech32_address
                txn_info = contract.call(
                    method="bestow",
                    params=[
                        Contract.value_dict("node", "ByStr32",
                                            parentLabelToNode(rootNode,
                                                              label)),
                        Contract.value_dict("label", "String", label),
                        Contract.value_dict("owner", "ByStr20", dest),
                        Contract.value_dict(
                            "resolver", "ByStr20",
                            "0x0000000000000000000000000000000000000000")
                    ],
                    nonce=1,
                    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))
    return txn_info_list, src_acc, None
Beispiel #7
0
def crowd_create_txns(contract, src_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)
    contract = Contract.load_from_address(contract.address, load_state=False)

    txn_info_list = []
    for src_acc in src_accs:
        contract.account = src_acc
        src_addr = src_acc.bech32_address
        try:
            txn_info = contract.call(method="Donate",
                                     params=[],
                                     zils=amount,
                                     nonce=1,
                                     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("Crowdfund exception: {}".format(e))
    # nonce_now = nonces.get(src_addr, src_acc.get_nonce())
    return txn_info_list, src_acc, None
Beispiel #8
0
#!/usr/bin/env python3
from pprint import pprint

from pyzil.zilliqa.api import ZilliqaAPI, APIError
from pyzil.zilliqa import chain
from pyzil.account import Account
import json
import sys
import datetime
import math
from concurrent import futures
from concurrent.futures import ProcessPoolExecutor

API_ENDPOINT = "http://localhost:4201"

LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0)
chain.set_active_chain(LocalNet)

MAX_NUM_WORKERS = 100
TARGET_BUCKET_SIZE = 1000
GET_CHAIN_NONCE = False

nonces = {}

def partition(list, num_buckets):
    part = {}
    for b in range(num_buckets):
        part[b] = []

    for i, val in enumerate(list):
        part[i % num_buckets].append(val)