Beispiel #1
0
 def __init__(self, chain, privkey, transport, discovery):
     self.chain = chain
     self.privkey = privkey
     self.address = privtoaddr(privkey)
     self.protocol = RaidenProtocol(transport, discovery, self)
     self.assetmanagers = dict()
     self.api = RaidenAPI(self)
Beispiel #2
0
def privtoaddr(key):
    """Derive an address from a private key.

    KEY must either be a raw private key in hex encoding or a WIF string.

    The resulting address will be printed in hex encoding.
    """
    click.echo(utils.privtoaddr(encode_privkey(key, 'hex')))
Beispiel #3
0
 def __init__(self, chain, privkey, transport, discovery):
     self.chain = chain
     self.privkey = privkey
     self.address = privtoaddr(privkey)
     self.protocol = RaidenProtocol(transport, discovery, self)
     transport.protocol = self.protocol
     self.assetmanagers = dict()
     self.api = RaidenAPI(self)
Beispiel #4
0
def privtoaddr(key):
    """Derive an address from a private key.

    KEY must either be a raw private key in hex encoding or a WIF string.

    The resulting address will be printed in hex encoding.
    """
    click.echo(utils.privtoaddr(encode_privkey(key, 'hex')))
Beispiel #5
0
def quicktx(client, gasprice, startgas, to, value, data, key):
    """Create and finalize a transaction.

    This command is a shortcut that chains getnonce, mktx, signtx, and applytx.
    It returns the server's response.
    """
    encoded_key = encode_privkey(key, 'hex')
    nonce = int(client.getaccount(utils.privtoaddr(encoded_key))['nonce'])
    tx = Transaction(nonce, gasprice, startgas, to, value, str(data))
    tx.sign(encode_privkey(key, 'hex'))
    pecho(client.applytx(tx))
Beispiel #6
0
def quicktx(client, gasprice, startgas, to, value, data, key):
    """Create and finalize a transaction.

    This command is a shortcut that chains getnonce, mktx, signtx, and applytx.
    It returns the server's response.
    """
    encoded_key = encode_privkey(key, 'hex')
    nonce = int(client.getaccount(utils.privtoaddr(encoded_key))['nonce'])
    tx = Transaction(nonce, gasprice, startgas, to, value, str(data))
    tx.sign(encode_privkey(key, 'hex'))
    pecho(client.applytx(tx))
Beispiel #7
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})
Beispiel #8
0
def mk_keys_addr():
    if len(sys.argv) == 2:
        path = sys.argv[1]
    else:
        path = os.path.join(sys.argv[1], "node" + sys.argv[2])
    dump_path = os.path.join(path, "privkey")
    privkey = PrivateKey()
    sec_key = privkey.serialize()
    f = open(dump_path, "w")
    f.write(sec_key)
    f.close()
    auth_path = os.path.join(sys.argv[1], "authorities")
    authority = encode_hex(privtoaddr(decode_hex(sec_key)))
    auth_file = open(auth_path, "a")
    auth_file.write("0x" + authority + "\n")
    auth_file.close()
Beispiel #9
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})
Beispiel #10
0
    def sign(self, key, network_id=None):
        if network_id is None:
            rawhash = sha3(rlp.encode(self, UnsignedBlock))
        else:
            assert 1 <= network_id < 2**63 - 18
            rlpdata = rlp.encode(
                rlp.infer_sedes(self).serialize(self)[:-3] +
                [network_id, b'', b''])
            rawhash = sha3(rlpdata)

        key = normalize_key(key)
        self.v, self.r, self.s = ecsign(rawhash, key)
        if network_id is not None:
            self.v += 8 + network_id * 2

        self._signer = privtoaddr(key)
        return self
Beispiel #11
0
#!/usr/bin/env python
import sys
import requests
import json
from common import make_pyethereum_avail
make_pyethereum_avail()
import utils
import transactions
from apiserver import base_url
base_url = "http://127.0.0.1:30203" + base_url


k = utils.sha3('heiko')
v = utils.privtoaddr(k)
k2 = utils.sha3('horse')
v2 = utils.privtoaddr(k2)

# Give tx2 some money
# nonce,gasprice,startgas,to,value,data,v,r,s
value = 10 ** 16
print value, 'from', v, 'to', v2

nonce = int(sys.argv[1])

tx = transactions.Transaction(
    nonce, gasprice=10 ** 12, startgas=10000, to=v2, value=10 ** 16, data='').sign(k)

data = tx.hex_serialize()

url = base_url + '/transactions/'
print 'PUT', url, data
Beispiel #12
0
def privtoaddr(x):
    if len(x) == 64:
        x = x.decode('hex')
    return utils.privtoaddr(x)
 def sign(self, key):
     rawhash = utils.sha3(self.serialize(False))
     self.v, self.r, self.s = ecdsa_raw_sign(rawhash, key)
     self.sender = utils.privtoaddr(key)
     return self
Beispiel #14
0
import serpent
import processblock as pb
import blocks as b
import transactions as t
import utils as u
import sys

k = u.sha3('cow')
v = u.privtoaddr(k)

k2 = u.sha3('horse')
v2 = u.privtoaddr(k2)

print "Starting boring transfer test"
blk = b.Block.genesis({ v: 10**18 })
# Give tx2 some money
tx = t.Transaction(0,10**16,10**12,1000,v2,'').sign(k)
pb.apply_tx(blk,tx)
print "New balance of v1: ", blk.get_balance(v)
print "New balance of v2: ", blk.get_balance(v2)

print "Starting namecoin tests"
blk = b.Block.genesis({ v: 10**18 })
scode1 = '''
if !contract.storage[msg.data[0]]:
    contract.storage[msg.data[0]] = msg.data[1]
    return(1)
else:
    return(0)
'''
code1 = serpent.compile(scode1)
Beispiel #15
0
import serpent
import processblock as pb
import blocks as b
import transactions as t
import utils as u
import sys

k = u.sha3('cow')
v = u.privtoaddr(k)

k2 = u.sha3('horse')
v2 = u.privtoaddr(k2)

print "Starting boring transfer test"
blk = b.Block.genesis({v: 10**18})
# Give tx2 some money
tx = t.Transaction(0, 10**16, 10**12, 1000, v2, '').sign(k)
pb.apply_tx(blk, tx)
print "New balance of v1: ", blk.get_balance(v)
print "New balance of v2: ", blk.get_balance(v2)

print "Starting namecoin tests"
blk = b.Block.genesis({v: 10**18})
scode1 = '''
if !contract.storage[msg.data[0]]:
    contract.storage[msg.data[0]] = msg.data[1]
    return(1)
else:
    return(0)
'''
code1 = serpent.compile(scode1)
Beispiel #16
0
def privtoaddr(x):
    if len(x) == 64:
        x = x.decode('hex')
    return utils.privtoaddr(x)
Beispiel #17
0
 def sign(self, key):
     rawhash = utils.sha3(self.serialize(False))
     self.v, self.r, self.s = ecdsa_raw_sign(rawhash, key)
     self.sender = utils.privtoaddr(key)
     return self
from db import DB
import utils
import rlp
import blocks
import processblock
from transactions import Transaction
from bitcoin import ecdsa_raw_recover, ecdsa_raw_verify
import serpent
import sys

logger = logging.getLogger(__name__)

rlp_hash_hex = lambda data: utils.sha3(rlp.encode(data)).encode('hex')

privkey = utils.sha3('brain wallet')
self_addr = utils.privtoaddr(privkey)

def byte_arrays_to_string(arr):
    stri = ''
    for d in arr:
        stri += string.join(map(chr, d), '')
    return stri

def byte_array_to_string(arr):
    return string.join(map(chr, arr), '')

class Miner():

    """
    Mines on the current head
    Stores received transactions
Beispiel #19
0
import utils
from transactions import Transaction
import rlp

#key = utils.random_privkey()
key = '2ff2ea218ea9ee91ddd651065e63551ee14cf82ec70a2ca0fa71923da10dd97c'
addr = utils.privtoaddr(key)
print "SENDER:", addr.encode('hex')

# Category 1&2

#tx = Transaction(5,1,'54450450e24286143a35686ad77a7c851ada01a0', 1, '192.152.0.0/16')
#tx = Transaction(5,1,'54450450e24286143a35686ad77a7c851ada01a0', 2, '2001:db8::1/16')

# Category 2
'''tx = Transaction(5,2,'54450450e24286143a35686ad77a7c851ada01a0', 1, '192.152.0.0/16', 
    [1, '1.1.1.1', '54dbb737eac5007103e729e9ab7ce64a6850a310',
     1, '2.2.2.2', '89b44e4d3c81ede05d0f5de8d1a68f754d73d997',
     2, '2001:db8:a0b:12f0::1', '3a1e02d9ea25349c47fe2e94f4265cd261c5c7ca'])'''

tx = Transaction(
    5, 2, '54450450e24286143a35686ad77a7c851ada01a0', 2, '2001:db8::1/16', [
        1, '1.1.1.1', '54dbb737eac5007103e729e9ab7ce64a6850a310', 2,
        '2001:cdba::3257:9652', '89b44e4d3c81ede05d0f5de8d1a68f754d73d997', 1,
        '3.3.3.3', '3a1e02d9ea25349c47fe2e94f4265cd261c5c7ca'
    ])

# Category 3
'''tx = Transaction(5,3,'54450450e24286143a35686ad77a7c851ada01a0', 1, '192.152.0.0/16', 
    [2, '2001:cdba:9abc:5678::', 20, 230,
     1, '5.5.5.5', 45, 50])'''
Beispiel #20
0
#!/usr/bin/env python
import sys
import requests
import json
from common import make_pyethereum_avail
make_pyethereum_avail()
import utils
import transactions
from apiserver import base_url
base_url = "http://127.0.0.1:30203" + base_url

k = utils.sha3('heiko')
v = utils.privtoaddr(k)
k2 = utils.sha3('horse')
v2 = utils.privtoaddr(k2)

# Give tx2 some money
# nonce,gasprice,startgas,to,value,data,v,r,s
value = 10**16
print value, 'from', v, 'to', v2

nonce = int(sys.argv[1])

tx = transactions.Transaction(nonce,
                              gasprice=10**12,
                              startgas=10000,
                              to=v2,
                              value=10**16,
                              data='').sign(k)

data = tx.hex_serialize()
Beispiel #21
0
from db import DB
import utils
import rlp
import blocks
import processblock
from transactions import Transaction
from bitcoin import ecdsa_raw_recover, ecdsa_raw_verify
import serpent
import sys

logger = logging.getLogger(__name__)

rlp_hash_hex = lambda data: utils.sha3(rlp.encode(data)).encode('hex')

privkey = utils.sha3('brain wallet')
self_addr = utils.privtoaddr(privkey)


def byte_arrays_to_string(arr):
    stri = ''
    for d in arr:
        stri += string.join(map(chr, d), '')
    return stri


def byte_array_to_string(arr):
    return string.join(map(chr, arr), '')


class Miner():
    """
Beispiel #22
0
 def sign(self, key):
     rawhash = sha3(rlp.encode(self.serialize(False)))
     self.v, self.r, self.s = ecdsa_raw_sign(rawhash, key)
     self.sender = privtoaddr(key)
     return self
Beispiel #23
0
 def sign(self, key):
     rawhash = sha3(rlp.encode(self.serialize(False)))
     self.v, self.r, self.s = ecdsa_raw_sign(rawhash, key)
     self.sender = privtoaddr(key)
     return self