fix: PostgreSQL compatibility for all chain adapters

- AUTOINCREMENT → SERIAL (bchain, qchain, zchain)
- INSERT OR IGNORE → ON CONFLICT DO NOTHING (all chains)
- INSERT OR REPLACE → ON CONFLICT DO UPDATE (qchain, tchain)
- datetime('now') → NOW() (pchain)
- datetime(?, 'unixepoch') → to_timestamp(?) (pchain)
- Add K-chain to DAG indexer and CLI
This commit is contained in:
2026-02-27 10:47:28 -08:00
parent 1a1d7a3eb1
commit 767b39bb14
11 changed files with 141 additions and 34 deletions
+1 -1
View File
@@ -408,7 +408,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
total_receipts BIGINT DEFAULT 0,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT OR IGNORE INTO achain_stats (id) VALUES (1);
INSERT INTO achain_stats (id) VALUES (1) ON CONFLICT DO NOTHING;
`
if err := store.Exec(ctx, schema); err != nil {
+2 -2
View File
@@ -286,7 +286,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
-- Locked assets table
CREATE TABLE IF NOT EXISTS bchain_locked_assets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id SERIAL PRIMARY KEY,
asset_id TEXT NOT NULL,
source_chain TEXT NOT NULL,
amount TEXT NOT NULL,
@@ -319,7 +319,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
unique_chains BIGINT DEFAULT 0,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT OR IGNORE INTO bchain_bridge_stats (id) VALUES (1);
INSERT INTO bchain_bridge_stats (id) VALUES (1) ON CONFLICT DO NOTHING;
`
if err := store.Exec(ctx, schema); err != nil {
+29
View File
@@ -20,6 +20,7 @@ import (
"github.com/luxfi/indexer/chain"
"github.com/luxfi/indexer/dag"
"github.com/luxfi/indexer/evm"
"github.com/luxfi/indexer/kchain"
"github.com/luxfi/indexer/pchain"
"github.com/luxfi/indexer/qchain"
"github.com/luxfi/indexer/storage"
@@ -130,6 +131,8 @@ func main() {
runTChain(ctx, store, *rpcEndpoint, *httpPort, *pollInterval)
case "zchain":
runZChain(ctx, store, *rpcEndpoint, *httpPort, *pollInterval)
case "kchain":
runKChain(ctx, store, *rpcEndpoint, *httpPort, *pollInterval)
// Linear chains
case "pchain":
runPChain(ctx, store, *rpcEndpoint, *httpPort, *pollInterval)
@@ -322,6 +325,29 @@ func runCChain(ctx context.Context, store storage.Store, rpcEndpoint string, htt
log.Println("[cchain] Indexer stopped")
}
func runKChain(ctx context.Context, store storage.Store, rpcEndpoint string, httpPort int, pollInterval time.Duration) {
adapter := kchain.New(rpcEndpoint)
cfg := dag.Config{
ChainType: dag.ChainK,
ChainName: "K-Chain (Key Management)",
RPCEndpoint: rpcEndpoint,
RPCMethod: "kvm",
HTTPPort: httpPort,
PollInterval: pollInterval,
}
idx, err := dag.New(cfg, store, adapter)
if err != nil {
log.Fatalf("[kchain] Failed to create indexer: %v", err)
}
log.Printf("[kchain] Starting DAG indexer on port %d", httpPort)
if err := idx.Run(ctx); err != nil && ctx.Err() == nil {
log.Fatalf("[kchain] Indexer error: %v", err)
}
log.Println("[kchain] Indexer stopped")
}
func printChainList() {
fmt.Println(" DAG-based chains (fast consensus):")
fmt.Println(" xchain - X-Chain (Exchange) - Port 4200 - Asset exchange, UTXOs")
@@ -330,6 +356,7 @@ func printChainList() {
fmt.Println(" qchain - Q-Chain (Quantum) - Port 4300 - Quantum finality proofs")
fmt.Println(" tchain - T-Chain (Teleport) - Port 4700 - MPC threshold signatures")
fmt.Println(" zchain - Z-Chain (Privacy) - Port 4400 - ZK transactions")
fmt.Println(" kchain - K-Chain (KMS) - Port 4900 - Post-quantum key material")
fmt.Println()
fmt.Println(" Linear chains (strict ordering):")
fmt.Println(" pchain - P-Chain (Platform) - Port 4100 - Validators, staking")
@@ -348,6 +375,7 @@ func defaultPort(ct string) int {
"achain": 4500,
"bchain": 4600,
"tchain": 4700,
"kchain": 4900,
}
return ports[ct]
}
@@ -362,6 +390,7 @@ func defaultRPC(ct string) string {
"achain": "http://localhost:9650/ext/bc/A",
"bchain": "http://localhost:9650/ext/bc/B",
"tchain": "http://localhost:9650/ext/bc/T",
"kchain": "http://localhost:9650/ext/bc/K",
}
return endpoints[ct]
}
+1
View File
@@ -30,6 +30,7 @@ const (
ChainQ ChainType = "qchain" // Quantum - finality proofs
ChainT ChainType = "tchain" // Teleport - MPC signatures
ChainZ ChainType = "zchain" // Privacy - ZK transactions (DAG for fast consensus, proofs for privacy)
ChainK ChainType = "kchain" // KMS - Post-quantum key material
)
// Config for DAG indexer
+1 -1
View File
@@ -411,7 +411,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
}
// Initialize stats row
return store.Exec(ctx, "INSERT OR IGNORE INTO dex_extended_stats (id) VALUES (1)")
return store.Exec(ctx, "INSERT INTO dex_extended_stats (id) VALUES (1) ON CONFLICT DO NOTHING")
}
// GetStats returns DEX L2 specific statistics using unified storage
+1 -1
View File
@@ -1416,7 +1416,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
}
// Initialize stats row
return store.Exec(ctx, "INSERT OR IGNORE INTO cchain_extended_stats (id) VALUES (1)")
return store.Exec(ctx, "INSERT INTO cchain_extended_stats (id) VALUES (1) ON CONFLICT DO NOTHING")
}
// GetStats returns C-Chain specific statistics using unified storage
+6 -6
View File
@@ -424,17 +424,17 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
}
// Initialize stats row
if err := store.Exec(ctx, "INSERT OR IGNORE INTO kchain_extended_stats (id) VALUES (1)"); err != nil {
if err := store.Exec(ctx, "INSERT INTO kchain_extended_stats (id) VALUES (1) ON CONFLICT DO NOTHING"); err != nil {
return err
}
// Seed algorithms reference data - simpler INSERT OR IGNORE
algorithms := []string{
"INSERT OR IGNORE INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('ml-kem-768', 'key-exchange', 192, 2400, 0, 1, 0, 'ML-KEM-768 post-quantum key encapsulation', '[\"NIST FIPS 203\"]')",
"INSERT OR IGNORE INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('ml-dsa-65', 'signing', 192, 0, 3309, 1, 0, 'ML-DSA-65 post-quantum digital signature', '[\"NIST FIPS 204\"]')",
"INSERT OR IGNORE INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('bls-threshold', 'signing', 128, 0, 96, 0, 1, 'BLS12-381 threshold signatures', '[\"IETF BLS Signature\"]')",
"INSERT OR IGNORE INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('secp256k1', 'signing', 128, 0, 64, 0, 0, 'ECDSA on secp256k1 (Ethereum compatible)', '[\"SEC 2\"]')",
"INSERT OR IGNORE INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('frost-secp256k1', 'signing', 128, 0, 64, 0, 1, 'FROST threshold Schnorr on secp256k1', '[\"IETF FROST\", \"BIP-340\"]')",
"INSERT INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('ml-kem-768', 'key-exchange', 192, 2400, 0, 1, 0, 'ML-KEM-768 post-quantum key encapsulation', '[\"NIST FIPS 203\"]') ON CONFLICT DO NOTHING",
"INSERT INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('ml-dsa-65', 'signing', 192, 0, 3309, 1, 0, 'ML-DSA-65 post-quantum digital signature', '[\"NIST FIPS 204\"]') ON CONFLICT DO NOTHING",
"INSERT INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('bls-threshold', 'signing', 128, 0, 96, 0, 1, 'BLS12-381 threshold signatures', '[\"IETF BLS Signature\"]') ON CONFLICT DO NOTHING",
"INSERT INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('secp256k1', 'signing', 128, 0, 64, 0, 0, 'ECDSA on secp256k1 (Ethereum compatible)', '[\"SEC 2\"]') ON CONFLICT DO NOTHING",
"INSERT INTO kchain_algorithms (name, type, security_level, key_size, signature_size, post_quantum, threshold_support, description, standards) VALUES ('frost-secp256k1', 'signing', 128, 0, 64, 0, 1, 'FROST threshold Schnorr on secp256k1', '[\"IETF FROST\", \"BIP-340\"]') ON CONFLICT DO NOTHING",
}
for _, q := range algorithms {
_ = store.Exec(ctx, q)
+6 -6
View File
@@ -330,8 +330,8 @@ func (a *Adapter) GetStats(ctx context.Context, store storage.Store) (map[string
// Get validator stats
validatorRows, _ := store.Query(ctx, "SELECT COUNT(*) as cnt FROM pchain_validators")
activeRows, _ := store.Query(ctx, "SELECT COUNT(*) as cnt FROM pchain_validators WHERE end_time > datetime('now')")
stakeRows, _ := store.Query(ctx, "SELECT COALESCE(SUM(stake_amount), 0) as total FROM pchain_validators WHERE end_time > datetime('now')")
activeRows, _ := store.Query(ctx, "SELECT COUNT(*) as cnt FROM pchain_validators WHERE end_time > NOW()")
stakeRows, _ := store.Query(ctx, "SELECT COALESCE(SUM(stake_amount), 0) as total FROM pchain_validators WHERE end_time > NOW()")
var totalValidators, activeValidators int64
var totalStake int64
@@ -358,8 +358,8 @@ func (a *Adapter) GetStats(ctx context.Context, store storage.Store) (map[string
}
// Get delegator stats
delegatorRows, _ := store.Query(ctx, "SELECT COUNT(*) as cnt FROM pchain_delegators WHERE end_time > datetime('now')")
delegatedRows, _ := store.Query(ctx, "SELECT COALESCE(SUM(stake_amount), 0) as total FROM pchain_delegators WHERE end_time > datetime('now')")
delegatorRows, _ := store.Query(ctx, "SELECT COUNT(*) as cnt FROM pchain_delegators WHERE end_time > NOW()")
delegatedRows, _ := store.Query(ctx, "SELECT COALESCE(SUM(stake_amount), 0) as total FROM pchain_delegators WHERE end_time > NOW()")
var totalDelegators int64
var totalDelegated int64
@@ -532,7 +532,7 @@ func (a *Adapter) SyncValidators(ctx context.Context, store storage.Store) error
for _, v := range validators {
err := store.Exec(ctx, `
INSERT INTO pchain_validators (node_id, start_time, end_time, stake_amount, potential_reward, delegation_fee, uptime, connected, tx_id, updated_at)
VALUES (?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
VALUES (?, to_timestamp(?), to_timestamp(?), ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
ON CONFLICT (node_id) DO UPDATE SET
end_time = EXCLUDED.end_time,
stake_amount = EXCLUDED.stake_amount,
@@ -549,7 +549,7 @@ func (a *Adapter) SyncValidators(ctx context.Context, store storage.Store) error
for _, d := range v.Delegators {
err := store.Exec(ctx, `
INSERT INTO pchain_delegators (tx_id, node_id, start_time, end_time, stake_amount, potential_reward, reward_owner)
VALUES (?, ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?, ?, ?)
VALUES (?, ?, to_timestamp(?), to_timestamp(?), ?, ?, ?)
ON CONFLICT (tx_id) DO UPDATE SET
end_time = EXCLUDED.end_time,
potential_reward = EXCLUDED.potential_reward
+38 -6
View File
@@ -275,7 +275,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
// Create lattice parameters table
err = store.Exec(ctx, `
CREATE TABLE IF NOT EXISTS qchain_lattice_params (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
dimension INTEGER NOT NULL,
modulus INTEGER NOT NULL,
@@ -307,8 +307,9 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
}
for _, d := range defaults {
_ = store.Exec(ctx, `
INSERT OR IGNORE INTO qchain_lattice_params (name, dimension, modulus, error_bound, security_level, algorithm, description)
INSERT INTO qchain_lattice_params (name, dimension, modulus, error_bound, security_level, algorithm, description)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING
`, d.name, d.dimension, d.modulus, d.errorBound, d.secLvl, d.algorithm, d.description)
}
@@ -384,7 +385,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
return fmt.Errorf("create extended stats table: %w", err)
}
_ = store.Exec(ctx, `INSERT OR IGNORE INTO qchain_extended_stats (id) VALUES (1)`)
_ = store.Exec(ctx, `INSERT INTO qchain_extended_stats (id) VALUES (1) ON CONFLICT DO NOTHING`)
return nil
}
@@ -464,10 +465,21 @@ func (a *Adapter) StoreProof(ctx context.Context, store storage.Store, proof *Fi
verified = 1
}
return store.Exec(ctx, `
INSERT OR REPLACE INTO qchain_finality_proofs
INSERT INTO qchain_finality_proofs
(id, vertex_id, proof_type, lattice_dimension, lattice_modulus,
lattice_error_bound, security_level, algorithm, signature, public_key, verified)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
vertex_id = EXCLUDED.vertex_id,
proof_type = EXCLUDED.proof_type,
lattice_dimension = EXCLUDED.lattice_dimension,
lattice_modulus = EXCLUDED.lattice_modulus,
lattice_error_bound = EXCLUDED.lattice_error_bound,
security_level = EXCLUDED.security_level,
algorithm = EXCLUDED.algorithm,
signature = EXCLUDED.signature,
public_key = EXCLUDED.public_key,
verified = EXCLUDED.verified
`,
proof.ID, proof.VertexID, proof.ProofType,
proof.LatticeParams.Dimension, proof.LatticeParams.Modulus,
@@ -538,9 +550,19 @@ func (a *Adapter) StoreStamp(ctx context.Context, store storage.Store, stamp *Qu
certified = 1
}
return store.Exec(ctx, `
INSERT OR REPLACE INTO qchain_stamps
INSERT INTO qchain_stamps
(id, vertex_id, chain_id, block_height, block_hash, entropy, key_id, signature, timestamp, certified)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
vertex_id = EXCLUDED.vertex_id,
chain_id = EXCLUDED.chain_id,
block_height = EXCLUDED.block_height,
block_hash = EXCLUDED.block_hash,
entropy = EXCLUDED.entropy,
key_id = EXCLUDED.key_id,
signature = EXCLUDED.signature,
timestamp = EXCLUDED.timestamp,
certified = EXCLUDED.certified
`, stamp.ID, stamp.VertexID, stamp.ChainID, stamp.BlockHeight, stamp.BlockHash,
stamp.Entropy, stamp.KeyID, stamp.Signature, stamp.Timestamp, certified)
}
@@ -552,9 +574,19 @@ func (a *Adapter) StoreCoronaKey(ctx context.Context, store storage.Store, key *
revoked = 1
}
return store.Exec(ctx, `
INSERT OR REPLACE INTO qchain_corona_keys
INSERT INTO qchain_corona_keys
(id, public_key, key_type, algorithm, security_level, owner, valid_from, valid_until, revoked, vertex_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
public_key = EXCLUDED.public_key,
key_type = EXCLUDED.key_type,
algorithm = EXCLUDED.algorithm,
security_level = EXCLUDED.security_level,
owner = EXCLUDED.owner,
valid_from = EXCLUDED.valid_from,
valid_until = EXCLUDED.valid_until,
revoked = EXCLUDED.revoked,
vertex_id = EXCLUDED.vertex_id
`, key.ID, key.PublicKey, key.KeyType, key.Algorithm, key.SecurityLvl,
key.Owner, key.ValidFrom, key.ValidUntil, revoked, vertexID)
}
+47 -5
View File
@@ -463,7 +463,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
return fmt.Errorf("create mpc stats table: %w", err)
}
_ = store.Exec(ctx, `INSERT OR IGNORE INTO tchain_mpc_stats (id) VALUES (1)`)
_ = store.Exec(ctx, `INSERT INTO tchain_mpc_stats (id) VALUES (1) ON CONFLICT DO NOTHING`)
return nil
}
@@ -584,16 +584,38 @@ func (a *Adapter) StoreSession(ctx context.Context, store storage.Store, s *Sign
signatures, _ := json.Marshal(s.Signatures)
return store.Exec(ctx, `
INSERT OR REPLACE INTO tchain_sessions (id, threshold, total_shares, message_hash, participants, signatures, final_sig, status, source_chain, dest_chain, created_at, completed_at, expires_at)
INSERT INTO tchain_sessions (id, threshold, total_shares, message_hash, participants, signatures, final_sig, status, source_chain, dest_chain, created_at, completed_at, expires_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
threshold = EXCLUDED.threshold,
total_shares = EXCLUDED.total_shares,
message_hash = EXCLUDED.message_hash,
participants = EXCLUDED.participants,
signatures = EXCLUDED.signatures,
final_sig = EXCLUDED.final_sig,
status = EXCLUDED.status,
source_chain = EXCLUDED.source_chain,
dest_chain = EXCLUDED.dest_chain,
created_at = EXCLUDED.created_at,
completed_at = EXCLUDED.completed_at,
expires_at = EXCLUDED.expires_at
`, s.ID, s.Threshold, s.TotalShares, s.MessageHash, string(participants), string(signatures), s.FinalSig, s.Status, s.SourceChain, s.DestChain, s.CreatedAt, s.CompletedAt, s.ExpiresAt)
}
// StoreKeyShare stores a key share
func (a *Adapter) StoreKeyShare(ctx context.Context, store storage.Store, k *KeyShare) error {
return store.Exec(ctx, `
INSERT OR REPLACE INTO tchain_key_shares (id, public_key, share_index, node_id, keygen_id, status, created_at, rotated_at, expires_at)
INSERT INTO tchain_key_shares (id, public_key, share_index, node_id, keygen_id, status, created_at, rotated_at, expires_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
public_key = EXCLUDED.public_key,
share_index = EXCLUDED.share_index,
node_id = EXCLUDED.node_id,
keygen_id = EXCLUDED.keygen_id,
status = EXCLUDED.status,
created_at = EXCLUDED.created_at,
rotated_at = EXCLUDED.rotated_at,
expires_at = EXCLUDED.expires_at
`, k.ID, k.PublicKey, k.ShareIndex, k.NodeID, k.KeyGenID, k.Status, k.CreatedAt, k.RotatedAt, k.ExpiresAt)
}
@@ -602,16 +624,36 @@ func (a *Adapter) StoreKeyGeneration(ctx context.Context, store storage.Store, k
participants, _ := json.Marshal(kg.Participants)
return store.Exec(ctx, `
INSERT OR REPLACE INTO tchain_key_generations (id, threshold, total_shares, public_key, participants, status, created_at, completed_at)
INSERT INTO tchain_key_generations (id, threshold, total_shares, public_key, participants, status, created_at, completed_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
threshold = EXCLUDED.threshold,
total_shares = EXCLUDED.total_shares,
public_key = EXCLUDED.public_key,
participants = EXCLUDED.participants,
status = EXCLUDED.status,
created_at = EXCLUDED.created_at,
completed_at = EXCLUDED.completed_at
`, kg.ID, kg.Threshold, kg.TotalShares, kg.PublicKey, string(participants), kg.Status, kg.CreatedAt, kg.CompletedAt)
}
// StoreMessage stores a teleport message
func (a *Adapter) StoreMessage(ctx context.Context, store storage.Store, m *TeleportMessage) error {
return store.Exec(ctx, `
INSERT OR REPLACE INTO tchain_messages (id, source_chain, dest_chain, sender, receiver, payload, nonce, session_id, status, created_at, signed_at, delivered_at)
INSERT INTO tchain_messages (id, source_chain, dest_chain, sender, receiver, payload, nonce, session_id, status, created_at, signed_at, delivered_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
source_chain = EXCLUDED.source_chain,
dest_chain = EXCLUDED.dest_chain,
sender = EXCLUDED.sender,
receiver = EXCLUDED.receiver,
payload = EXCLUDED.payload,
nonce = EXCLUDED.nonce,
session_id = EXCLUDED.session_id,
status = EXCLUDED.status,
created_at = EXCLUDED.created_at,
signed_at = EXCLUDED.signed_at,
delivered_at = EXCLUDED.delivered_at
`, m.ID, m.SourceChain, m.DestChain, m.Sender, m.Receiver, string(m.Payload), m.Nonce, m.SessionID, m.Status, m.CreatedAt, m.SignedAt, m.DeliveredAt)
}
+9 -6
View File
@@ -392,7 +392,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
// Create ZK proofs archive table
err = store.Exec(ctx, `
CREATE TABLE IF NOT EXISTS zchain_proofs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id SERIAL PRIMARY KEY,
tx_id TEXT NOT NULL,
proof_type TEXT NOT NULL,
proof_data TEXT NOT NULL,
@@ -423,7 +423,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
return fmt.Errorf("create merkle state table: %w", err)
}
_ = store.Exec(ctx, `INSERT OR IGNORE INTO zchain_merkle_state (id, root, height, leaf_count) VALUES (1, '', 0, 0)`)
_ = store.Exec(ctx, `INSERT INTO zchain_merkle_state (id, root, height, leaf_count) VALUES (1, '', 0, 0) ON CONFLICT DO NOTHING`)
// Create extended stats table
err = store.Exec(ctx, `
@@ -442,7 +442,7 @@ func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error {
return fmt.Errorf("create extended stats table: %w", err)
}
_ = store.Exec(ctx, `INSERT OR IGNORE INTO zchain_extended_stats (id) VALUES (1)`)
_ = store.Exec(ctx, `INSERT INTO zchain_extended_stats (id) VALUES (1) ON CONFLICT DO NOTHING`)
return nil
}
@@ -537,8 +537,9 @@ func (a *Adapter) GetStats(ctx context.Context, store storage.Store) (map[string
func (a *Adapter) StoreTransfer(ctx context.Context, store storage.Store, t ShieldedTransfer, vertexID string) error {
// Store transfer
err := store.Exec(ctx, `
INSERT OR IGNORE INTO zchain_transfers (tx_id, type, proof_type, proof_data, value_balance, fee, memo, timestamp, vertex_id)
INSERT INTO zchain_transfers (tx_id, type, proof_type, proof_data, value_balance, fee, memo, timestamp, vertex_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING
`, t.TxID, t.Type, t.Proof.Type, t.Proof.Data, t.ValueBalance, t.Fee, t.Memo, t.Timestamp, vertexID)
if err != nil {
return fmt.Errorf("store transfer: %w", err)
@@ -557,8 +558,9 @@ func (a *Adapter) StoreTransfer(ctx context.Context, store storage.Store, t Shie
// Store nullifiers
for _, n := range t.Nullifiers {
err = store.Exec(ctx, `
INSERT OR IGNORE INTO zchain_nullifiers (hash, tx_id, idx, spent_at)
INSERT INTO zchain_nullifiers (hash, tx_id, idx, spent_at)
VALUES (?, ?, ?, ?)
ON CONFLICT DO NOTHING
`, n.Hash, n.TxID, n.Index, n.SpentAt)
if err != nil {
return fmt.Errorf("store nullifier: %w", err)
@@ -572,8 +574,9 @@ func (a *Adapter) StoreTransfer(ctx context.Context, store storage.Store, t Shie
spent = 1
}
err = store.Exec(ctx, `
INSERT OR IGNORE INTO zchain_commitments (hash, tx_id, idx, created_at, spent)
INSERT INTO zchain_commitments (hash, tx_id, idx, created_at, spent)
VALUES (?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING
`, c.Hash, c.TxID, c.Index, c.CreatedAt, spent)
if err != nil {
return fmt.Errorf("store commitment: %w", err)