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

Updated neo4j syntax

Open zenonp opened this issue 1 year ago • 0 comments

from main.php:

SyntaxError" and message "Invalid constraint syntax, ON and ASSERT should not be used. Replace ON with FOR and ASSERT with REQUIRE. (line 1, column 1 (offset: 0))
"CREATE CONSTRAINT IF NOT EXISTS ON (b:block) ASSERT b.hash IS UNIQUE"

Fix:

--- main.php       2023-03-17 21:52:13.720000000 +0200
+++ main.php    2023-03-17 21:53:26.601000000 +0200
@@ -35,9 +35,9 @@
 }
 
 // Create Neo4j constraints (for unique indexes, not regular indexes (should be faster))
-$neo->run("CREATE CONSTRAINT IF NOT EXISTS ON (b:block) ASSERT b.hash IS UNIQUE");
-$neo->run("CREATE CONSTRAINT IF NOT EXISTS ON (t:tx) ASSERT t.txid IS UNIQUE");
-$neo->run("CREATE CONSTRAINT IF NOT EXISTS ON (o:output) ASSERT o.index IS UNIQUE");
+$neo->run("CREATE CONSTRAINT IF NOT EXISTS FOR (b:block) REQUIRE b.hash IS UNIQUE");
+$neo->run("CREATE CONSTRAINT IF NOT EXISTS FOR (t:tx) REQUIRE t.txid IS UNIQUE");
+$neo->run("CREATE CONSTRAINT IF NOT EXISTS FOR (o:output) REQUIRE o.index IS UNIQUE");
 $neo->run("CREATE INDEX IF NOT EXISTS FOR (b:block) ON (b.height)");
 $neo->run("CREATE INDEX IF NOT EXISTS FOR (a:address) ON (a.address)"); // for getting outputs locked to an address

From main.php a couple of minutes later:

Neo4j errors detected. First one with code "Neo.ClientError.Statement.SyntaxError" and message "The property existence syntax `... exists(variable.property)` is no longer supported. Please use `variable.property IS NOT NULL` instead. (line 3, column 43 (offset: 136))
"                WHERE NOT exists(coinbase.value)"

Fix:

@@ -317,7 +317,7 @@
                 // Update coinbase and fee (if the coinbase input value has not been set)
                 $coinbaserun = $neo->run('
                 MATCH (block :block {hash:$orphan})-[:coinbase]->(coinbase :output:coinbase)-[:in]->(tx :tx)
-                WHERE NOT exists(coinbase.value)
+                WHERE coinbase.value IS NOT NULL
                 SET coinbase.value=$blockreward
                 SET tx.fee= tx.fee + $blockreward

I checked when the syntax changed, and it was in neo4j-5.0. That's fairly recent, so it would make sense to check the neo4j version at startup and then use the old or the new syntax accordingly. It's just one cypher call at the beginning and a simple if/else wrapper instead of my patches above.

zenonp avatar Mar 17 '23 19:03 zenonp