コード例 #1
0
 async def get_new_trie_with_proof_nodes(proof_nodes):
     """Return SubTrie created from proof_nodes."""
     new_trie = SubTrie()
     for node in proof_nodes:
         R = rlp_encode(node)
         H = sha3_256(R)
         new_trie._subtrie[H] = R
     return new_trie
コード例 #2
0
ファイル: mpt.py プロジェクト: counterfactual/research
def get_mpt_root(mpt):
    if isinstance(mpt, bytes): return mpt
    if isinstance(mpt, PatriciaTrieExtension):
        assert isinstance(mpt.child, PatriciaTrieBranch)
        # compress extension nodes whose child branch node has a single child
        if len(mpt.child.children) == 1:
            assert '' in mpt.child.children
            pathlen = len(mpt.extension) % 2
            if pathlen == 0:
                x = [
                    bytes(bytearray.fromhex('20' + mpt.extension)),
                    mpt.child.children['']
                ]
                print('x=', [e.hex() for e in x])
                print(x, rlp.rlp_encode(x).hex())
                return H(rlp.rlp_encode(x))
            else:
                x = [
                    bytes(bytearray.fromhex('3' + mpt.extension)),
                    mpt.child.children['']
                ]
                print('x=', [e.hex() for e in x])
                return H(rlp.rlp_encode(x))
        else:
            pathlen = len(mpt.extension) % 2
            if pathlen == 0:
                x = [
                    bytes(bytearray.fromhex('00' + mpt.extension)),
                    get_mpt_root(mpt.child)
                ]
                print('x=', [e.hex() for e in x])
                return H(rlp.rlp_encode(x))
            else:
                x = [
                    bytes(bytearray.fromhex('1' + mpt.extension)),
                    get_mpt_root(mpt.child)
                ]
                print('x=', [e.hex() for e in x])
                return H(rlp.rlp_encode(x))

    elif isinstance(mpt, PatriciaTrieBranch):
        indices = list('0123456789abcdef') + ['']
        arr = [get_mpt_root(mpt.children.get(k, b'')) for k in indices]
        print('arr=', [e.hex() for e in arr])
        return H(rlp.rlp_encode(arr))
    else:
        print(type(mpt), mpt)
        raise
コード例 #3
0
ファイル: rlp.py プロジェクト: Nautilusc/thor-devkit.py
 def encode(self, data: Any) -> bytes:
     packed = pack(data, self.wrapper)
     return rlp_encode(packed)
コード例 #4
0
ファイル: erc20_offl_txn.py プロジェクト: aussiehash/reddit
sig = ethereum.sign_tx(
    client,
    n=address_n,
    nonce=nonce,
    gas_price=gas_price,
    gas_limit=gas_limit,
    to=to_address,
    value=amount,
    data=data,
    chain_id=chain_id,
)
client.close()

to = bytes.fromhex(to_address[2:])
transaction = rlp_encode((nonce, gas_price, gas_limit, to, amount, data) + sig)
print(f'{{"hex": "0x{transaction.hex()}"}}')

"""
txn_id = 0xdcaf3eba690a3cdbad8c2926a8f5a95cd20003c5ba2aace91d8c5fe8048e395b
https://etherscan.io/getRawTx?tx=${txn_id}

# trezorctl ethereum sign-tx                         \
  --chain-id 1                                       \
  --address m/44'/60'/0'/0/0                         \
  --gas-limit 200000                                 \
  --gas-price 5000000000                             \
  --nonce 11                                         \
  --token 0xa74476443119A942dE498590Fe1f2454d7D4aC0d \
  0xA6ABB480640d6D27D2FB314196D94463ceDcB31e 5000000000000000
コード例 #5
0
ファイル: rlp.py プロジェクト: vechain/thor-devkit.py
 def encode(self, data: Any) -> bytes:
     packed = pack(data, self.wrapper)
     # pretty_print(packed, 0) # Uncomment for debugging.
     return rlp_encode(packed)
コード例 #6
0
    frontier_genesis = json.load(f)

# YP: yellow paper, appendix I

# print(block0['difficulty'] == frontier_genesis['difficulty']) # TODO. difficulty set to 2**17, YP
assert(block0['extraData'] == frontier_genesis['extraData']) # testnet block 1028201
assert(block0['gasLimit'] == frontier_genesis['gasLimit']) # ??
assert(block0['gasUsed'] == "0x0")
# hash
assert(set(block0['logsBloom']) == set(['0', 'x'])) # no txns
assert(block0['miner'] == frontier_genesis['coinbase'] == ('0x' + '0'*40))
# mixhash
assert(block0['nonce'] == '0x0000000000000042') # yp
assert(block0['number'] == '0x0') # 0th block
# parentHash
assert(block0['receiptsRoot'] == '0x' + keccak256(rlp.rlp_encode(b'')))
assert(block0['sha3Uncles'] == '0x' + keccak256(rlp.rlp_encode([])))
# size
# stateRoot !important
# timestamp
# totalDifficulty
assert(block0['transactions'] == [])
assert(block0['transactionsRoot'] == '0x' + keccak256(rlp.rlp_encode(b'')))
assert(block0['uncles'] == [])

EMPTY_STORAGEROOT = rlp.to_binary(0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421)
EMPTY_CODEHASH = rlp.to_binary(0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)

for addr in frontier_genesis['alloc']:
    balance = int(frontier_genesis['alloc'][addr]['balance'], 10)
    print(keccak256(bytearray.fromhex(addr)), rlp.rlp_encode([