output = sys.argv[4] input = sys.argv[5] all_users = [] with open(input, 'r') as f: for line in f: line = line.rstrip('\n') segments = line.split(',') u = { 'private_key': segments[0], 'address': segments[1], 'kitty': segments[2], } all_users.append(u) cli = Cli(HTTPProvider(frontend)) compiled_sol = compile_contracts('./contract') kitty_core = compiled_sol['./contract/KittyCore.sol:KittyCore'] kitty_core_contract = cli.eth.contract( abi=kitty_core['abi'], address=kitty_core_address, ) num_per_batch = 1000 lines = [] def make_one_batch(i): users = all_users[i * 2000:(i + 1) * 2000] for i in range(num_per_batch):
from utils import wait_for_receipts # frontend = 'http://localhost:8080' # private_key = 'cfac4f5fa828072ba8313b0686f02f576fa0fc8caba947569429e88968577865' frontend = sys.argv[1] private_key = sys.argv[2] compiled_sol = compile_files( ['./contract/MainService.sol', './contract/ConcurrentLibInterface.sol'], output_values=['abi', 'bin']) storage_svc = compiled_sol['./contract/MainService.sol:StorageService'] computing_svc = compiled_sol['./contract/MainService.sol:ComputingService'] main_svc = compiled_sol['./contract/MainService.sol:MainService'] cli = Cli(HTTPProvider(frontend)) storage_svc_contract = cli.eth.contract(abi=storage_svc['abi'], bytecode=storage_svc['bin']) computing_svc_contract = cli.eth.contract(abi=computing_svc['abi'], bytecode=computing_svc['bin']) main_svc_contract = cli.eth.contract(abi=main_svc['abi'], bytecode=main_svc['bin']) account = Account(private_key) raw_tx, tx_hash = account.sign( storage_svc_contract.constructor().buildTransaction({ 'nonce': 1, 'gas': 1000000000, 'gasPrice': 1, })) cli.sendTransactions({tx_hash: raw_tx})
contract Example { uint256 value = 0; constructor(uint256 n) public { value = n; } function func1(uint256 n) public { value = n; } } ''' compiled_sol = compile_source(source) _, contract_interface = compiled_sol.popitem() cli = Cli(HTTPProvider("http://localhost:8080")) example_contract = cli.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin']) tx = example_contract.constructor(1).buildTransaction({ 'nonce': 1, 'gas': 100000, 'gasPrice': 100, }) print(tx) account = Account( "cfac4f5fa828072ba8313b0686f02f576fa0fc8caba947569429e88968577865") raw_tx, tx_hash = account.sign(tx) # print("raw_tx = {}, tx_hash = {}".format(raw_tx, tx_hash))
import sys sys.path.append('../../..') from ammolite import (Cli, HTTPProvider, Account) import time cli = Cli(HTTPProvider('http://192.168.1.111:8080')) acc_from = Account('316b4cb5409a7c8998c04ad81ffb5f771c70ae7305cbd976845c27320aa2fb36') to_address1 = 'd024a83F83394B90AA2db581250Bc00B0B0f414a' to_address2 = 'd7cB260c7658589fe68789F2d678e1e85F7e4831' origin_balance_from = cli.getBalance(acc_from.address()) origin_balance_to1 = cli.getBalance(to_address1) origin_balance_to2 = cli.getBalance(to_address2) print('Before transfer:') print(f'\tBalance of {acc_from.address()}: {origin_balance_from}') print(f'\tBalance of {to_address1}: {origin_balance_to1}') print(f'\tBalance of {to_address2}: {origin_balance_to2}') raw_tx1, tx_hash1 = acc_from.sign({ 'nonce': 1, 'value': origin_balance_from - 21000, 'gas': 21000, 'gasPrice': 1, 'data': b'', 'to': bytearray.fromhex(to_address1) }) raw_tx2, tx_hash2 = acc_from.sign({ 'nonce': 2, 'value': origin_balance_from - 21000, 'gas': 21000,
import sys sys.path.append('../../..') from ammolite import (Cli, HTTPProvider) from rich.progress import Progress frontend = sys.argv[1] input = sys.argv[2] cli = Cli(HTTPProvider(frontend)) txs = {} with open(input, 'r') as f: print("Loading...") for line in f: line = line.rstrip('\n') if len(line) == 0: continue segments = line.split(',') txs[bytes(bytearray.fromhex(segments[1]))] = bytes( bytearray.fromhex(segments[0])) with Progress() as progress: task = progress.add_task("Sending...", total=len(txs)) batch = {} n = 0 for h in txs.keys(): batch[h] = txs[h] if len(batch) == 1000: cli.sendTransactions(batch) progress.update(task, advance=len(batch))
get_keys_by_weights(private_keys, config['test_case_weights'], 'sale_auction'), sale_auction_keys) write_private_keys( get_keys_by_weights(private_keys, config['test_case_weights'], 'siring_auction_creator'), siring_auction_creator_keys) write_private_keys( get_keys_by_weights(private_keys, config['test_case_weights'], 'siring_auction_bidder'), siring_auction_bidder_keys) write_private_keys( get_keys_by_weights(private_keys, config['test_case_weights'], 'kitty_raiser'), kitty_raiser_keys) write_private_keys( get_keys_by_weights(private_keys, config['test_case_weights'], 'kitties_exchanger'), kitty_exchanger_keys) cli = Cli(HTTPProvider(frontend)) kitty_core_contract = cli.eth.contract(abi=kitty_core['abi'], bytecode=kitty_core['bin']) # 1. Deploy KittyCore. ceo = Account(ceo_private_key) coo = Account(coo_private_key) cfo = Account(cfo_private_key) raw_tx, tx_hash = ceo.sign(kitty_core_contract.constructor().buildTransaction({ 'nonce': 1, 'gas': 10000000000, 'gasPrice': 1,
import sys import time sys.path.append('../') from ammolite import (Cli, HTTPProvider, Account) frontend = sys.argv[1] #cli = Cli(HTTPProvider("http://192.168.1.111:8080")) cli = Cli(HTTPProvider("http://" + frontend)) willQuery = True blockHeight = 0 queryCount = 0 while willQuery: block = cli.getBlock(-1) print(block['height']) if blockHeight > 0 and block['height'] > blockHeight: willQuery = False print('Cluster is runing.....') else: blockHeight = block['height'] queryCount = queryCount + 1 if queryCount > 5: break time.sleep(5) if willQuery: print('Cluster status error, please contact system administrator.....')
from rich.console import Console sol_dir = sys.argv[1] frontend = sys.argv[2] owner_key = sys.argv[3] sols = [] for root, _, files in os.walk(sol_dir): for f in files: if f.endswith('.sol'): sols.append(os.path.join(root, f)) compiled_sols = compile_files(sols, output_values = ['abi', 'bin']) ds_token = compiled_sols[sol_dir + 'token.sol:DSToken'] cli = Cli(HTTPProvider(frontend)) ds_token_contract = cli.eth.contract( abi = ds_token['abi'], bytecode = ds_token['bin'], ) contract_owner = Account(owner_key) console = Console() with console.status('[bold green]Working on tasks...') as status: raw_tx, tx_hash = contract_owner.sign(ds_token_contract.constructor(b'DST').buildTransaction({ 'nonce': 1, 'gas': 10000000000, 'gasPrice': 1, })) #print(tx_hash.hex())
for b in blocks: if b['timestamp'] + 60 < now: continue remains.append(b) num_txs = 0 for b in remains: if b['transactions'] is None or len(b['transactions']) == 0: continue num_txs += len(b['transactions']) return remains, num_txs / 60 frontend = sys.argv[1] cli = Cli(HTTPProvider(frontend)) block = cli.getBlock(-1) height = block['height'] blocks_within_1m = [block] console = Console() max_tps = 0 def create_table(blocks, tps, max_tps) -> Table: table = Table() table.add_column(" Height", justify="right") table.add_column("Transactions", justify="right") table.title = 'TPS: {}(MAX) / {}(1m AVG)'.format(int(max_tps), int(tps)) n = min(5, len(blocks))
import sys sys.path.append('../../..') import time, os from solcx import compile_files from ammolite import (Cli, HTTPProvider, Account) sources = [] for root, _, files in os.walk('./contract'): for file in files: if file.endswith('.sol'): sources.append(os.path.join(root, file)) cli = Cli(HTTPProvider('http://192.168.1.111:8080')) compiled_sol = compile_files(sources, output_values=['abi', 'bin']) kitty_core = compiled_sol['./contract/KittyCore.sol:KittyCore'] kitty_core_contract = cli.eth.contract( abi=kitty_core['abi'], address='b1e0e9e68297aae01347f6ce0ff21d5f72d3fa0f', ) coo_private_key = '2289ae919f03075448d567c9c4a22846ce3711731c895f1bea572cef25bb346f' user_private_key = 'd9815a0fa4f31172530f17a6ae64bf5f00a3a651f3d6476146d2c62ae5527dc4' coo = Account(coo_private_key) user1 = Account(user_private_key) user2_address = '230DCCC4660dcBeCb8A6AEA1C713eE7A04B35cAD' raw_tx, tx_hash = coo.sign( kitty_core_contract.functions.createPromoKitty( 0, user1.address()).buildTransaction({