コード例 #1
0
 def load_state(env, alloc):
     db = env.db
     state = SecureTrie(Trie(db, BLANK_ROOT))
     count = 0
     databaseLog.debug("Loading state from snapshot")
     for addr in alloc:
         databaseLog.debug("[%d] loading account %s", count, addr)
         account = alloc[addr]
         acct = Account.blank_account(db, env.config['ACCOUNT_INITIAL_NONCE'])
         if len(account['storage']) > 0:
             t = SecureTrie(Trie(db, BLANK_ROOT))
             c = 0
             for k in account['storage']:
                 v = account['storage'][k]
                 enckey = zpad(decode_hex(k), 32)
                 t.update(enckey, decode_hex(v))
                 c += 1
                 if c % 1000 and len(db.db_service.uncommitted) > 50000:
                     databaseLog.debug("%d uncommitted. committing...", len(db.db_service.uncommitted))
                     db.commit()
             acct.storage = t.root_hash
         if account['nonce']:
             acct.nonce = int(account['nonce'])
         if account['balance']:
             acct.balance = int(account['balance'])
         state.update(decode_hex(addr), rlp.encode(acct))
         count += 1
     db.commit()
     return state
コード例 #2
0
ファイル: python_sha3.py プロジェクト: zoonfafer/pyethrecover
  def digest(self):
    """Return the digest of the strings passed to the update() method so far.

    This is a string of digest_size bytes which may contain non-ASCII
    characters, including null bytes."""

    if self.last_digest:
      return self.last_digest

    # UGLY WARNING
    # Handle bytestring/hexstring conversions
    M = _build_message_pair(decode_hex(self.buffered_data))

    # First finish the padding and force the final update:
    self.buffered_data = Keccak.pad10star1(M, self.r)
    self.update('')
    # UGLY WARNING over

    assert len(self.buffered_data) == 0, "Why is there data left in the buffer? %s with length %d" % (self.buffered_data, len(self.buffered_data) * 4)

    # Squeezing time!
    Z = ''
    outputLength = self.n
    while outputLength > 0:
      string = _convertTableToStr(self.S, self.w)
      # Read the first 'r' bits of the state
      Z = Z + string[:self.r * 2 // 8]
      outputLength -= self.r
      if outputLength > 0:
        S = KeccakF(S, verbose)

    self.last_digest = decode_hex(Z[:2 * self.n // 8])
    return self.last_digest
コード例 #3
0
ファイル: recover_tools.py プロジェクト: Empact/pyethrecover
def secure_privtopub(priv):
    if len(priv) == 64:
        return encode_hex(secure_privtopub(decode_hex(priv)))
    if openssl:
        k = openssl.CKey()
        k.generate(priv)
        return k.get_pubkey()
    else:
        return bitcoin.privtopub(priv)
コード例 #4
0
def secure_privtopub(priv):
    if len(priv) == 64:
        return encode_hex(secure_privtopub(decode_hex(priv)))
    if openssl:
        k = openssl.CKey()
        k.generate(priv)
        return k.get_pubkey()
    else:
        return bitcoin.privtopub(priv)
コード例 #5
0
 def from_snapshot(cls, snapshot_data, env, executing_on_head=False):
     state = State(env=env)
     if "alloc" in snapshot_data:
         for addr, data in snapshot_data["alloc"].items():
             if len(addr) == 40:
                 addr = decode_hex(addr)
             assert len(addr) == 20
             if 'balance' in data:
                 state.set_balance(addr, utils.bin_to_object(data['balance']))
             if 'nonce' in data:
                 state.set_nonce(addr, parse_as_int(data['nonce']))
     elif "state_root" in snapshot_data:
         state.trie.root_hash = parse_as_bin(snapshot_data["state_root"])
     else:
         raise Exception(
             "Must specify either alloc or state root parameter")
     for k, default in STATE_DEFAULTS.items():
         default = copy.copy(default)
         v = snapshot_data[k] if k in snapshot_data else None
         if is_numeric(default):
             setattr(state, k, parse_as_int(v)
             if k in snapshot_data else default)
         elif is_string(default):
             setattr(state, k, parse_as_bin(v)
             if k in snapshot_data else default)
         elif k == 'prev_headers':
             if k in snapshot_data:
                 headers = [dict_to_prev_header(h) for h in v]
             else:
                 headers = default
             setattr(state, k, headers)
     if executing_on_head:
         state.executing_on_head = True
     state.commit()
     state.changed = {}
     return state
コード例 #6
0
def decode_rpc_proof(proof_data):
    return [rlp.decode(decode_hex(node)) for node in proof_data]
コード例 #7
0
                address = ContractAddress(address_hex, 
                                            creation_transaction=transaction)
                print("Address: contract.")
            except FileNotFoundError:
                print("Error: Local Web3 node not found. Did you forget to start it?")
                exit(2)
            except AssertionError:
                print("Error: Transaction {} is not a creation "
                      "transaction.".format(options.sent_transaction))
        else:
            print("Error: Please specify either sent trasaction (-p) or creation transaction (-c) flag.")
            exit(1)

        encrypted_message = address.encrypt(message)
        print("Encrypted message: {}".format(utils.add_0x_prefix(utils.encode_hex(encrypted_message))))
        owner = utils.decode_hex(utils.remove_0x_prefix(address.owner_address))
        assert len(owner) == 20
        message_data = owner + encrypted_message + info_bytes()
        print("Message to send: {}".format(utils.add_0x_prefix(utils.encode_hex(message_data))))
        
        if options.send:
            print("Sending transaction to: {}".format(address_hex))
            sender_account = options.send_from
            if not utils.is_hex_address(sender_account):
                try:
                    sender_account = web3.personal.listAccounts[int(sender_account)]
                except ValueError:
                    print("Error: Invalid sender account. Should be your local Ethereum account "
                          "or its index number. See --list flag.")
                    exit(1)
                except IndexError: