Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: dogisland on October 31, 2011, 06:16:31 PM



Title: SQL schema for the blockchain ?
Post by: dogisland on October 31, 2011, 06:16:31 PM
I'm going to store the blockchain in a SQL database.

Has anyone got any experience of this or even a schema they can share ? What I've got so far looks like this.

Code:
CREATE TABLE blocks ( hash CHAR(32) NOT NULL CONSTRAINT blocks_pk PRIMARY KEY,chainWork BLOB NOT NULL,height BIGINT NOT NULL,heade
r BLOB NOT NULL);
CREATE TABLE settings ( name VARCHAR(32) NOT NULL CONSTRAINT settings_pk PRIMARY KEY,value BLOB);
CREATE TABLE transactions ( hash TEXT NOT NULL CONSTRAINT transactions_pk PRIMARY KEY,ver INTEGER NOT NULL,vin_sz INTEGER NOT NULL
,vout_sz INTEGER NOT NULL,lock_time INTEGER NOT NULL,size INTEGER NOT NULL);
CREATE TABLE transactions_input ( hash_parent_tx TEXT NOT NULL,script_sig TEXT NOT NULL);
CREATE TABLE transactions_output ( hash_parent_tx TEXT NOT NULL,value REAL NOT NULL,script_pub_key TEXT NOT NULL);


I'm going to use BitcoinJ to download the chain as it's quite easy to create a new DataStore. I'll open source the result so if anyone has any requirements for this please let me know.

What I'm looking to do is gather data to make payment transactions for arbitrary public keys. 


Title: Re: SQL schema for the blockchain ?
Post by: genjix on October 31, 2011, 06:26:00 PM
https://bitcointalk.org/index.php?topic=38246.0

https://gitorious.org/libbitcoin/libbitcoin/blobs/master/bitcoin.sql


Title: Re: SQL schema for the blockchain ?
Post by: dogisland on October 31, 2011, 07:40:12 PM
https://bitcointalk.org/index.php?topic=38246.0

https://gitorious.org/libbitcoin/libbitcoin/blobs/master/bitcoin.sql

That's why I love this forum. Thanks.