当前位置: 首页>>代码示例>>Python>>正文


Python blocks.genesis函数代码示例

本文整理汇总了Python中pyethereum.blocks.genesis函数的典型用法代码示例。如果您正苦于以下问题:Python genesis函数的具体用法?Python genesis怎么用?Python genesis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了genesis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_genesis_db

def test_genesis_db():
    k, v, k2, v2 = accounts()
    set_db()
    blk = blocks.genesis({v: utils.denoms.ether * 1})
    db_store(blk)
    blk2 = blocks.genesis({v: utils.denoms.ether * 1})
    blk3 = blocks.genesis()
    assert blk == blk2
    assert blk != blk3
    set_db()
    blk2 = blocks.genesis({v: utils.denoms.ether * 1})
    blk3 = blocks.genesis()
    assert blk == blk2
    assert blk != blk3
开发者ID:maieuto,项目名称:pyethereum,代码行数:14,代码来源:test_chain.py

示例2: test_genesis

def test_genesis():
    k, v, k2, v2 = accounts()
    set_db()
    blk = blocks.genesis({v: utils.denoms.ether * 1})
    db_store(blk)
    assert blk in set([blk])
    assert blk == blocks.Block.deserialize(blk.serialize())
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:7,代码来源:test_chain.py

示例3: test_namecoin

def test_namecoin():
    k, v, k2, v2 = accounts()

    blk = b.genesis({v: u.denoms.ether * 1})

    code1 = serpent.compile(namecoin_code)
    tx1 = t.contract(0, gasprice, startgas, 0, code1).sign(k)
    s, addr = pb.apply_transaction(blk, tx1)

    snapshot = blk.snapshot()

    # tx2
    tx2 = t.Transaction(1, gasprice, startgas, addr, 0,
                        serpent.encode_datalist(['george', 45]))
    tx2.sign(k)
    s, o = pb.apply_transaction(blk, tx2)
    assert serpent.decode_datalist(o) == [1]

    # tx3
    tx3 = t.Transaction(2, gasprice, startgas, addr, 0,
                        serpent.encode_datalist(['george', 20])).sign(k)
    s, o = pb.apply_transaction(blk, tx3)
    assert serpent.decode_datalist(o) == [0]

    # tx4
    tx4 = t.Transaction(3, gasprice, startgas, addr, 0,
                        serpent.encode_datalist(['harry', 60])).sign(k)
    s, o = pb.apply_transaction(blk, tx4)
    assert serpent.decode_datalist(o) == [1]

    blk.revert(snapshot)

    assert blk.to_dict()
    assert blk.to_dict()['state'][addr]['code']
开发者ID:origingod,项目名称:pyethereum,代码行数:34,代码来源:test_contracts.py

示例4: test_data_feeds

def test_data_feeds():
    k, v, k2, v2 = accounts()
    scode3 = '''
if !contract.storage[1000]:
    contract.storage[1000] = 1
    contract.storage[1001] = msg.sender
    return(0)
elif msg.sender == contract.storage[1001] and msg.datasize == 2:
    contract.storage[msg.data[0]] = msg.data[1]
    return(1)
else:
    return(contract.storage[msg.data[0]])
'''
    code3 = serpent.compile(scode3)
    logger.debug("AST", serpent.rewrite(serpent.parse(scode3)))
    blk = b.genesis({v: 10 ** 18, v2: 10 ** 18})
    tx10 = t.contract(0, gasprice, startgas, 0, code3).sign(k)
    s, addr = pb.apply_transaction(blk, tx10)
    tx11 = t.Transaction(1, gasprice, startgas, addr, 0, '').sign(k)
    s, o = pb.apply_transaction(blk, tx11)
    tx12 = t.Transaction(2, gasprice, startgas, addr, 0,
                         serpent.encode_datalist([500])).sign(k)
    s, o = pb.apply_transaction(blk, tx12)
    assert serpent.decode_datalist(o) == [0]
    tx13 = t.Transaction(3, gasprice, startgas, addr, 0,
                         serpent.encode_datalist([500, 726])).sign(k)
    s, o = pb.apply_transaction(blk, tx13)
    assert serpent.decode_datalist(o) == [1]
    tx14 = t.Transaction(4, gasprice, startgas, addr, 0,
                         serpent.encode_datalist([500])).sign(k)
    s, o = pb.apply_transaction(blk, tx14)
    assert serpent.decode_datalist(o) == [726]
    return blk, addr
开发者ID:origingod,项目名称:pyethereum,代码行数:33,代码来源:test_contracts.py

示例5: mkgenesis

def mkgenesis(*args, **kargs):
    "set INITIAL_DIFFICULTY to a value that is quickly minable"
    tmp = blocks.INITIAL_DIFFICULTY
    blocks.INITIAL_DIFFICULTY = 2 ** 16
    g = blocks.genesis(*args, **kargs)
    blocks.INITIAL_DIFFICULTY = tmp
    return g
开发者ID:ebuchman,项目名称:daoist_protocol,代码行数:7,代码来源:test_chain.py

示例6: test_genesis_state_root

def test_genesis_state_root(genesis_fixture):
    # https://ethereum.etherpad.mozilla.org/12
    set_db()
    genesis = blocks.genesis()
    for k, v in blocks.GENESIS_INITIAL_ALLOC.items():
        assert genesis.get_balance(k) == v
    assert genesis.state_root.encode(
        'hex') == genesis_fixture['genesis_state_root']
开发者ID:maieuto,项目名称:pyethereum,代码行数:8,代码来源:test_chain.py

示例7: test_genesis_state_root

def test_genesis_state_root():
    # https://ethereum.etherpad.mozilla.org/12
    set_db()
    genesis = blocks.genesis()
    for k, v in blocks.GENESIS_INITIAL_ALLOC.items():
        assert genesis.get_balance(k) == v
    assert genesis.state_root.encode(
        'hex') == CPP_PoC5_GENESIS_STATE_ROOT_HEX_HASH
开发者ID:ebuchman,项目名称:daoist_protocol,代码行数:8,代码来源:test_chain.py

示例8: test_block_serialization_other_db

def test_block_serialization_other_db():
    k, v, k2, v2 = accounts()
    # mine two blocks
    set_db()
    a_blk = blocks.genesis()
    db_store(a_blk)
    a_blk2 = mine_next_block(a_blk)
    db_store(a_blk2)

    # receive in other db
    set_db()
    b_blk = blocks.genesis()
    assert b_blk == a_blk
    db_store(b_blk)
    b_blk2 = b_blk.deserialize(a_blk2.serialize())
    assert a_blk2.hex_hash() == b_blk2.hex_hash()
    db_store(b_blk2)
    assert a_blk2.hex_hash() == b_blk2.hex_hash()
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:18,代码来源:test_chain.py

示例9: _recv_Status

def _recv_Status(self, data):
    #old_status(self, data)
    h = blocks.genesis().hash
    print('Status RECEIVED')
    head_hash = data[3]
    print "head_hash", head_hash.encode('hex')
    print "head difficulty", idec(data[2])
    assert not len(collected_blocks)
    self.send_GetBlockHashes(head_hash, NUM_BLOCKS_PER_REQUEST)
开发者ID:Bitcoinzie,项目名称:pyethereum,代码行数:9,代码来源:blockfetcherpatch.py

示例10: test_genesis_hash

def test_genesis_hash(genesis_fixture):
    set_db()
    genesis = blocks.genesis()
    """
    YP: https://raw.githubusercontent.com/ethereum/latexpaper/master/Paper.tex
    0256 , SHA3RLP(), 0160 , stateRoot, 0256 , 2**22 , 0, 0, 1000000, 0, 0, (),
    SHA3(42), (), ()

    Where 0256 refers to the parent and state and transaction root hashes,
    a 256-bit hash which is all zeroes;
    0160 refers to the coinbase address,
    a 160-bit hash which is all zeroes;
    2**22 refers to the difficulty;
    0 refers to the timestamp (the Unix epoch);
    () refers to the extradata and the sequences of both uncles and
    transactions, all empty.
    SHA3(42) refers to the SHA3 hash of a byte array of length one whose first
    and only byte is of value 42.
    SHA3RLP() values refer to the hashes of the transaction and uncle lists
    in RLP
    both empty.
    The proof-of-concept series include a development premine, making the state
    root hash some value stateRoot. The latest documentation should be
    consulted for the value of the state root.
    """

    h256 = '\00' * 32
    sr = genesis_fixture['genesis_state_root'].decode('hex')
    genesis_block_defaults = [
        ["prevhash", "bin", h256],  # h256()
        ["uncles_hash", "bin", utils.sha3(rlp.encode([]))],  # sha3EmptyList
        ["coinbase", "addr", "0" * 40],  # h160()
        ["state_root", "trie_root", sr],  # stateRoot
        ["tx_list_root", "trie_root", trie.BLANK_ROOT],  # h256()
        ["difficulty", "int", 2 ** 22],  # c_genesisDifficulty
        ["number", "int", 0],  # 0
        ["min_gas_price", "int", 0],  # 0
        ["gas_limit", "int", 10 ** 6],  # 10**6 for genesis
        ["gas_used", "int", 0],  # 0
        ["timestamp", "int", 0],  # 0
        ["extra_data", "bin", ""],  # ""
        ["nonce", "bin", utils.sha3(chr(42))],  # sha3(bytes(1, 42));
    ]

    cpp_genesis_block = rlp.decode(
        genesis_fixture['genesis_rlp_hex'].decode('hex'))
    cpp_genesis_header = cpp_genesis_block[0]

    for i, (name, typ, genesis_default) in enumerate(genesis_block_defaults):
        assert utils.decoders[typ](cpp_genesis_header[i]) == genesis_default
        assert getattr(genesis, name) == genesis_default

    assert genesis.hex_hash() == genesis_fixture['genesis_hash']

    assert genesis.hex_hash() == utils.sha3(
        genesis_fixture['genesis_rlp_hex'].decode('hex')
    ).encode('hex')
开发者ID:maieuto,项目名称:pyethereum,代码行数:57,代码来源:test_chain.py

示例11: test_genesis_hash

def test_genesis_hash():
    set_db()
    genesis = blocks.genesis()
    """
    cpp: https://github.com/ethereum/cpp-ethereum/libethereum/BlockInfo.cpp#L64
    h256() << sha3EmptyList << h160() << stateRoot << h256() << c_genesisDifficulty << 0 << 0 << 1000000 << 0 << (uint)0 << string() << sha3(bytes(1, 42));

    PoC5 etherpad: https://ethereum.etherpad.mozilla.org/11
    Genesis block is: ( B32(0, 0, ...), B32(sha3(B())), B20(0, 0, ...), B32(stateRoot), B32(0, 0, ...), P(2^22), P(0), P(0), P(1000000), P(0), P(0) << B() << B32(sha3(B(42))) )

    Genesis hash: 69a7356a245f9dc5b865475ada5ee4e89b18f93c06503a9db3b3630e88e9fb4e

    YP: https://raw.githubusercontent.com/ethereum/latexpaper/master/Paper.tex
    0256 , SHA3RLP(), 0160 , stateRoot, 0256 , 2**22 , 0, 0, 1000000, 0, 0, (), SHA3(42), (), ()

    Where 0256 refers to the parent and state and transaction root hashes, 
    a 256-bit hash which is all zeroes; 
    0160 refers to the coinbase address, 
    a 160-bit hash which is all zeroes; 
    2**22 refers to the difficulty; 
    0 refers to the timestamp (the Unix epoch); 
    () refers to the extradata and the sequences of both uncles and transactions, all empty. 
    SHA3(42) refers to the SHA3 hash of a byte array of length one whose first
    and only byte is of value 42. 
    SHA3RLP() values refer to the hashes of the transaction and uncle lists in RLP, 
    both empty.
    The proof-of-concept series include a development premine, making the state root 
    hash some value stateRoot. The latest documentation should be consulted for 
    the value of the state root.
    """

    h256 = "\x00" * 32
    sr = CPP_PoC5_GENESIS_STATE_ROOT_HEX_HASH.decode('hex')
    genisi_block_defaults = [
        ["prevhash", "bin", h256],  # h256()
        ["uncles_hash", "bin", utils.sha3(rlp.encode([]))],  # sha3EmptyList
        ["coinbase", "addr", "0" * 40],  # h160()
        ["state_root", "trie_root", sr],  # stateRoot
        ["tx_list_root", "trie_root", h256],  # h256()
        ["difficulty", "int", 2 ** 22],  # c_genesisDifficulty
        ["number", "int", 0],  # 0
        ["min_gas_price", "int", 0],  # 0
        ["gas_limit", "int", 1000000],  # 1000000
        ["gas_used", "int", 0],  # 0
        ["timestamp", "int", 0],  # 0
        ["extra_data", "bin", ""],  # ""
        ["nonce", "bin", utils.sha3(chr(42))],  # sha3(bytes(1, 42));
    ]

    cpp_genesis_block = rlp.decode(CPP_PoC5_GENESIS_HEX.decode('hex'))
    cpp_genesis_header = cpp_genesis_block[0]

    for i, (name, typ, genesis_default) in enumerate(genisi_block_defaults):
        # print name, repr(getattr(genesis, name)),  repr(genesis_default)
        assert utils.decoders[typ](cpp_genesis_header[i]) == genesis_default
        assert getattr(genesis, name) == genesis_default
    assert genesis.hex_hash() == CPP_PoC5_GENESIS_HEX_HASH
开发者ID:ebuchman,项目名称:daoist_protocol,代码行数:57,代码来源:test_chain.py

示例12: test_transaction

def test_transaction():
    k, v, k2, v2 = accounts()
    set_db()
    blk = blocks.genesis({v: utils.denoms.ether * 1})
    tx = get_transaction()
    assert not tx in blk.get_transactions()
    success, res = processblock.apply_tx(blk, tx)
    assert tx in blk.get_transactions()
    assert blk.get_balance(v) == utils.denoms.finney * 990
    assert blk.get_balance(v2) == utils.denoms.finney * 10
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:10,代码来源:test_chain.py

示例13: test_mine_block

def test_mine_block():
    k, v, k2, v2 = accounts()
    set_db()
    blk = blocks.genesis({v: utils.denoms.ether * 1})
    db_store(blk)
    blk2 = mine_next_block(blk, coinbase=v)
    db_store(blk2)
    assert blk2.get_balance(v) == blocks.BLOCK_REWARD + blk.get_balance(v)
    assert blk.state.db.db == blk2.state.db.db
    assert blk2.get_parent() == blk
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:10,代码来源:test_chain.py

示例14: test_transfer

def test_transfer():
    k, v, k2, v2 = accounts()
    blk = blocks.genesis({v: utils.denoms.ether * 1})
    b_v = blk.get_balance(v)
    b_v2 = blk.get_balance(v2)
    value = 42
    success = blk.transfer_value(v, v2, value)
    assert success
    assert blk.get_balance(v) == b_v - value
    assert blk.get_balance(v2) == b_v2 + value
开发者ID:maieuto,项目名称:pyethereum,代码行数:10,代码来源:test_chain.py

示例15: _recv_Hello

def _recv_Hello(self, data):
    old_hello(self, data)
    h = blocks.genesis().hash
    print('HELLO RECEIVED')
    head_hash = data[7]
    print "head_hash", head_hash.encode('hex')
    from peer import idec
    print "head difficulty", idec(data[6])
    #self.send_GetBlocks([head_hash])
    assert not len(collected_blocks)
    self.send_GetBlockHashes(head_hash, NUM_BLOCKS_PER_REQUEST)
开发者ID:csbitcoin,项目名称:pyethereum,代码行数:11,代码来源:blockfetcherpatch.py


注:本文中的pyethereum.blocks.genesis函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。