service backend
This commit is contained in:
90
api/chain/gateway/storage/model/wallet.go
Normal file
90
api/chain/gateway/storage/model/wallet.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
)
|
||||
|
||||
type ManagedWalletStatus string
|
||||
|
||||
const (
|
||||
ManagedWalletStatusActive ManagedWalletStatus = "active"
|
||||
ManagedWalletStatusSuspended ManagedWalletStatus = "suspended"
|
||||
ManagedWalletStatusClosed ManagedWalletStatus = "closed"
|
||||
)
|
||||
|
||||
// ManagedWallet represents a user-controlled on-chain wallet managed by the service.
|
||||
type ManagedWallet struct {
|
||||
storable.Base `bson:",inline" json:",inline"`
|
||||
|
||||
IdempotencyKey string `bson:"idempotencyKey" json:"idempotencyKey"`
|
||||
WalletRef string `bson:"walletRef" json:"walletRef"`
|
||||
OrganizationRef string `bson:"organizationRef" json:"organizationRef"`
|
||||
OwnerRef string `bson:"ownerRef" json:"ownerRef"`
|
||||
Network string `bson:"network" json:"network"`
|
||||
TokenSymbol string `bson:"tokenSymbol" json:"tokenSymbol"`
|
||||
ContractAddress string `bson:"contractAddress" json:"contractAddress"`
|
||||
DepositAddress string `bson:"depositAddress" json:"depositAddress"`
|
||||
KeyReference string `bson:"keyReference,omitempty" json:"keyReference,omitempty"`
|
||||
Status ManagedWalletStatus `bson:"status" json:"status"`
|
||||
Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// Collection implements storable.Storable.
|
||||
func (*ManagedWallet) Collection() string {
|
||||
return mservice.ChainWallets
|
||||
}
|
||||
|
||||
// WalletBalance captures computed wallet balances.
|
||||
type WalletBalance struct {
|
||||
storable.Base `bson:",inline" json:",inline"`
|
||||
|
||||
WalletRef string `bson:"walletRef" json:"walletRef"`
|
||||
Available *moneyv1.Money `bson:"available" json:"available"`
|
||||
PendingInbound *moneyv1.Money `bson:"pendingInbound,omitempty" json:"pendingInbound,omitempty"`
|
||||
PendingOutbound *moneyv1.Money `bson:"pendingOutbound,omitempty" json:"pendingOutbound,omitempty"`
|
||||
CalculatedAt time.Time `bson:"calculatedAt" json:"calculatedAt"`
|
||||
}
|
||||
|
||||
// Collection implements storable.Storable.
|
||||
func (*WalletBalance) Collection() string {
|
||||
return mservice.ChainWalletBalances
|
||||
}
|
||||
|
||||
// ManagedWalletFilter describes list filters.
|
||||
type ManagedWalletFilter struct {
|
||||
OrganizationRef string
|
||||
OwnerRef string
|
||||
Network string
|
||||
TokenSymbol string
|
||||
Cursor string
|
||||
Limit int32
|
||||
}
|
||||
|
||||
// ManagedWalletList contains paginated wallet results.
|
||||
type ManagedWalletList struct {
|
||||
Items []*ManagedWallet
|
||||
NextCursor string
|
||||
}
|
||||
|
||||
// Normalize trims string fields for consistent indexing.
|
||||
func (m *ManagedWallet) Normalize() {
|
||||
m.IdempotencyKey = strings.TrimSpace(m.IdempotencyKey)
|
||||
m.WalletRef = strings.TrimSpace(m.WalletRef)
|
||||
m.OrganizationRef = strings.TrimSpace(m.OrganizationRef)
|
||||
m.OwnerRef = strings.TrimSpace(m.OwnerRef)
|
||||
m.Network = strings.TrimSpace(strings.ToLower(m.Network))
|
||||
m.TokenSymbol = strings.TrimSpace(strings.ToUpper(m.TokenSymbol))
|
||||
m.ContractAddress = strings.TrimSpace(strings.ToLower(m.ContractAddress))
|
||||
m.DepositAddress = strings.TrimSpace(strings.ToLower(m.DepositAddress))
|
||||
m.KeyReference = strings.TrimSpace(m.KeyReference)
|
||||
}
|
||||
|
||||
// Normalize trims wallet balance identifiers.
|
||||
func (b *WalletBalance) Normalize() {
|
||||
b.WalletRef = strings.TrimSpace(b.WalletRef)
|
||||
}
|
||||
Reference in New Issue
Block a user