postgres schema and tables for btc

This commit is contained in:
Ian Norden
2020-02-20 16:14:17 -06:00
parent 9018e551ba
commit 5094b975fc
7 changed files with 343 additions and 3 deletions
@@ -0,0 +1,5 @@
-- +goose Up
CREATE SCHEMA btc;
-- +goose Down
DROP SCHEMA btc;
@@ -0,0 +1,15 @@
-- +goose Up
CREATE TABLE btc.header_cids (
id SERIAL PRIMARY KEY,
block_number BIGINT NOT NULL,
block_hash VARCHAR(66) NOT NULL,
parent_hash VARCHAR(66) NOT NULL,
cid TEXT NOT NULL,
version INTEGER NOT NULL,
timestamp INTEGER NOT NULL,
bits INTEGER NOT NULL,
UNIQUE (block_number, block_hash)
);
-- +goose Down
DROP TABLE btc.header_cids;
@@ -0,0 +1,14 @@
-- +goose Up
CREATE TABLE btc.transaction_cids (
id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES btc.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
index INTEGER NOT NULL,
tx_hash VARCHAR(66) NOT NULL,
cid TEXT NOT NULL,
has_witness BOOL NOT NULL,
witness_hash VARCHAR(66),
UNIQUE (header_id, tx_hash)
);
-- +goose Down
DROP TABLE btc.transaction_cids;
@@ -0,0 +1,15 @@
-- +goose Up
CREATE TABLE btc.tx_inputs (
id SERIAL PRIMARY KEY,
tx_id INTEGER NOT NULL REFERENCES btc.transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
index INTEGER NOT NULL,
tx_witness BYTEA[],
sequence INTEGER NOT NULL,
script BYTEA NOT NULL,
outpoint_hash VARCHAR(66) NOT NULL,
outpoint_index INTEGER NOT NULL,
UNIQUE (tx_id, index)
);
-- +goose Down
DROP TABLE btc.tx_inputs;
@@ -0,0 +1,12 @@
-- +goose Up
CREATE TABLE btc.tx_outputs (
id SERIAL PRIMARY KEY,
tx_id INTEGER NOT NULL REFERENCES btc.transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
index INTEGER NOT NULL,
value INTEGER NOT NULL,
script BYTEA NOT NULL,
UNIQUE (tx_id, index)
);
-- +goose Down
DROP TABLE btc.tx_outputs;