Exemplo n.º 1
0
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))

cli.sendTransactions({tx_hash: raw_tx})
receipt = cli.getTransactionReceipt(tx_hash)
example_contract.setAddress(receipt['contractAddress'])
tx = example_contract.functions.func1(2).buildTransaction({
    'nonce': 2,
    'gas': 200000,
    'gasPrice': 100,
})
raw_tx, tx_hash = account.sign(tx)
cli.sendTransactions({tx_hash: raw_tx})

balance = cli.getBalance("1234567890123456789012345678901234567890", height=1)
print('balance = {}'.format(balance))

receipt = cli.getTransactionReceipt("1234567890123456789012345678901234567890")
print('receipt = {}'.format(receipt))
Exemplo n.º 2
0
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))
            n += len(batch)
            #print('sending {} of {}'.format(n, len(txs)))
            batch = {}

    if len(batch) != 0:
        cli.sendTransactions(batch)
        progress.update(task, advance=len(batch))
Exemplo n.º 3
0
    '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,
    'gasPrice': 1,
    'data': b'',
    'to': bytearray.fromhex(to_address2)
})
cli.sendTransactions({tx_hash1: raw_tx1, tx_hash2: raw_tx2})

while True:
    receipts = cli.getTransactionReceipts([tx_hash1, tx_hash2])
    if receipts is None or len(receipts) != 2:
        time.sleep(1)
        continue
    break

new_balance_from = cli.getBalance(acc_from.address())
new_balance_to1 = cli.getBalance(to_address1)
new_balance_to2 = cli.getBalance(to_address2)
print('After transfer:')
print(f'\tBalance of {acc_from.address()}: {new_balance_from}')
print(f'\tBalance of {to_address1}: {new_balance_to1}')
print(f'\tBalance of {to_address2}: {new_balance_to2}')
    print('batch_start = {}, batch_end = {}'.format(batch_start, batch_end))

    txs = {}
    hashes = []
    for j in range(batch_start, batch_end):
        raw_tx, tx_hash = coo.sign(
            kitty_core_contract.functions.createPromoKitty(
                j, addresses[j]).buildTransaction({
                    'nonce': j,
                    'gas': 1000000,
                    'gasPrice': 1,
                }))
        txs[tx_hash] = raw_tx
        hashes.append(tx_hash)

    cli.sendTransactions(txs)
    candidates = []
    receipts = wait_for_receipts(cli, hashes)
    for j in range(len(hashes)):
        receipt = receipts[hashes[j]]
        if receipt['status'] != 1:
            assert False

        processed_receipt = kitty_core_contract.processReceipt(receipt)
        if 'Birth' not in processed_receipt:
            assert False

        candidates.append({
            'private_key': private_keys[batch_start + j],
            'address': addresses[batch_start + j],
            'kitty': processed_receipt['Birth']['kittyId'],
Exemplo n.º 5
0
# 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,
}))

cli.sendTransactions({tx_hash: raw_tx})
receipts = wait_for_receipts(cli, [tx_hash])
check_receipts(receipts)
kitty_core_address = receipts[tx_hash]['contractAddress']
kitty_core_contract.setAddress(kitty_core_address)

# 2. Deploy SaleClockAuction, SiringAuction and GeneScience.
sale_auction_contract = cli.eth.contract(abi=sale_auction['abi'],
                                         bytecode=sale_auction['bin'])
raw_tx1, tx_hash1 = ceo.sign(
    sale_auction_contract.constructor(kitty_core_address,
                                      100).buildTransaction({
                                          'nonce': 2,
                                          'gas': 10000000000,
                                          'gasPrice': 1,
                                      }))
Exemplo n.º 6
0
            computing_svc_address,
            10).buildTransaction({
                'nonce': offset + i,
                'gas': 1000000,
                'gasPrice': 1,
                'value': 10,
            })
        raw_tx, tx_hash = account.sign(tx)
        txs.append([tx_hash, raw_tx])
    if offset == 0:
        for i in range(10):
            print(txs[i][0].hex())
    return txs


while True:
    if len(buf) < buf_size:
        txs = create_new_txs(len(buf))
        buf.extend(txs)
    else:
        if index + batch_size >= buf_size:
            index = 0
    txs = buf[index:index + batch_size]
    index += batch_size

    transactions = {}
    for tx in txs:
        transactions[tx[0]] = tx[1]
    cli.sendTransactions(transactions)
    time.sleep(3)