mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 04:34:19 +01:00
Add support for announcing market hours (#380)
* feat: add market hour configuration for optimal payment timing This commit adds market hour configuration to help users determine optimal times for making payments with lower fees. The configuration is managed through environment variables and exposed via the GetInfo RPC. Changes: - Add MarketHour message type to protobuf service definition - Add market hour configuration fields to Config struct - Update covenant and covenantless services to handle market hour data - Extend GetInfo RPC response to include market hour information - Set default market hour period to 24 hours - Initialize market hour fields after other service fields Configuration: - ARK_FIRST_MARKET_HOUR: Initial market hour timestamp (default: current server start time) - ARK_MARKET_HOUR_PERIOD: Time between market hours in seconds (default: 86400) - ARK_MARKET_HOUR_ROUND_LIFETIME: Round lifetime for market hours (default: 0, falls back to ARK_ROUND_LIFETIME) * feat: add admin RPC for updating market hour configuration Add new UpdateMarketHour RPC to AdminService for configuring market hour parameters: - Add request/response messages to admin.proto - Add UpdateMarketHour method to Service interface - Implement market hour updates in covenant and covenantless services - Add validation for market hour parameters - Implement admin gRPC handler The RPC allows updating: - First market hour timestamp - Market hour period - Market hour round lifetime (optional, defaults to round lifetime * feat: add market hour persistence with sqlite - Add MarketHourRepo interface in domain layer - Implement market hour persistence using SQLite - Add market hour queries to sqlc/query.sql - Update service initialization to load market hours from DB - Add fallback to config values if no DB entry exists - Update RepoManager interface with new MarketHourRepo method
This commit is contained in:
@@ -63,12 +63,25 @@ func NewCovenantService(
|
||||
builder ports.TxBuilder, scanner ports.BlockchainScanner,
|
||||
scheduler ports.SchedulerService,
|
||||
notificationPrefix string,
|
||||
marketHourStartTime, marketHourEndTime time.Time, marketHourPeriod, marketHourRoundInterval time.Duration,
|
||||
) (Service, error) {
|
||||
pubkey, err := walletSvc.GetPubkey(context.Background())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch pubkey: %s", err)
|
||||
}
|
||||
|
||||
marketHour, err := repoManager.MarketHourRepo().Get(context.Background())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get market hours from db: %w", err)
|
||||
}
|
||||
|
||||
if marketHour == nil {
|
||||
marketHour = domain.NewMarketHour(marketHourStartTime, marketHourEndTime, marketHourPeriod, marketHourRoundInterval)
|
||||
if err := repoManager.MarketHourRepo().Upsert(context.Background(), *marketHour); err != nil {
|
||||
return nil, fmt.Errorf("failed to upsert initial market hours to db: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
svc := &covenantService{
|
||||
network: network,
|
||||
pubkey: pubkey,
|
||||
@@ -430,6 +443,22 @@ func (s *covenantService) GetInfo(ctx context.Context) (*ServiceInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
marketHourConfig, err := s.repoManager.MarketHourRepo().Get(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
marketHourNextStart, marketHourNextEnd, err := calcNextMarketHour(
|
||||
marketHourConfig.StartTime,
|
||||
marketHourConfig.EndTime,
|
||||
marketHourConfig.Period,
|
||||
marketHourDelta,
|
||||
time.Now(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ServiceInfo{
|
||||
PubKey: pubkey,
|
||||
RoundLifetime: s.roundLifetime,
|
||||
@@ -438,6 +467,12 @@ func (s *covenantService) GetInfo(ctx context.Context) (*ServiceInfo, error) {
|
||||
Network: s.network.Name,
|
||||
Dust: dust,
|
||||
ForfeitAddress: forfeitAddress,
|
||||
NextMarketHour: &NextMarketHour{
|
||||
StartTime: marketHourNextStart,
|
||||
EndTime: marketHourNextEnd,
|
||||
Period: marketHourConfig.Period,
|
||||
RoundInterval: marketHourConfig.RoundInterval,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1153,3 +1188,24 @@ func findForfeitTxLiquid(
|
||||
|
||||
return "", fmt.Errorf("forfeit tx not found")
|
||||
}
|
||||
|
||||
func (s *covenantService) GetMarketHourConfig(ctx context.Context) (*domain.MarketHour, error) {
|
||||
return s.repoManager.MarketHourRepo().Get(ctx)
|
||||
}
|
||||
|
||||
func (s *covenantService) UpdateMarketHourConfig(
|
||||
ctx context.Context,
|
||||
marketHourStartTime, marketHourEndTime time.Time, period, roundInterval time.Duration,
|
||||
) error {
|
||||
marketHour := domain.NewMarketHour(
|
||||
marketHourStartTime,
|
||||
marketHourEndTime,
|
||||
period,
|
||||
roundInterval,
|
||||
)
|
||||
if err := s.repoManager.MarketHourRepo().Upsert(ctx, *marketHour); err != nil {
|
||||
return fmt.Errorf("failed to upsert market hours: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user