bitcoin-to-neo4j icon indicating copy to clipboard operation
bitcoin-to-neo4j copied to clipboard

Unsupported operand types: int - string in /var/www/functions/script.php:293

Open yellowonblack opened this issue 2 years ago • 2 comments

Hello,

I run the importer for several days and everything worked normally but now it stopped with the following error:

Reading /home/user/.bitcoin/blocks/blk00111.dat...

 1: 00000000000000000888b3c9ac26b034e38d26396d4421f4a190e61e537870d9 [366.35 kb] (fp:70435685) 
......

PHP Fatal error:  Uncaught TypeError: Unsupported operand types: int - string in /var/www/functions/script.php:293
Stack trace:
#0 /var/www/functions/tx.php(91): decodeScript()
#1 /var/www/cyphertx.php(13): decoderawtransaction()
#2 /var/www/main.php(380): cypherTx()
#3 {main}
  thrown in /var/www/functions/script.php on line 293

For me it stopped at blk00011.dat and redis stored info are:

redis-cli HGETALL bitcoin-to-neo4j

  1. "blk.dat"
  2. "111"
  3. "fp"
  4. "70435685"

redis-cli HGETALL bitcoin-to-neo4j:tip

  1. "height"
  2. "283110"
  3. "hash"
  4. "000000000000000167b56449edc301a97e499dcae29b20edcf106f194a4ba939"

I don't know if blk*.dat files are identical between installations but I may provide the one which cause the issue.

I'm running the script main.php in a docker container, but I don't know if that is relevant, as it worked fine until this error.

Thanks.

yellowonblack avatar Jun 25 '22 11:06 yellowonblack

Hey @yellowonblack,

It's been a while, but the issue seems to stem from the absence of an invalid output check (at least, that's my interpretation). For instance, in the transaction linked here, there's an invalid output with op codes 'op_return' and 'op_checkmultisig'.

The code snippet in question is:

$op_n = preg_replace("/[^0-9]/", '', array_slice($lockops, -2, 1)[0]);
// $op_n is empty, causing
$pubkeys = array_slice($lockops, -2-$op_n, $op_n)
// to fail

I've made an adjustment in my code to include an 'OP_RETURN' check:

$op_code = array_slice($lockops, -2, 1)[0];
if ($op_code != "OP_RETURN") {
    $op_n = preg_replace("/[^0-9]/", '', array_slice($lockops, -2, 1)[0]);
    // Further code
}

However, I'm uncertain if this is the optimal solution and whether it might have unforeseen consequences. I'd appreciate it if someone could assess whether this solution is substantial or if there might be a better approach. Thank you.

TimoHerz avatar Nov 13 '23 09:11 TimoHerz

I encounter the same issue; any solution would be appreciated.

Jerry602071349 avatar Nov 22 '23 09:11 Jerry602071349