feat: added models
This commit is contained in:
3
server/.gitignore
vendored
3
server/.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
# Go files
|
||||||
|
ccoin
|
||||||
|
|
||||||
# Compiled class file
|
# Compiled class file
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
|
|||||||
0
server/Dockerfile
Normal file
0
server/Dockerfile
Normal file
2
server/database/tables/main.go
Normal file
2
server/database/tables/main.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
package tables
|
||||||
|
|
||||||
0
server/docker-compose.yml
Normal file
0
server/docker-compose.yml
Normal file
3
server/go.mod
Normal file
3
server/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module ccoin
|
||||||
|
|
||||||
|
go 1.25.5
|
||||||
70
server/models/api/model.go
Normal file
70
server/models/api/model.go
Normal file
@@ -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"
|
||||||
|
)
|
||||||
2
server/models/block/model.go
Normal file
2
server/models/block/model.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
package block
|
||||||
|
|
||||||
39
server/models/transaction/model.go
Normal file
39
server/models/transaction/model.go
Normal file
@@ -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"
|
||||||
|
)
|
||||||
24
server/models/wallet/model.go
Normal file
24
server/models/wallet/model.go
Normal file
@@ -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"`
|
||||||
|
}
|
||||||
5
server/server.go
Normal file
5
server/server.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
println("Hello world")
|
||||||
|
}
|
||||||
2
server/utils/crypto/main.go
Normal file
2
server/utils/crypto/main.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
package crypto
|
||||||
|
|
||||||
2
server/utils/extensions.go
Normal file
2
server/utils/extensions.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
2
server/utils/hash/main.go
Normal file
2
server/utils/hash/main.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
package hash
|
||||||
|
|
||||||
Reference in New Issue
Block a user