Add admin APIs to manage wallet (#226)

* Add admin rpcs to manage wallet

* Fix

* Fixes

* Add sleeping time

* Increase sleeping time
This commit is contained in:
Pietralberto Mazza
2024-08-07 00:36:51 +02:00
committed by GitHub
parent fb8a127f4f
commit 1c67c56d9d
28 changed files with 3680 additions and 1721 deletions

View File

@@ -41,12 +41,10 @@ type RoundDetails struct {
}
type AdminService interface {
GetBalance(ctx context.Context) (*ArkProviderBalance, error)
Wallet() ports.WalletService
GetScheduledSweeps(ctx context.Context) ([]ScheduledSweep, error)
GetRoundDetails(ctx context.Context, roundId string) (*RoundDetails, error)
GetRounds(ctx context.Context, after int64, before int64) ([]string, error)
GetWalletAddress(ctx context.Context) (string, error)
GetWalletStatus(ctx context.Context) (*WalletStatus, error)
}
type adminService struct {
@@ -63,21 +61,8 @@ func NewAdminService(walletSvc ports.WalletService, repoManager ports.RepoManage
}
}
func (a *adminService) GetBalance(ctx context.Context) (*ArkProviderBalance, error) {
mainBalance, mainBalanceLocked, err := a.walletSvc.MainAccountBalance(ctx)
if err != nil {
return nil, err
}
connectorBalance, connectorBalanceLocked, err := a.walletSvc.ConnectorsAccountBalance(ctx)
if err != nil {
return nil, err
}
return &ArkProviderBalance{
MainAccountBalance: Balance{Locked: mainBalanceLocked, Available: mainBalance},
ConnectorsAccountBalance: Balance{Locked: connectorBalanceLocked, Available: connectorBalance},
}, nil
func (a *adminService) Wallet() ports.WalletService {
return a.walletSvc
}
func (a *adminService) GetRoundDetails(ctx context.Context, roundId string) (*RoundDetails, error) {
@@ -169,24 +154,3 @@ func (a *adminService) GetScheduledSweeps(ctx context.Context) ([]ScheduledSweep
return scheduledSweeps, nil
}
func (a *adminService) GetWalletAddress(ctx context.Context) (string, error) {
addresses, err := a.walletSvc.DeriveAddresses(ctx, 1)
if err != nil {
return "", err
}
return addresses[0], nil
}
func (a *adminService) GetWalletStatus(ctx context.Context) (*WalletStatus, error) {
status, err := a.walletSvc.Status(ctx)
if err != nil {
return nil, err
}
return &WalletStatus{
IsInitialized: status.IsInitialized(),
IsUnlocked: status.IsUnlocked(),
IsSynced: status.IsSynced(),
}, nil
}