Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions packages/btcindexer/db/migrations/0001_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CREATE TABLE processed_blocks (
processed_at INTEGER DEFAULT unixepoch('subsec')
) STRICT;

---------- NBTC Minting and Withdrawal ----------

-- This table tracks the nBTC deposit txs
CREATE TABLE nbtc_txs (
tx_id TEXT PRIMARY KEY,
Expand All @@ -18,7 +20,27 @@ CREATE TABLE nbtc_txs (
updated_at INTEGER DEFAULT unixepoch('subsec')
) STRICT;

-- Indexes
CREATE INDEX nbtc_txs_status ON nbtc_txs (status);
CREATE INDEX nbtc_txs_sui_recipient ON nbtc_txs (sui_recipient);
CREATE INDEX processed_blocks_height ON processed_blocks (height);
CREATE INDEX nbtc_txs_sui_recipient ON nbtc_txs (sui_recipient, created_at);

-- nbtc_withdrawal table tracks nBTC withdraw transactions from SUI
CREATE TABLE nbtc_withdrawal (
sui_tx_id TEXT PRIMARY KEY,
sender TEXT NOT NULL, -- sui sender
amount INTEGER NOT NULL, -- amount of nBTC to be burn and withdraw on BTC,
recipient TEXT NOT NULL, -- the bitcoin address or script that will recive the BTC,
note TEXT, -- additional note that we can include for the user. eg. you are sending funds to a collegue, this note will be included (maybe op_return?)
sent_at INTEGER NOT NULL,
btc_tx_id TEXT, -- will be set once Bitcoin tx will be broadcasted
status INTEGER NOT NULL
) STRICT;

CREATE INDEX nbtc_withdraw_sender ON nbtc_withdrawal (sender, recipient, sent_at);

-- nbtc_withdrawal.status:
-- 1 = requested
-- 2 = burn
-- 3 = signing -- ika signature
-- 4 = signed
-- 5 = broadcasted to bitcoin
-- 6 = confirmations (here user technically already has the funds)