-- 037: Indexed on-chain transactions (chain-indexer)
CREATE TABLE IF NOT EXISTS chain_transactions (
    hash VARCHAR(128) PRIMARY KEY,
    block_height BIGINT NOT NULL REFERENCES blocks(height),
    from_addr VARCHAR(128) NOT NULL,
    to_addr VARCHAR(128) NOT NULL,
    amount VARCHAR(78) NOT NULL DEFAULT '0',
    status VARCHAR(20) NOT NULL DEFAULT 'confirmed',
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_chain_tx_block ON chain_transactions(block_height);
CREATE INDEX idx_chain_tx_from ON chain_transactions(from_addr);
CREATE INDEX idx_chain_tx_to ON chain_transactions(to_addr);
