Related to following answer:
function block_hash_validation(uint blockNumber, bytes32 blockHash) constant returns(bool isValid) { return (block.blockhash(blockNumber) == blockHash); }
When I call it as follows from a python script:
blockHash = web3.eth.getBlock(0)["hash"]; //'0x040db90fe13e6688c86ff93c5ce8e4a0a61faaf6a734c548febd0d0b44c86aa8'
block_hash_validation(0, blockHash);
It gives following error: TypeError: One or more arguments could not be encoded to the necessary ABI type. Expected types are: bytes32
When I replace bytes32
as string
=> (string
blockHash) it now gives following problem:
contracts/Receipt.sol:26:48: Error: Operator == not compatible with types bytes32
and string memory
if( blk_start_ >= blk_end_ || core_ < 0 || block.blockhash(blk_end_) == b2 )
^-----------------------------^
I have implemented following code but now the comparison is wrong:
function block_hash_validation(uint blockNumber, string blockHash)
constant returns(bool isValid)
{
bytes32 blockHash_result;
assembly {
blockHash_result := mload(add(blockHash, 32)) //this also obtains hash's first 32 characters which is wrong.
}
return (block.blockhash(blockNumber) == blockHash_result);
}
=> This should have return true
, but it returns false
. When I only return block.blockhash(1)
inside populus
, it returns some random characters for example: "òÓ F»\TÕ' ʦ,ºåY¹DèÝ�¿"
In additon to that on my private ethereum network I tried following contract:
contract C {
function get_block_hash(uint blockNumber) constant returns( bytes32 my_hash ) {
return (block.blockhash(blockNumber));
}
}
It always return "0x" for the any block numbers I have tried.
[geth]> C.get_block_hash(block.number - 1)
"0x0000000000000000000000000000000000000000000000000000000000000000"
[Q] How could I overcome those problems I am facing? Please note that I am experimenting inside populus
.
Thank you for your valuable time and help.
C.get_block_hash(1)
, it's going to be 0. – Tjaden Hess♦ Feb 4 '17 at 19:26