diff --git a/server/.gitignore b/server/.gitignore index 7d61c09..7921cd7 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,3 +1,6 @@ +# Go files +ccoin + # Compiled class file *.class diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/server/database/tables/main.go b/server/database/tables/main.go new file mode 100644 index 0000000..43f51a6 --- /dev/null +++ b/server/database/tables/main.go @@ -0,0 +1,2 @@ +package tables + diff --git a/server/docker-compose.yml b/server/docker-compose.yml new file mode 100644 index 0000000..e69de29 diff --git a/server/go.mod b/server/go.mod new file mode 100644 index 0000000..6d33007 --- /dev/null +++ b/server/go.mod @@ -0,0 +1,3 @@ +module ccoin + +go 1.25.5 diff --git a/server/models/api/model.go b/server/models/api/model.go new file mode 100644 index 0000000..3defce7 --- /dev/null +++ b/server/models/api/model.go @@ -0,0 +1,70 @@ +package api + +type ApiResponse[T any] struct { + Success bool `json:"success"` + Data *T `json:"data,omitempty"` // Nullable data + Error *string `json:"error,omitempty"` // Nullable error message + Timestamp int64 `json:"timestamp"` +} + +type ErrorResponse struct { + Error string `json:"error"` + Code *string `json:"code,omitempty"` + Details map[string]string `json:"details,omitempty"` + Timestamp int64 `json:"timestamp"` +} + +type SuccessResponse struct { + Message string `json:"message"` + Timestamp int64 `json:"timestamp"` +} + +type HealthResponse struct { + Status string `json:"status"` + Version string `json:"version"` + Uptime int64 `json:"uptime"` + Database DatabaseHealth `json:"database"` + BlockChain BlockChainHealth `json:"blockchain"` +} + +type DatabaseHealth struct { + Connected bool `json:"connected"` + ResponseTime int64 `json:"response_time"` + ActiveConnections int `json:"active_connections"` + MaxConnections int `json:"max_connections"` +} + +type BlockChainHealth struct { + LatestBlock int `json:"latest_block"` + PendingTransactions int `json:"pending_transactions"` + NetworkHashRate float64 `json:"network_hash_rate"` + AverageBlockTime int64 `json:"average_block_time"` +} + +type PaginationRequest struct { + Page int `json:"page"` + PageSize int `json:"page_size"` + SortBy *string `json:"sort_by,omitempty"` + SortOrder SortOrder `json:"sort_order"` +} + +type PaginatedResponse[T any] struct { + Data []T `json:"data"` + Pagination PaginationInfo `json:"pagination"` +} + +type PaginationInfo struct { + CurrentPage int `json:"current_page"` + PageSize int `json:"page_size"` + TotalItems int `json:"total_items"` + TotalPages int `json:"total_pages"` + HasNext bool `json:"has_next"` + HasPrevious bool `json:"has_previous"` +} + +type SortOrder string + +const ( + ASC SortOrder = "ASC" + DESC SortOrder = "DESC" +) diff --git a/server/models/block/model.go b/server/models/block/model.go new file mode 100644 index 0000000..e1c2ab6 --- /dev/null +++ b/server/models/block/model.go @@ -0,0 +1,2 @@ +package block + diff --git a/server/models/transaction/model.go b/server/models/transaction/model.go new file mode 100644 index 0000000..d21e18a --- /dev/null +++ b/server/models/transaction/model.go @@ -0,0 +1,39 @@ +package transaction + +type SendTransactionRequest struct { + FromAddress string `json:"from_address"` + ToAddress string `json:"to_address"` + Amount float64 `json:"amount"` + Fee float64 `json:"fee"` + Memo *string `json:"memo,omitempty"` + Password string `json:"password"` +} + +type TransactionResponse struct { + Hash string `json:"hash"` + FromAddress *string `json:"from_address,omitempty"` + ToAddress string `json:"to_address"` + Amount float64 `json:"amount"` + Fee float64 `json:"fee"` + Memo *string `json:"memo,omitempty"` + BlockHash string `json:"block_hash"` + Timestamp int64 `json:"timestamp"` + Status string `json:"status"` + Confirmations int `json:"confirmations"` +} + +type TransactionHistoryResponse struct { + Transactions []TransactionResponse `json:"transactions"` + TotalCount int `json:"total_count"` + Page int `json:"page"` + PageSize int `json:"page_size"` +} + +type TransactionStatus string + +const ( + PENDING TransactionStatus = "PENDING" + CONFIRMED TransactionStatus = "CONFIRMED" + FAILED TransactionStatus = "FAILED" + CANCELLED TransactionStatus = "CANCELLED" +) diff --git a/server/models/wallet/model.go b/server/models/wallet/model.go new file mode 100644 index 0000000..79b3568 --- /dev/null +++ b/server/models/wallet/model.go @@ -0,0 +1,24 @@ +package wallet + +type CreateWalletRequest struct { + Label *string `json:"label,omitempty"` + Password string `json:"password"` +} + +type WalletResponse struct { + Address string `json:"address"` // Format: "random_word:123456" (e.g. "cave:595462") + Balance float64 `json:"balance"` + Label *string `json:"label,omitempty"` + PasswordHash string `json:"password_hash"` + CreatedAt int64 `json:"created_at"` + LastActivity *int64 `json:"last_activity,omitempty"` +} + +type BalanceResponse struct { + Address string `json:"address"` + Balance float64 `json:"balance"` +} + +type UpdateWalletRequest struct { + Label *string `json:"label,omitempty"` +} diff --git a/server/server.go b/server/server.go new file mode 100644 index 0000000..344d51f --- /dev/null +++ b/server/server.go @@ -0,0 +1,5 @@ +package main + +func main() { + println("Hello world") +} diff --git a/server/utils/crypto/main.go b/server/utils/crypto/main.go new file mode 100644 index 0000000..e4f8dd1 --- /dev/null +++ b/server/utils/crypto/main.go @@ -0,0 +1,2 @@ +package crypto + diff --git a/server/utils/extensions.go b/server/utils/extensions.go new file mode 100644 index 0000000..9008f48 --- /dev/null +++ b/server/utils/extensions.go @@ -0,0 +1,2 @@ +package utils + diff --git a/server/utils/hash/main.go b/server/utils/hash/main.go new file mode 100644 index 0000000..301e290 --- /dev/null +++ b/server/utils/hash/main.go @@ -0,0 +1,2 @@ +package hash +