Esempio n. 1
0
def call_validation_code(state, validation_code_addr, msg_hash, signature):
    """Call validationCodeAddr on the main shard with 200000 gas, 0 value,
    the block_number concatenated with the sigIndex'th signature as input data gives output 1.
    """
    dummy_addr = b'\xff' * 20
    data = msg_hash + signature
    msg = vm.Message(dummy_addr, validation_code_addr, 0, 200000, data)
    result = apply_message(state.ephemeral_clone(), msg)
    if result is None:
        raise MessageFailed()
    return bool(utils.big_endian_to_int(result))
Esempio n. 2
0
 def call(self, sender=k0, to=b'\x00' * 20, value=0,
          data=b'', startgas=STARTGAS, gasprice=GASPRICE):
     self.state.commit()
     sender_addr = privtoaddr(sender)
     result = apply_message(
         self.state.ephemeral_clone(),
         sender=sender_addr,
         to=to,
         code_address=to,
         value=value,
         data=data,
         gas=startgas)
     if result is None:
         raise TransactionFailed()
     return result
Esempio n. 3
0
def call_msg(state,
             ct,
             func,
             args,
             sender_addr,
             to,
             value=0,
             startgas=STARTGAS):
    abidata = vm.CallData(
        [utils.safe_ord(x) for x in ct.encode_function_call(func, args)])
    msg = vm.Message(sender_addr, to, value, startgas, abidata)
    result = apply_message(state, msg)
    if result is None:
        raise MessageFailed("Msg failed")
    if result is False:
        return result
    if result == b'':
        return None
    o = ct.decode(func, result)
    return o[0] if len(o) == 1 else o
Esempio n. 4
0
    def call(self, transaction, block_number="latest"):
        from ethereum.messages import apply_message

        if isinstance(block_number, bytes):
            state = self.evm.chain.mk_poststate_of_blockhash(block_number)
        elif isinstance(block_number, int) or isinstance(block_number, str):
            block = _get_block_by_number(self.evm, block_number)
            state = self.evm.chain.mk_poststate_of_blockhash(block.hash)
        else:
            raise BlockNotFound("Invalid block identifer.")

        output = apply_message(
            state,
            sender=transaction['from'],
            to=transaction['to'],
            code_address=transaction['to'],
            data=transaction['data'],
            gas=transaction['gas'],
        )
        if output is None:
            raise TransactionFailed
        return output