@@ -603,7 +603,7 @@ CREATE TABLE mint_anchor_uni_commitments (
603
603
group_key BLOB
604
604
, taproot_internal_key_id
605
605
BIGINT REFERENCES internal_keys(key_id)
606
- NOT NULL );
606
+ NOT NULL , spent_by BIGINT REFERENCES supply_commitments(commit_id) );
607
607
608
608
CREATE UNIQUE INDEX mint_anchor_uni_commitments_unique
609
609
ON mint_anchor_uni_commitments (batch_id, tx_output_index);
@@ -753,6 +753,113 @@ CREATE TABLE script_keys (
753
753
754
754
CREATE INDEX status_idx ON addr_events(status);
755
755
756
+ CREATE TABLE supply_commit_state_machines (
757
+ -- The tweaked group key identifying the asset group's state machine.
758
+ group_key BLOB PRIMARY KEY CHECK (length(group_key) = 33 ),
759
+
760
+ -- The current state of the state machine.
761
+ current_state_id INTEGER NOT NULL REFERENCES supply_commit_states(id),
762
+
763
+ -- The latest successfully committed supply state on chain.
764
+ -- Can be NULL if no commitment has been made yet.
765
+ latest_commitment_id BIGINT REFERENCES supply_commitments(commit_id)
766
+ );
767
+
768
+ CREATE TABLE supply_commit_states (
769
+ id INTEGER PRIMARY KEY ,
770
+ state_name TEXT UNIQUE NOT NULL
771
+ );
772
+
773
+ CREATE TABLE supply_commit_transitions (
774
+ transition_id INTEGER PRIMARY KEY ,
775
+
776
+ -- Reference back to the state machine this transition belongs to.
777
+ state_machine_group_key BLOB NOT NULL REFERENCES supply_commit_state_machines(group_key),
778
+
779
+ -- The commitment being replaced by this transition.
780
+ -- Can be NULL if this is the first commitment.
781
+ old_commitment_id BIGINT REFERENCES supply_commitments(commit_id),
782
+
783
+ -- The new commitment that this transition aims to create.
784
+ -- Can be NULL initially, before the commitment details are created.
785
+ new_commitment_id BIGINT REFERENCES supply_commitments(commit_id),
786
+
787
+ -- The chain transaction that, once confirmed, will finalize this transition.
788
+ -- Can be NULL until the transaction is created and signed.
789
+ pending_commit_txn_id BIGINT REFERENCES chain_txns(txn_id),
790
+
791
+ -- Indicates if this transition has been successfully completed and committed.
792
+ finalized BOOLEAN NOT NULL DEFAULT FALSE,
793
+
794
+ -- Timestamp when this transition was initiated (unix timestamp in seconds).
795
+ creation_time BIGINT NOT NULL
796
+ );
797
+
798
+ CREATE UNIQUE INDEX supply_commit_transitions_single_pending_idx
799
+ ON supply_commit_transitions (state_machine_group_key) WHERE finalized = FALSE;
800
+
801
+ CREATE INDEX supply_commit_transitions_state_machine_group_key_idx ON supply_commit_transitions(state_machine_group_key);
802
+
803
+ CREATE TABLE supply_commit_update_types (
804
+ id INTEGER PRIMARY KEY ,
805
+ update_type_name TEXT UNIQUE NOT NULL
806
+ );
807
+
808
+ CREATE TABLE supply_commitments (
809
+ commit_id INTEGER PRIMARY KEY ,
810
+
811
+ -- The tweaked group key identifying the asset group this commitment belongs to.
812
+ group_key BLOB NOT NULL CHECK (length(group_key) = 33 ),
813
+
814
+ -- The chain transaction that included this commitment.
815
+ chain_txn_id BIGINT NOT NULL REFERENCES chain_txns(txn_id),
816
+
817
+ -- The output index within the chain_txn_id transaction for the commitment.
818
+ output_index INTEGER ,
819
+
820
+ -- The internal key used for the commitment output.
821
+ internal_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id),
822
+
823
+ -- The taproot output key used for the commitment output.
824
+ output_key BLOB NOT NULL CHECK (length(output_key) = 33 ),
825
+
826
+ -- The block header of the block mining the commitment transaction.
827
+ block_header BLOB,
828
+
829
+ -- The block height at which the commitment transaction was confirmed.
830
+ -- Can be NULL if the transaction is not yet confirmed.
831
+ block_height INTEGER ,
832
+
833
+ -- The merkle proof demonstrating the commitment's inclusion in the block.
834
+ merkle_proof BLOB,
835
+
836
+ -- The root hash of the supply commitment at this snapshot.
837
+ supply_root_hash BLOB,
838
+
839
+ -- The root sum of the supply commitment at this snapshot.
840
+ supply_root_sum BIGINT
841
+ );
842
+
843
+ CREATE INDEX supply_commitments_chain_txn_id_idx ON supply_commitments(chain_txn_id);
844
+
845
+ CREATE INDEX supply_commitments_group_key_idx ON supply_commitments(group_key);
846
+
847
+ CREATE TABLE supply_update_events (
848
+ event_id INTEGER PRIMARY KEY ,
849
+
850
+ -- Reference to the state transition this event is part of.
851
+ transition_id BIGINT NOT NULL REFERENCES supply_commit_transitions(transition_id) ON DELETE CASCADE ,
852
+
853
+ -- The type of update (mint, burn, ignore).
854
+ update_type_id INTEGER NOT NULL REFERENCES supply_commit_update_types(id),
855
+
856
+ -- Opaque blob containing the serialized data for the specific
857
+ -- SupplyUpdateEvent (NewMintEvent, NewBurnEvent, NewIgnoreEvent).
858
+ event_data BLOB NOT NULL
859
+ );
860
+
861
+ CREATE INDEX supply_update_events_transition_id_idx ON supply_update_events(transition_id);
862
+
756
863
CREATE TABLE tapscript_edges (
757
864
edge_id INTEGER PRIMARY KEY ,
758
865
0 commit comments