-
-
Save tonicebrian/25caf4a25d675858e5fb3149f3f9d540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE INDEX ON :Block(height); | |
CREATE INDEX ON :Transaction(hash); | |
CREATE INDEX ON :Output(tx_hash, output_index); | |
CREATE INDEX ON :Address(address_string); | |
LOAD CSV WITH HEADERS FROM "http://storage.googleapis.com/bitcoin-neo4j-etl/blocks.csv" AS row | |
MERGE (b:Block {height: toInt(row.number)}) | |
ON CREATE SET | |
b.hash = row.hash, | |
b.size = toInt(row.size), | |
b.stripped_size = toInt(row.stripped_size), | |
b.weight = toInt(row.weight), | |
b.version = row.version, | |
b.merkle_root = row.merkle_root, | |
b.timestamp = toInt(row.timestamp), | |
b.nonce = row.nonce, | |
b.bits = row.bits, | |
b.transaction_count = toInt(row.transaction_count), | |
b.coinbase_param = row.coinbase_param | |
WITH b | |
MATCH (_b: Block {height: b.height - 1}) | |
MERGE (_b)-[:next] ->(b) | |
USING PERIODIC COMMIT 10000 | |
LOAD CSV WITH HEADERS FROM "http://storage.googleapis.com/bitcoin-neo4j-etl/txns.csv" AS row | |
CREATE (t:Transaction {hash: row.hash}) | |
SET | |
t.hash = row.hash, | |
t.size = toInt(row.size), | |
t.virtual_size = toInt(row.virtual_size), | |
t.version = toInt(row.version), | |
t.lock_time = toInt(row.lock_time), | |
t.is_coinbase = row.is_coinbase, | |
t.input_count = toInt(row.input_count), | |
t.output_count = toInt(row.output_count) | |
WITH t, row | |
MATCH (b:Block {height: row.block_number}) | |
CREATE (t)-[:at]->(b) | |
USING PERIODIC COMMIT 10000 | |
LOAD CSV WITH HEADERS FROM "http://storage.googleapis.com/bitcoin-neo4j-etl/outputs.csv" AS row | |
CREATE (o:Output {tx_hash: row.hash, output_index: row.index}) | |
SET | |
o.required_signatures = toInt(row.required_signatures), | |
o.type = row.type, | |
o.value = toInt(row.value), | |
o.is_unspent = toBoolean(true) | |
WITH o, row | |
MATCH (t:Transaction {hash: o.hash}) | |
CREATE (o)<-[:received]-(t) | |
USING PERIODIC COMMIT 10000 | |
LOAD CSV WITH HEADERS FROM "http://storage.googleapis.com/bitcoin-neo4j-etl/outputs_addresses.csv" AS row | |
MATCH (o:Output {tx_hash: row.hash, output_index: row.index}) | |
MERGE (a:Address {address_string: row.addresses}) | |
MERGE (a)<-[:owned]-(o) | |
USING PERIODIC COMMIT 10000 | |
LOAD CSV WITH HEADERS FROM "http://storage.googleapis.com/bitcoin-neo4j-etl/inputs.csv" AS row | |
MATCH (i:Output {tx_hash: row.spent_transaction_hash, output_index: row.spent_output_index}) | |
SET | |
i.input_index = row.index, | |
i.is_unspent = toBoolean(false), | |
i.spending_tx = row.spent_transaction_hash | |
WITH i, row | |
MATCH (t:Transaction {hash: i.tx_hash}) | |
CREATE (i)-[:sent]->(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment