Exemple #1
0
def mkcontract(nonce, gasprice, startgas, value, code):
    """Assemble a contract creating transaction.

    The result is the hex representation of the transaction in RLP encoding.
    """
    ct = contract(nonce, gasprice, startgas, value, str(code))
    click.echo(ct.hex_serialize(False))
Exemple #2
0
def mkcontract(nonce, gasprice, startgas, value, code):
    """Assemble a contract creating transaction.

    The result is the hex representation of the transaction in RLP encoding.
    """
    ct = contract(nonce, gasprice, startgas, value, str(code))
    click.echo(ct.hex_serialize(False))
Exemple #3
0
def quickcontract(client, gasprice, startgas, value, code, key):
    """Create and finalize a contract.

    This command is a shortcut that chains getnonce, mkcontract, signtx, and
    applytx. In addition to the server's response, it returns the address of
    the newly created contract.
    """
    encoded_key = encode_privkey(key, 'hex')
    sender = utils.privtoaddr(encoded_key)
    nonce = int(client.getaccount(sender)['nonce'])
    tx = contract(nonce, gasprice, startgas, value, str(code))
    tx.sign(encoded_key)
    response = client.applytx(tx)
    pecho({'address': tx.contract_address(), 'transaction': response})
Exemple #4
0
def quickcontract(client, gasprice, startgas, value, code, key):
    """Create and finalize a contract.

    This command is a shortcut that chains getnonce, mkcontract, signtx, and
    applytx. In addition to the server's response, it returns the address of
    the newly created contract.
    """
    encoded_key = encode_privkey(key, 'hex')
    sender = utils.privtoaddr(encoded_key)
    nonce = int(client.getaccount(sender)['nonce'])
    tx = contract(nonce, gasprice, startgas, value, str(code))
    tx.sign(encoded_key)
    response = client.applytx(tx)
    pecho({
        'address': tx.contract_address(),
        'transaction': response})
Exemple #5
0
def contract(nonce, value, code):
    return transactions.contract(int(nonce), 10**12, 10000, int(value),
                                 code.decode('hex')).hex_serialize(False)
Exemple #6
0
def contract(nonce, gasprice, startgas, value, code):
    return transactions.contract(
        int(nonce), gasprice, startgas, int(value), code.decode('hex')
    ).hex_serialize(False)
Exemple #7
0
def contract(nonce, gasprice, startgas, value, code):
    return transactions.contract(
        int(nonce), gasprice, startgas, int(value), code.decode('hex')
    ).hex_serialize(False)
Exemple #8
0
assert blk.get_balance(v) == u.denoms.finney * 990
assert blk.get_balance(v2) == u.denoms.finney * 10

print("Starting namecoin tests")
blk = b.genesis({v: u.denoms.ether * 1})
scode1 = '''
if !contract.storage[msg.data[0]]:
    contract.storage[msg.data[0]] = msg.data[1]
    return(1)
else:
    return(0)
'''
code1 = serpent.compile(scode1)
# print("AST", serpent.rewrite(serpent.parse(scode1)))
# print("Assembly", serpent.compile_to_assembly(scode1))
tx1 = t.contract(0, gasprice, startgas, 0, code1).sign(k)
s, addr = pb.apply_tx(blk, tx1)
snapshot = blk.snapshot()
print("Contract address", addr)
tx2 = t.Transaction(1, gasprice, startgas, addr, 0,
                    serpent.encode_datalist(['george', 45]))
tx2.sign(k)
s, o = pb.apply_tx(blk, tx2)
print("Result of registering george:45: ", serpent.decode_datalist(o))
assert serpent.decode_datalist(o) == [1]
tx3 = t.Transaction(2, gasprice, startgas, addr, 0,
                    serpent.encode_datalist(['george', 20])).sign(k)
s, o = pb.apply_tx(blk, tx3)
print("Result of registering george:20: ", serpent.decode_datalist(o))
assert serpent.decode_datalist(o) == [0]
tx4 = t.Transaction(3, gasprice, startgas, addr, 0,
Exemple #9
0
assert blk.get_balance(v) == u.denoms.finney * 990
assert blk.get_balance(v2) == u.denoms.finney * 10

print("Starting namecoin tests")
blk = b.genesis({v: u.denoms.ether * 1})
scode1 = '''
if !contract.storage[msg.data[0]]:
    contract.storage[msg.data[0]] = msg.data[1]
    return(1)
else:
    return(0)
'''
code1 = serpent.compile(scode1)
# print("AST", serpent.rewrite(serpent.parse(scode1)))
# print("Assembly", serpent.compile_to_assembly(scode1))
tx1 = t.contract(0, gasprice, startgas, 0, code1).sign(k)
s, addr = pb.apply_tx(blk, tx1)
snapshot = blk.snapshot()
print("Contract address", addr)
tx2 = t.Transaction(1, gasprice, startgas, addr, 0, serpent.encode_datalist(['george', 45]))
tx2.sign(k)
s, o = pb.apply_tx(blk, tx2)
print("Result of registering george:45: ", serpent.decode_datalist(o))
assert serpent.decode_datalist(o) == [1]
tx3 = t.Transaction(2, gasprice, startgas, addr, 0, serpent.encode_datalist(['george', 20])).sign(k)
s, o = pb.apply_tx(blk, tx3)
print("Result of registering george:20: ", serpent.decode_datalist(o))
assert serpent.decode_datalist(o) == [0]
tx4 = t.Transaction(3, gasprice, startgas, addr, 0, serpent.encode_datalist(['harry', 60])).sign(k)
s, o = pb.apply_tx(blk, tx4)
print("Result of registering harry:60: ", serpent.decode_datalist(o))
Exemple #10
0
def contract(nonce, value, code):
    return transactions.contract(
        int(nonce), 10 ** 12, 10000, int(value), code.decode('hex')
    ).hex_serialize(False)