getblockhash returning 500 error : where is rpc request logs location?

+1 vote

Where can i find  the rpc server logs.

I am writing a perl script to interact with a private blockchain and I am able to make few api calls but server is throwing "500 Internal Server Error" when I invoke getblockhash

Code snippet:
  sub getBlockHash {
    $class=shift;
    my $height=shift;
    print "height inside fn: $height \n";   
# I am getting the number correctly here.
    my $obj = {
       method  => 'getblockhash',      
# similar function with getinfo or getblockcount without
       params  => [$height],                 # passing params works well.
    };                                                      # tried sendwithmetadata , it works with params
 
    my $res = $client->call( $uri, $obj );
     if ($res){
      print "Got res\n";
      if ($res->is_error) { print "Error : ", $res->error_message; return "ERROR"; }
      else {
            my $data = Dumper ($res->result);
            $bcount = substr ($data,length('$VAR1 = '),length($data));
            $bcount =~ s/\W//g;
            return  $bcount;
           }   
    } else {
      print "no res\n";
      print $client->status_line;
      return "ERROR";
    }   
  }
----------------- RESULT -----------------------

height inside fn: 15545
no res
500 Internal Server ErrorHash = ERROR

---------------------
Where can I find the logs to debug these kind of errors? is getblockhash not recognised?

I want to traverse the block starting from 0 to total number of blocks , using getblock api after I get the hash from getblockhash <height> call.
is there any other  method to do this? I am interested to fetch transactions which has metadata attached to them.

any help much appreciated.
thanks

asked Apr 28, 2016 by sanmadhavan
edited Apr 28, 2016 by sanmadhavan
It works when I pass 15000 inside params array.
 my $obj = {
       method  => 'getblockhash',
       params  => [15000],
    };
not when I pass variable.
Resolved :
was an issue in variable data type, guess it was taking as string. Added $height+0 in the params and it worked!

   my $obj = {
       method  => 'getblockhash',
       params  => [$height+0],
    };

1 Answer

0 votes
Thanks for answering your own question!
answered Apr 28, 2016 by MultiChain
Yeah it was a silly mistake.
btw is the following method for traversing the chain right?

for count  = zero to getblockcount
   hash = getblockhash <count>
   block = getblock <hash>
   listoftransactions = count transactions of block
   for each transaction
          fetch transaction id,
          data =getwallettransaction <txid>
          { process data  }
    

please advise if there is a better way to do this.

I am adding some data to the chain using sendwithmetadata
and my display gui will need to show only the transactions which has the metadata associated with it.
You should use getrawtransaction rather than getwallettransaction since the latter only works with transactions that are relevant for the local wallet.

Also later you could extract the transactions directly from the raw block content given by getblock (with format=false) but this is probably too much work at this stage.
thanks , shall try that.
...