squeaknode/init.sql
Jonathan Zernik 686edbcd77
Decode payment request on get offer (#235)
* Decode payment request after getting offer

* Decode amount and node_pubkey from payment request string

* Rename fields in offer database table

* Include invoice time and expiry time in offer table

* Fix block time display in squeak detail component
2020-08-07 17:50:06 -07:00

74 lines
2.3 KiB
SQL

CREATE TABLE IF NOT EXISTS squeak (
hash CHAR(64) PRIMARY KEY,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
n_version INTEGER NOT NULL,
hash_enc_content CHAR(64) NOT NULL,
hash_reply_sqk CHAR(64) NOT NULL,
hash_block CHAR(64) NOT NULL,
n_block_height INTEGER NOT NULL,
vch_script_pub_key bytea NOT NULL,
vch_encryption_key bytea NOT NULL,
enc_data_key CHAR(256) NOT NULL,
iv CHAR(32) NOT NULL,
n_time INTEGER NOT NULL,
n_nonce BIGINT NOT NULL,
enc_content CHAR(2272) NOT NULL, -- Encrypted content length is always 1136 bytes (2272 hex characters).
vch_script_sig bytea NOT NULL,
author_address VARCHAR(35) NOT NULL, -- Maximum length of a bitcoin address is 35.
vch_decryption_key bytea,
block_header bytea
);
CREATE INDEX IF NOT EXISTS idx_squeak_address
ON squeak(author_address);
CREATE TABLE IF NOT EXISTS profile (
profile_id SERIAL PRIMARY KEY,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
profile_name VARCHAR(64) NOT NULL,
private_key bytea,
address VARCHAR(35) UNIQUE NOT NULL, -- Maximum length of a bitcoin address is 35.
sharing BOOLEAN NOT NULL,
following BOOLEAN NOT NULL,
whitelisted BOOLEAN NOT NULL
);
CREATE TABLE IF NOT EXISTS peer (
peer_id SERIAL PRIMARY KEY,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
peer_name VARCHAR(64),
server_host VARCHAR(256) NOT NULL,
server_port INTEGER NOT NULL,
uploading BOOLEAN NOT NULL,
downloading BOOLEAN NOT NULL
);
CREATE TABLE IF NOT EXISTS offer (
offer_id SERIAL PRIMARY KEY,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
squeak_hash CHAR(64) NOT NULL,
key_cipher bytea NOT NULL,
iv bytea NOT NULL,
payment_hash CHAR(64) NOT NULL,
invoice_timestamp INTEGER NOT NULL,
invoice_expiry INTEGER NOT NULL,
price_msat INTEGER NOT NULL,
payment_request TEXT NOT NULL,
destination VARCHAR(66) NOT NULL,
node_host VARCHAR(256) NOT NULL,
node_port INTEGER NOT NULL,
peer_id INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS sent_payment (
sent_payment_id SERIAL PRIMARY KEY,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
offer_id INTEGER NOT NULL,
peer_id INTEGER NOT NULL,
squeak_hash CHAR(64) NOT NULL,
preimage_hash CHAR(64) NOT NULL,
preimage CHAR(64) NOT NULL,
amount INTEGER NOT NULL,
node_pubkey VARCHAR(66) NOT NULL,
preimage_is_valid BOOLEAN NOT NULL
);