Files

454 lines
11 KiB
MySQL
Raw Permalink Normal View History

Refactor/orm (#7) * feat/refactor-motr * feat/refactor-motr * feat: introduce Cloudflare Workers gateway application * chore: migrate build system from Makefile to Taskfile for improved automation * feat: streamline task management with Taskfile consolidation * feat: consolidate build and install tasks for simplified workflows * <no value> * feat: enable publishing for core packages * feat/refactor-motr * feat: integrate updated crypto library for enhanced security * ci: Configure CI/CD to build and test WASM signer * refactor: streamline build process using npm scripts * fix: Correct template file paths for accurate error reporting * refactor: standardize templ file paths for improved maintainability * chore: remove package documentation * build: exclude documentation artifacts from version control * feat: serve static assets from cloudflare worker * feat: introduce Motr controller service * refactor: move UI components to separate ui module * refactor: move resolver middleware to top-level middleware directory * feat: introduce modular middleware architecture * refactor: improve separation of concerns by relocating endpoint definitions * build: simplify codebase by deleting unused info types * refactor: decouple middleware configurations * feat: integrate request middleware for enhanced processing * feat: implement register and login pages * feat: integrate WASM signer for enhanced security * refactor: move type definitions to models package * refactor: rename ipfs middleware to vault middleware * feat: Add Dockerfile for controller service * feat: Add Dockerfile for controller with multi-stage build * chore: Update Golang version to 1.24.2 in Dockerfile * feat: introduce Docker support for application deployment * feat: Implement WASM-based signing service * feat: migrate build system to Taskfile for improved automation * feat: enable docker-based development for controller and resolver * feat: Add docker-compose services for resolver and controller workers * refactor: streamline build and deployment processes with Devbox * chore: standardize development environment with Devbox * chore: standardize container entrypoint for improved consistency * feat: introduce docker-compose setup for local development * feat: remove initial placeholder code * refactor: restructure project modules for improved organization * feat: integrate motr UI library for enhanced components * chore: upgrade motr dependency to v0.0.3 * refactor: restructure project layout for improved modularity * refactor: consolidate data models and options into directory * feat: integrate sqlc for database interaction * feat: integrate D1 database for improved data management * refactor: improve naming consistency across project * feat: enhance context with HTTP header utilities * refactor: restructure project layout for improved maintainability * refactor: centralize rendering logic into middleware * chore: update motr dependency to v0.0.5 to address data consistency issues * feat: consolidate handler logic into root * refactor: relocate handlers and middleware to internal packages * chore: update dependency to v0.9.0 * refactor: Improve code structure and add comprehensive documentation for WebAssembly signer module * feat: implement WASM-based signing functionality * chore: remove build system configuration * feat: integrate D1 database for persistent data storage * feat: enable D1 database integration for Cloudflare Workers * feat: enhance task execution with docker-compose integration * refactor: centralize database queries and models * refactor: improve sqlc code generation and project structure * docs: Update README with Docker support and new project architecture * refactor: centralize Sonr configuration via middleware * chore: improve build task definitions in Taskfile * chore: remove docker deployment configuration * feat: upgrade crypto module to v0.11.0 * refactor: migrate to a configuration-driven architecture * refactor: inject database common queries into index handler * feat: streamline worker initialization * refactor: standardize package versioning process * build: prepare vault package for public release * feat: enable WASM-based vault signing with durable objects * feat: introduce Vault service for enhanced security * feat: upgrade crypto library to v0.12.1 for enhanced security features * build: update middleware build constraints * feat: introduce struct-based handlers for improved organization * feat: centralize database configuration * build: update database seeding to target remote instance * feat: enhance asset handling with shared coin type * feat: decouple build process from database initialization * refactor: move base UI components to a dedicated directory * refactor: improve component structure for enhanced maintainability * refactor: rename binding for clarity and consistency * feat: introduce development task and environment configurations * feat: introduce mprocs for simplified local development * <no value> * refactor: rename Vault DB to Controller DB for clarity * refactor: simplify configuration loading and database connections * feat: introduce MotrMode configuration to differentiate service roles * refactor: restructure base components and consolidate metadata handling * feat: introduce session context middleware for request handling * feat: enhance task management with database migration support * feat: Add database controller middleware and context retrieval methods * refactor: Improve session context handling and add full database controller middleware * feat: integrate Helia and Extism for Vault durable object * refactor: rename resolver to frontend * feat: streamline infrastructure and data management * refactor: improve task management and dependency loading * fix: remove legacy fetch handler from vault worker * feat: integrate WebAuthn for secure authentication * build: add hx-trigger for enhanced interaction * refactor: centralize session ID handling in middleware * refactor: simplify session context initialization * feat/split workers (#6) * refactor: rename claim route to register for clarity * refactor: rename demo view to dashboard view * feat: automate build and publish process * refactor: unify database queries and models for vault operations * feat: implement WASM compatible server and routing * feat: introduce controller-based routing * feat: implement passkey-based authentication * feat: implement Cloudflare cache middleware for improved performance * refactor: move ui components to ui package * feat: add handler functions for login and registration * refactor: centralize route registration logic * feat: implement user registration and login with passkey support * refactor: restructure view components for improved organization * feat: enable handle-based authentication and session management * refactor: improve config access and remove unused dependencies * refactor: restructure middleware and configuration for clarity * refactor: Remove external libraries * docs: update architecture to reflect removal of WASM build * refactor: centralize metadata and coin info types * refactor: move auth types to auth package * refactor: remove session management from vault service * refactor: reorganize UI components and middleware for clarity * refactor: move UI components to internal directory * feat: add session expiry configuration * refactor: streamline Taskfile and remove deprecated options * feat: introduce account entities and UI components * refactor: streamline asset representation with entity interfaces * feat: introduce asset pricing and market data * feat: enhance radar with session and cache middleware * fix: update dependencies and resolve peer dependency conflicts * feat: add blockchain entity and data model * feat: introduce entity-specific query interfaces * feat: Implement transaction creation, signing, and broadcasting methods * feat: implement durable object vault with RPC and IPFS support * refactor: align protobuf imports with updated cosm-orc package * feat: simplify auth components by removing options * feat: enhance data models for comprehensive crypto analysis * feat: implement account lookup by handle * refactor: simplify account card rendering * feat: enhance UI rendering with middleware * feat: remove helia file operations * build: scaffold navigation component with templ * feat: introduce UI layout components and dependency management * feat: remove unused assets for templated html * feat: implement authentication flow with WebAuthn and handle registration * feat: remove radar cmd * feat: enhance application architecture with module-based structure * refactor: relocate config and middleware to internal packages * feat: integrate session management into landing page * feat: improve landing page handler setup and session handling * feat: streamline initial setup and configuration process * chore: reorganize project layout for clarity and maintainability * chore: reorganize project structure by moving workers to 'cmd' * refactor/orm * feat: enhance task automation with root directory task * refactor: relocate chart components to dedicated directory
2025-05-09 12:51:47 -04:00
-- ASSET QUERIES
-- name: InsertAsset :one
INSERT INTO assets (
name,
symbol,
decimals,
chain_id,
channel,
asset_type,
coingecko_id
) VALUES (?, ?, ?, ?, ?, ?, ?)
RETURNING *;
-- name: GetAssetByID :one
SELECT * FROM assets
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAssetBySymbol :one
SELECT * FROM assets
WHERE symbol = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAssetByChainAndSymbol :one
SELECT * FROM assets
WHERE chain_id = ? AND symbol = ? AND deleted_at IS NULL
LIMIT 1;
-- name: ListAssetsByChain :many
SELECT * FROM assets
WHERE chain_id = ? AND deleted_at IS NULL
ORDER BY symbol ASC;
-- name: UpdateAsset :one
UPDATE assets
SET
name = ?,
decimals = ?,
channel = ?,
asset_type = ?,
coingecko_id = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: SoftDeleteAsset :exec
UPDATE assets
SET deleted_at = CURRENT_TIMESTAMP
WHERE id = ?;
-- PRICE QUERIES (UPDATED)
-- name: InsertPrice :one
INSERT INTO prices (
asset_id,
price_usd,
price_btc,
volume_24h_usd,
market_cap_usd,
available_supply,
total_supply,
max_supply,
percent_change_1h,
percent_change_24h,
percent_change_7d,
rank,
last_updated
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING *;
-- name: GetPriceByAssetID :one
SELECT * FROM prices
WHERE asset_id = ? AND deleted_at IS NULL
ORDER BY last_updated DESC
LIMIT 1;
-- name: GetPriceByID :one
SELECT * FROM prices
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;
-- name: ListPriceHistoryByAssetID :many
SELECT * FROM prices
WHERE asset_id = ? AND deleted_at IS NULL
ORDER BY last_updated DESC
LIMIT ? OFFSET ?;
-- name: GetAssetWithLatestPrice :one
SELECT a.*, p.price_usd, p.price_btc, p.volume_24h_usd, p.market_cap_usd,
p.available_supply, p.total_supply, p.max_supply,
p.percent_change_1h, p.percent_change_24h, p.percent_change_7d,
p.rank, p.last_updated
FROM assets a
LEFT JOIN (
SELECT p1.*
FROM prices p1
INNER JOIN (
SELECT asset_id, MAX(last_updated) as max_date
FROM prices
WHERE deleted_at IS NULL
GROUP BY asset_id
) p2 ON p1.asset_id = p2.asset_id AND p1.last_updated = p2.max_date
WHERE p1.deleted_at IS NULL
) p ON a.id = p.asset_id
WHERE a.id = ? AND a.deleted_at IS NULL
LIMIT 1;
-- name: ListAssetsWithLatestPrices :many
SELECT a.*, p.price_usd, p.price_btc, p.volume_24h_usd, p.market_cap_usd,
p.available_supply, p.total_supply, p.max_supply,
p.percent_change_1h, p.percent_change_24h, p.percent_change_7d,
p.rank, p.last_updated
FROM assets a
LEFT JOIN (
SELECT p1.*
FROM prices p1
INNER JOIN (
SELECT asset_id, MAX(last_updated) as max_date
FROM prices
WHERE deleted_at IS NULL
GROUP BY asset_id
) p2 ON p1.asset_id = p2.asset_id AND p1.last_updated = p2.max_date
WHERE p1.deleted_at IS NULL
) p ON a.id = p.asset_id
WHERE a.deleted_at IS NULL
ORDER BY p.rank ASC, a.symbol ASC
LIMIT ? OFFSET ?;
-- name: UpdatePrice :one
UPDATE prices
SET
price_usd = ?,
price_btc = ?,
volume_24h_usd = ?,
market_cap_usd = ?,
available_supply = ?,
total_supply = ?,
max_supply = ?,
percent_change_1h = ?,
percent_change_24h = ?,
percent_change_7d = ?,
rank = ?,
last_updated = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- PRICE CONVERSION QUERIES (NEW)
-- name: InsertPriceConversion :one
INSERT INTO price_conversions (
price_id,
currency_code,
price,
volume_24h,
market_cap,
last_updated
) VALUES (?, ?, ?, ?, ?, ?)
RETURNING *;
-- name: GetPriceConversionByID :one
SELECT * FROM price_conversions
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetPriceConversionsByPriceID :many
SELECT * FROM price_conversions
WHERE price_id = ? AND deleted_at IS NULL
ORDER BY currency_code ASC;
-- name: GetPriceConversionByCurrency :one
SELECT * FROM price_conversions
WHERE price_id = ? AND currency_code = ? AND deleted_at IS NULL
LIMIT 1;
-- name: UpdatePriceConversion :one
UPDATE price_conversions
SET
price = ?,
volume_24h = ?,
market_cap = ?,
last_updated = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: SoftDeletePriceConversion :exec
UPDATE price_conversions
SET deleted_at = CURRENT_TIMESTAMP
WHERE id = ?;
-- BLOCKCHAIN QUERIES
-- name: InsertBlockchain :one
INSERT INTO blockchains (
id,
chain_name,
chain_id_cosmos,
chain_id_evm,
api_name,
bech_account_prefix,
bech_validator_prefix,
main_asset_symbol,
main_asset_denom,
staking_asset_symbol,
staking_asset_denom,
is_stake_enabled,
chain_image,
main_asset_image,
staking_asset_image,
chain_type,
is_support_mobile_wallet,
is_support_extension_wallet,
is_support_erc20,
description_en,
description_ko,
description_ja,
origin_genesis_time,
account_type,
btc_staking,
cosmos_fee_info,
evm_fee_info,
lcd_endpoint,
grpc_endpoint,
evm_rpc_endpoint,
explorer,
about,
forum
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING *;
-- name: GetBlockchainByID :one
SELECT * FROM blockchains
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetBlockchainByChainName :one
SELECT * FROM blockchains
WHERE chain_name = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetBlockchainByCosmosChainID :one
SELECT * FROM blockchains
WHERE chain_id_cosmos = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetBlockchainByEvmChainID :one
SELECT * FROM blockchains
WHERE chain_id_evm = ? AND deleted_at IS NULL
LIMIT 1;
-- name: ListAllBlockchains :many
SELECT * FROM blockchains
WHERE deleted_at IS NULL
ORDER BY chain_name ASC;
-- name: ListBlockchainsByChainType :many
SELECT * FROM blockchains
WHERE chain_type LIKE '%' || ? || '%' AND deleted_at IS NULL
ORDER BY chain_name ASC;
-- name: ListBlockchainsWithStaking :many
SELECT * FROM blockchains
WHERE is_stake_enabled = 1 AND deleted_at IS NULL
ORDER BY chain_name ASC;
-- name: ListBlockchainsWithMobileSupport :many
SELECT * FROM blockchains
WHERE is_support_mobile_wallet = 1 AND deleted_at IS NULL
ORDER BY chain_name ASC;
-- name: ListBlockchainsWithExtensionSupport :many
SELECT * FROM blockchains
WHERE is_support_extension_wallet = 1 AND deleted_at IS NULL
ORDER BY chain_name ASC;
-- name: ListBlockchainsWithERC20Support :many
SELECT * FROM blockchains
WHERE is_support_erc20 = 1 AND deleted_at IS NULL
ORDER BY chain_name ASC;
-- name: UpdateBlockchain :one
UPDATE blockchains
SET
chain_name = ?,
chain_id_cosmos = ?,
chain_id_evm = ?,
api_name = ?,
bech_account_prefix = ?,
bech_validator_prefix = ?,
main_asset_symbol = ?,
main_asset_denom = ?,
staking_asset_symbol = ?,
staking_asset_denom = ?,
is_stake_enabled = ?,
chain_image = ?,
main_asset_image = ?,
staking_asset_image = ?,
chain_type = ?,
is_support_mobile_wallet = ?,
is_support_extension_wallet = ?,
is_support_erc20 = ?,
description_en = ?,
description_ko = ?,
description_ja = ?,
origin_genesis_time = ?,
account_type = ?,
btc_staking = ?,
cosmos_fee_info = ?,
evm_fee_info = ?,
lcd_endpoint = ?,
grpc_endpoint = ?,
evm_rpc_endpoint = ?,
explorer = ?,
about = ?,
forum = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: UpdateBlockchainEndpoints :one
UPDATE blockchains
SET
lcd_endpoint = ?,
grpc_endpoint = ?,
evm_rpc_endpoint = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: UpdateBlockchainExplorer :one
UPDATE blockchains
SET
explorer = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: UpdateBlockchainFeeInfo :one
UPDATE blockchains
SET
cosmos_fee_info = ?,
evm_fee_info = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: UpdateBlockchainImages :one
UPDATE blockchains
SET
chain_image = ?,
main_asset_image = ?,
staking_asset_image = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: UpdateBlockchainDescriptions :one
UPDATE blockchains
SET
description_en = ?,
description_ko = ?,
description_ja = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: UpdateBlockchainSocialLinks :one
UPDATE blockchains
SET
about = ?,
forum = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: SoftDeleteBlockchain :exec
UPDATE blockchains
SET deleted_at = CURRENT_TIMESTAMP
WHERE id = ?;
-- name: GetBlockchainWithAssetInfo :one
SELECT b.*, a.id as asset_id, a.symbol, a.decimals, p.price_usd, p.price_btc
FROM blockchains b
LEFT JOIN assets a ON b.main_asset_symbol = a.symbol
LEFT JOIN (
SELECT p1.*
FROM prices p1
INNER JOIN (
SELECT asset_id, MAX(last_updated) as max_date
FROM prices
WHERE deleted_at IS NULL
GROUP BY asset_id
) p2 ON p1.asset_id = p2.asset_id AND p1.last_updated = p2.max_date
WHERE p1.deleted_at IS NULL
) p ON a.id = p.asset_id
WHERE b.id = ? AND b.deleted_at IS NULL
LIMIT 1;
-- name: ListBlockchainsWithAssetInfo :many
SELECT b.*, a.id as asset_id, a.symbol, a.decimals, p.price_usd, p.price_btc
FROM blockchains b
LEFT JOIN assets a ON b.main_asset_symbol = a.symbol
LEFT JOIN (
SELECT p1.*
FROM prices p1
INNER JOIN (
SELECT asset_id, MAX(last_updated) as max_date
FROM prices
WHERE deleted_at IS NULL
GROUP BY asset_id
) p2 ON p1.asset_id = p2.asset_id AND p1.last_updated = p2.max_date
WHERE p1.deleted_at IS NULL
) p ON a.id = p.asset_id
WHERE b.deleted_at IS NULL
ORDER BY b.chain_name ASC
LIMIT ? OFFSET ?;
-- name: SearchBlockchains :many
SELECT * FROM blockchains
WHERE (
chain_name LIKE '%' || ? || '%' OR
main_asset_symbol LIKE '%' || ? || '%' OR
staking_asset_symbol LIKE '%' || ? || '%' OR
description_en LIKE '%' || ? || '%'
) AND deleted_at IS NULL
ORDER BY chain_name ASC
LIMIT ? OFFSET ?;
-- name: CountBlockchainsByChainType :one
SELECT COUNT(*) as count FROM blockchains
WHERE chain_type LIKE '%' || ? || '%' AND deleted_at IS NULL;
-- name: GetBlockchainEndpoints :one
SELECT id, chain_name, lcd_endpoint, grpc_endpoint, evm_rpc_endpoint
FROM blockchains
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetBlockchainExplorer :one
SELECT id, chain_name, explorer
FROM blockchains
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;