From cf9866239af7e9da373c26eb536d48c183c5cc15 Mon Sep 17 00:00:00 2001 From: Jeremy <168515712+jeremy-babylonlabs@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:51:43 +1100 Subject: [PATCH] add params (#94) --- .../db/client}/db_client.go | 0 internal/indexer/db/client/interface.go | 14 +++ internal/indexer/db/client/params.go | 87 +++++++++++++++++++ internal/indexer/db/model/delegation.go | 19 ++++ .../indexer/db/model/finality_providers.go | 18 ++++ internal/indexer/db/model/global_params.go | 11 +++ internal/indexer/db/model/setup.go | 8 ++ internal/indexer/db/model/timelock.go | 7 ++ internal/indexer/types/delegation_state.go | 14 +++ internal/indexer/types/global_params.go | 32 +++++++ internal/shared/db/clients/db_clients.go | 2 +- .../shared/db/indexer_db_client/interface.go | 9 -- internal/shared/types/global_params.go | 23 ----- internal/shared/utils/datagen/datagen.go | 43 ++++----- internal/v2/service/global_params.go | 25 ------ internal/v2/service/interface.go | 2 +- internal/v2/service/params.go | 53 +++++++++++ tests/testutils/database.go | 2 +- tests/testutils/datagen.go | 43 ++++----- 19 files changed, 310 insertions(+), 102 deletions(-) rename internal/{shared/db/indexer_db_client => indexer/db/client}/db_client.go (100%) create mode 100644 internal/indexer/db/client/interface.go create mode 100644 internal/indexer/db/client/params.go create mode 100644 internal/indexer/db/model/delegation.go create mode 100644 internal/indexer/db/model/finality_providers.go create mode 100644 internal/indexer/db/model/global_params.go create mode 100644 internal/indexer/db/model/setup.go create mode 100644 internal/indexer/db/model/timelock.go create mode 100644 internal/indexer/types/delegation_state.go create mode 100644 internal/indexer/types/global_params.go delete mode 100644 internal/shared/db/indexer_db_client/interface.go delete mode 100644 internal/v2/service/global_params.go create mode 100644 internal/v2/service/params.go diff --git a/internal/shared/db/indexer_db_client/db_client.go b/internal/indexer/db/client/db_client.go similarity index 100% rename from internal/shared/db/indexer_db_client/db_client.go rename to internal/indexer/db/client/db_client.go diff --git a/internal/indexer/db/client/interface.go b/internal/indexer/db/client/interface.go new file mode 100644 index 00000000..3890e90d --- /dev/null +++ b/internal/indexer/db/client/interface.go @@ -0,0 +1,14 @@ +package indexerdbclient + +import ( + "context" + + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" +) + +type IndexerDBClient interface { + Ping(ctx context.Context) error + // Params + GetBbnStakingParams(ctx context.Context) ([]*indexertypes.BbnStakingParams, error) + GetBtcCheckpointParams(ctx context.Context) ([]*indexertypes.BtcCheckpointParams, error) +} diff --git a/internal/indexer/db/client/params.go b/internal/indexer/db/client/params.go new file mode 100644 index 00000000..e4ff2542 --- /dev/null +++ b/internal/indexer/db/client/params.go @@ -0,0 +1,87 @@ +package indexerdbclient + +import ( + "context" + "fmt" + + indexerdbmodel "github.com/babylonlabs-io/staking-api-service/internal/indexer/db/model" + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" + "go.mongodb.org/mongo-driver/bson" +) + +func (db *IndexerDatabase) GetBbnStakingParams(ctx context.Context) ([]*indexertypes.BbnStakingParams, error) { + cursor, err := db.Client.Database(db.DbName).Collection(indexerdbmodel.GlobalParamsCollection).Find(ctx, bson.M{ + "type": indexertypes.STAKING_PARAMS_TYPE, + }) + if err != nil { + return nil, fmt.Errorf("failed to query global params: %w", err) + } + defer cursor.Close(ctx) + + var params []*indexertypes.BbnStakingParams + + for cursor.Next(ctx) { + var model indexerdbmodel.IndexerGlobalParamsDocument + if err := cursor.Decode(&model); err != nil { + return nil, fmt.Errorf("failed to decode document: %w", err) + } + + var stakingParams indexertypes.BbnStakingParams + bsonBytes, err := bson.Marshal(model.Params) + if err != nil { + return nil, fmt.Errorf("failed to marshal params: %w", err) + } + if err := bson.Unmarshal(bsonBytes, &stakingParams); err != nil { + return nil, fmt.Errorf("failed to unmarshal into staking params: %w", err) + } + + stakingParams.Version = model.Version + + params = append(params, &stakingParams) + } + + if err := cursor.Err(); err != nil { + return nil, fmt.Errorf("cursor iteration error: %w", err) + } + + return params, nil +} + +func (db *IndexerDatabase) GetBtcCheckpointParams(ctx context.Context) ([]*indexertypes.BtcCheckpointParams, error) { + cursor, err := db.Client.Database(db.DbName).Collection(indexerdbmodel.GlobalParamsCollection).Find(ctx, bson.M{ + "type": indexertypes.CHECKPOINT_PARAMS_TYPE, + }) + if err != nil { + return nil, fmt.Errorf("failed to query global params: %w", err) + } + defer cursor.Close(ctx) + + var params []*indexertypes.BtcCheckpointParams + + for cursor.Next(ctx) { + var model indexerdbmodel.IndexerGlobalParamsDocument + if err := cursor.Decode(&model); err != nil { + return nil, fmt.Errorf("failed to decode document: %w", err) + } + + var btcParams indexertypes.BtcCheckpointParams + + bsonBytes, err := bson.Marshal(model.Params) + if err != nil { + return nil, fmt.Errorf("failed to marshal params: %w", err) + } + if err := bson.Unmarshal(bsonBytes, &btcParams); err != nil { + return nil, fmt.Errorf("failed to unmarshal into staking params: %w", err) + } + + btcParams.Version = model.Version + + params = append(params, &btcParams) + } + + if err := cursor.Err(); err != nil { + return nil, fmt.Errorf("cursor iteration error: %w", err) + } + + return params, nil +} diff --git a/internal/indexer/db/model/delegation.go b/internal/indexer/db/model/delegation.go new file mode 100644 index 00000000..22d7f79d --- /dev/null +++ b/internal/indexer/db/model/delegation.go @@ -0,0 +1,19 @@ +package indexerdbmodel + +import ( + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" +) + +type BTCDelegationDetails struct { + StakingTxHashHex string `bson:"_id"` // Primary key + ParamsVersion string `bson:"params_version"` + FinalityProviderBtcPksHex []string `bson:"finality_provider_btc_pks_hex"` + StakerBtcPkHex string `bson:"staker_btc_pk_hex"` + StakingTime string `bson:"staking_time"` + StakingAmount string `bson:"staking_amount"` + UnbondingTime string `bson:"unbonding_time"` + UnbondingTx string `bson:"unbonding_tx"` + State indexertypes.DelegationState `bson:"state"` + StartHeight uint32 `bson:"start_height"` + EndHeight uint32 `bson:"end_height"` +} diff --git a/internal/indexer/db/model/finality_providers.go b/internal/indexer/db/model/finality_providers.go new file mode 100644 index 00000000..fb01f83e --- /dev/null +++ b/internal/indexer/db/model/finality_providers.go @@ -0,0 +1,18 @@ +package indexerdbmodel + +type IndexerFinalityProviderDetails struct { + BtcPk string `bson:"_id"` // Primary key + BabylonAddress string `bson:"babylon_address"` + Commission string `bson:"commission"` + State string `bson:"state"` + Description Description `bson:"description"` +} + +// Description represents the nested description field +type Description struct { + Moniker string `bson:"moniker"` + Identity string `bson:"identity"` + Website string `bson:"website"` + SecurityContact string `bson:"security_contact"` + Details string `bson:"details"` +} diff --git a/internal/indexer/db/model/global_params.go b/internal/indexer/db/model/global_params.go new file mode 100644 index 00000000..8702e63f --- /dev/null +++ b/internal/indexer/db/model/global_params.go @@ -0,0 +1,11 @@ +package indexerdbmodel + +import ( + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" +) + +type IndexerGlobalParamsDocument struct { + Type indexertypes.GlobalParamsType `bson:"type"` + Version uint32 `bson:"version"` + Params interface{} `bson:"params"` +} diff --git a/internal/indexer/db/model/setup.go b/internal/indexer/db/model/setup.go new file mode 100644 index 00000000..bf788273 --- /dev/null +++ b/internal/indexer/db/model/setup.go @@ -0,0 +1,8 @@ +package indexerdbmodel + +const ( + FinalityProviderDetailsCollection = "finality_provider_details" + BTCDelegationDetailsCollection = "btc_delegation_details" + TimeLockCollection = "timelock" + GlobalParamsCollection = "global_params" +) diff --git a/internal/indexer/db/model/timelock.go b/internal/indexer/db/model/timelock.go new file mode 100644 index 00000000..9fa2474d --- /dev/null +++ b/internal/indexer/db/model/timelock.go @@ -0,0 +1,7 @@ +package indexerdbmodel + +type TimeLockDocument struct { + StakingTxHashHex string `bson:"_id"` // Primary key + ExpireHeight uint32 `bson:"expire_height"` + TxType string `bson:"tx_type"` +} diff --git a/internal/indexer/types/delegation_state.go b/internal/indexer/types/delegation_state.go new file mode 100644 index 00000000..c6095ae2 --- /dev/null +++ b/internal/indexer/types/delegation_state.go @@ -0,0 +1,14 @@ +package indexertypes + +// Enum values for Delegation State +type DelegationState string + +const ( + StatePending DelegationState = "PENDING" + StateVerified DelegationState = "VERIFIED" + StateActive DelegationState = "ACTIVE" + StateUnbonding DelegationState = "UNBONDING" + StateWithdrawable DelegationState = "WITHDRAWABLE" + StateWithdrawn DelegationState = "WITHDRAWN" + StateSlashed DelegationState = "SLASHED" +) diff --git a/internal/indexer/types/global_params.go b/internal/indexer/types/global_params.go new file mode 100644 index 00000000..0041f1f2 --- /dev/null +++ b/internal/indexer/types/global_params.go @@ -0,0 +1,32 @@ +package indexertypes + +type GlobalParamsType string + +const ( + CHECKPOINT_PARAMS_VERSION uint32 = 0 + CHECKPOINT_PARAMS_TYPE GlobalParamsType = "CHECKPOINT" + STAKING_PARAMS_TYPE GlobalParamsType = "STAKING" +) + +type BbnStakingParams struct { + Version uint32 `json:"version"` + CovenantPks []string `json:"covenant_pks"` + CovenantQuorum uint32 `json:"covenant_quorum"` + MinStakingValueSat int64 `json:"min_staking_value_sat"` + MaxStakingValueSat int64 `json:"max_staking_value_sat"` + MinStakingTimeBlocks uint32 `json:"min_staking_time_blocks"` + MaxStakingTimeBlocks uint32 `json:"max_staking_time_blocks"` + SlashingPkScript string `json:"slashing_pk_script"` + MinSlashingTxFeeSat int64 `json:"min_slashing_tx_fee_sat"` + SlashingRate string `json:"slashing_rate"` + MinUnbondingTimeBlocks uint32 `json:"min_unbonding_time_blocks"` + UnbondingFeeSat int64 `json:"unbonding_fee_sat"` + MinCommissionRate string `json:"min_commission_rate"` + MaxActiveFinalityProviders uint32 `json:"max_active_finality_providers"` + DelegationCreationBaseGasFee uint64 `json:"delegation_creation_base_gas_fee"` +} + +type BtcCheckpointParams struct { + Version uint32 `json:"version"` + BtcConfirmationDepth uint64 `json:"btc_confirmation_depth"` +} diff --git a/internal/shared/db/clients/db_clients.go b/internal/shared/db/clients/db_clients.go index 0c0afc3e..e5e3d086 100644 --- a/internal/shared/db/clients/db_clients.go +++ b/internal/shared/db/clients/db_clients.go @@ -3,9 +3,9 @@ package dbclients import ( "context" + indexerdbclient "github.com/babylonlabs-io/staking-api-service/internal/indexer/db/client" "github.com/babylonlabs-io/staking-api-service/internal/shared/config" dbclient "github.com/babylonlabs-io/staking-api-service/internal/shared/db/client" - indexerdbclient "github.com/babylonlabs-io/staking-api-service/internal/shared/db/indexer_db_client" v1dbclient "github.com/babylonlabs-io/staking-api-service/internal/v1/db/client" v2dbclient "github.com/babylonlabs-io/staking-api-service/internal/v2/db/client" "github.com/rs/zerolog/log" diff --git a/internal/shared/db/indexer_db_client/interface.go b/internal/shared/db/indexer_db_client/interface.go deleted file mode 100644 index fb7554fc..00000000 --- a/internal/shared/db/indexer_db_client/interface.go +++ /dev/null @@ -1,9 +0,0 @@ -package indexerdbclient - -import ( - dbclient "github.com/babylonlabs-io/staking-api-service/internal/shared/db/client" -) - -type IndexerDBClient interface { - dbclient.DBClient -} diff --git a/internal/shared/types/global_params.go b/internal/shared/types/global_params.go index 0a241009..0e5bffa6 100644 --- a/internal/shared/types/global_params.go +++ b/internal/shared/types/global_params.go @@ -14,29 +14,6 @@ type VersionedGlobalParams = parser.VersionedGlobalParams type GlobalParams = parser.GlobalParams -type BabylonParams struct { - Version int `json:"version"` - CovenantPKs []string `json:"covenant_pks"` - CovenantQuorum int `json:"covenant_quorum"` - MaxStakingAmount int64 `json:"max_staking_amount"` - MinStakingAmount int64 `json:"min_staking_amount"` - MaxStakingTime int64 `json:"max_staking_time"` - MinStakingTime int64 `json:"min_staking_time"` - SlashingPKScript string `json:"slashing_pk_script"` - MinSlashingTxFee int64 `json:"min_slashing_tx_fee"` - SlashingRate float64 `json:"slashing_rate"` - MinUnbondingTime int64 `json:"min_unbonding_time"` - UnbondingFee int64 `json:"unbonding_fee"` - MinCommissionRate float64 `json:"min_commission_rate"` - MaxActiveFinalityProviders int `json:"max_active_finality_providers"` - DelegationCreationBaseGasFee int64 `json:"delegation_creation_base_gas_fee"` -} - -type BTCParams struct { - Version int `json:"version"` - BTCConfirmationDepth int `json:"btc_confirmation_depth"` -} - func NewGlobalParams(path string) (*GlobalParams, error) { data, err := os.ReadFile(filepath.Clean(path)) if err != nil { diff --git a/internal/shared/utils/datagen/datagen.go b/internal/shared/utils/datagen/datagen.go index 5b04488b..e96fdb2e 100644 --- a/internal/shared/utils/datagen/datagen.go +++ b/internal/shared/utils/datagen/datagen.go @@ -8,6 +8,7 @@ import ( "math/rand" "time" + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" "github.com/babylonlabs-io/staking-api-service/internal/shared/types" "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2/schnorr" @@ -174,30 +175,30 @@ func RandomFinalityProviderState(r *rand.Rand) types.FinalityProviderState { return states[r.Intn(len(states))] } -func GenerateRandomBabylonParams(r *rand.Rand) types.BabylonParams { - return types.BabylonParams{ - Version: r.Intn(10), - CovenantPKs: GeneratePks(r.Intn(10)), - CovenantQuorum: r.Intn(10), - MaxStakingAmount: int64(r.Intn(1000000000000000000)), - MinStakingAmount: int64(r.Intn(1000000000000000000)), - MaxStakingTime: int64(r.Intn(1000000000000000000)), - MinStakingTime: int64(r.Intn(1000000000000000000)), - SlashingPKScript: RandomString(r, 10), - MinSlashingTxFee: int64(r.Intn(1000000000000000000)), - SlashingRate: RandomPostiveFloat64(r), - MinUnbondingTime: int64(r.Intn(1000000000000000000)), - UnbondingFee: int64(r.Intn(1000000000000000000)), - MinCommissionRate: RandomPostiveFloat64(r), - MaxActiveFinalityProviders: r.Intn(10), - DelegationCreationBaseGasFee: int64(r.Intn(1000000000000000000)), +func GenerateRandomBabylonParams(r *rand.Rand) indexertypes.BbnStakingParams { + return indexertypes.BbnStakingParams{ + Version: uint32(r.Intn(10)), + CovenantPks: GeneratePks(r.Intn(10)), + CovenantQuorum: uint32(r.Intn(10)), + MinStakingValueSat: int64(r.Intn(10)), + MaxStakingValueSat: int64(r.Intn(10)), + MinStakingTimeBlocks: uint32(r.Intn(10)), + MaxStakingTimeBlocks: uint32(r.Intn(10)), + SlashingPkScript: RandomString(r, 10), + MinSlashingTxFeeSat: int64(r.Intn(10)), + SlashingRate: fmt.Sprintf("%f", RandomPostiveFloat64(r)), + MinUnbondingTimeBlocks: uint32(r.Intn(10)), + UnbondingFeeSat: int64(r.Intn(10)), + MinCommissionRate: fmt.Sprintf("%f", RandomPostiveFloat64(r)), + MaxActiveFinalityProviders: uint32(r.Intn(10)), + DelegationCreationBaseGasFee: uint64(r.Intn(10)), } } -func GenerateRandomBTCParams(r *rand.Rand) types.BTCParams { - return types.BTCParams{ - Version: r.Intn(10), - BTCConfirmationDepth: r.Intn(10), +func GenerateRandomBTCParams(r *rand.Rand) indexertypes.BtcCheckpointParams { + return indexertypes.BtcCheckpointParams{ + Version: uint32(r.Intn(10)), + BtcConfirmationDepth: uint64(r.Intn(10)), } } diff --git a/internal/v2/service/global_params.go b/internal/v2/service/global_params.go deleted file mode 100644 index 96954f3a..00000000 --- a/internal/v2/service/global_params.go +++ /dev/null @@ -1,25 +0,0 @@ -package v2service - -import ( - "context" - "math/rand" - "time" - - "github.com/babylonlabs-io/staking-api-service/internal/shared/types" - "github.com/babylonlabs-io/staking-api-service/internal/shared/utils/datagen" -) - -type GlobalParamsPublic struct { - Babylon []types.BabylonParams `json:"babylon"` - BTC []types.BTCParams `json:"btc"` -} - -func (s *V2Service) GetGlobalParams(ctx context.Context) (GlobalParamsPublic, *types.Error) { - r := rand.New(rand.NewSource(time.Now().UnixNano())) - babylonParams := datagen.GenerateRandomBabylonParams(r) - btcParams := datagen.GenerateRandomBTCParams(r) - return GlobalParamsPublic{ - Babylon: []types.BabylonParams{babylonParams}, - BTC: []types.BTCParams{btcParams}, - }, nil -} diff --git a/internal/v2/service/interface.go b/internal/v2/service/interface.go index 432bc8af..2c5b9481 100644 --- a/internal/v2/service/interface.go +++ b/internal/v2/service/interface.go @@ -10,7 +10,7 @@ import ( type V2ServiceProvider interface { service.SharedServiceProvider GetFinalityProviders(ctx context.Context, paginationKey string) ([]FinalityProviderPublic, string, *types.Error) - GetGlobalParams(ctx context.Context) (GlobalParamsPublic, *types.Error) + GetGlobalParams(ctx context.Context) (*GlobalParamsPublic, *types.Error) GetOverallStats(ctx context.Context) (OverallStatsPublic, *types.Error) GetStakerDelegations(ctx context.Context, paginationKey string) ([]StakerDelegationPublic, string, *types.Error) GetStakerStats(ctx context.Context, stakerPKHex string) (StakerStatsPublic, *types.Error) diff --git a/internal/v2/service/params.go b/internal/v2/service/params.go new file mode 100644 index 00000000..1b50a77b --- /dev/null +++ b/internal/v2/service/params.go @@ -0,0 +1,53 @@ +package v2service + +import ( + "context" + "net/http" + + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" + "github.com/babylonlabs-io/staking-api-service/internal/shared/types" +) + +type GlobalParamsPublic struct { + Bbn []*indexertypes.BbnStakingParams `json:"bbn"` + Btc []*indexertypes.BtcCheckpointParams `json:"btc"` +} + +func (s *V2Service) GetGlobalParams(ctx context.Context) (*GlobalParamsPublic, *types.Error) { + babylonParams, err := s.getBbnStakingParams(ctx) + if err != nil { + return nil, err + } + + btcParams, err := s.getBtcCheckpointParams(ctx) + if err != nil { + return nil, err + } + return &GlobalParamsPublic{ + Bbn: babylonParams, + Btc: btcParams, + }, nil +} + +func (s *V2Service) getBbnStakingParams(ctx context.Context) ([]*indexertypes.BbnStakingParams, *types.Error) { + params, err := s.DbClients.IndexerDBClient.GetBbnStakingParams(ctx) + if err != nil { + return nil, types.NewErrorWithMsg( + http.StatusInternalServerError, types.InternalServiceError, + "failed to get babylon params", + ) + } + + return params, nil +} + +func (s *V2Service) getBtcCheckpointParams(ctx context.Context) ([]*indexertypes.BtcCheckpointParams, *types.Error) { + params, err := s.DbClients.IndexerDBClient.GetBtcCheckpointParams(ctx) + if err != nil { + return nil, types.NewErrorWithMsg( + http.StatusInternalServerError, types.InternalServiceError, + "failed to get btc params", + ) + } + return params, nil +} diff --git a/tests/testutils/database.go b/tests/testutils/database.go index 628e3e95..010572cf 100644 --- a/tests/testutils/database.go +++ b/tests/testutils/database.go @@ -4,10 +4,10 @@ import ( "context" "log" + indexerdbclient "github.com/babylonlabs-io/staking-api-service/internal/indexer/db/client" "github.com/babylonlabs-io/staking-api-service/internal/shared/config" dbclient "github.com/babylonlabs-io/staking-api-service/internal/shared/db/client" dbclients "github.com/babylonlabs-io/staking-api-service/internal/shared/db/clients" - indexerdbclient "github.com/babylonlabs-io/staking-api-service/internal/shared/db/indexer_db_client" dbmodel "github.com/babylonlabs-io/staking-api-service/internal/shared/db/model" v1dbclient "github.com/babylonlabs-io/staking-api-service/internal/v1/db/client" v2dbclient "github.com/babylonlabs-io/staking-api-service/internal/v2/db/client" diff --git a/tests/testutils/datagen.go b/tests/testutils/datagen.go index 376d2b71..b156b815 100644 --- a/tests/testutils/datagen.go +++ b/tests/testutils/datagen.go @@ -9,6 +9,7 @@ import ( "time" bbndatagen "github.com/babylonlabs-io/babylon/testutil/datagen" + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" "github.com/babylonlabs-io/staking-api-service/internal/shared/config" "github.com/babylonlabs-io/staking-api-service/internal/shared/types" "github.com/babylonlabs-io/staking-queue-client/client" @@ -249,30 +250,30 @@ func GenerateRandomActiveStakingEvents( return activeStakingEvents } -func GenerateRandomBabylonParams(r *rand.Rand) types.BabylonParams { - return types.BabylonParams{ - Version: r.Intn(10), - CovenantPKs: GeneratePks(r.Intn(10)), - CovenantQuorum: r.Intn(10), - MaxStakingAmount: int64(r.Intn(1000000000000000000)), - MinStakingAmount: int64(r.Intn(1000000000000000000)), - MaxStakingTime: int64(r.Intn(1000000000000000000)), - MinStakingTime: int64(r.Intn(1000000000000000000)), - SlashingPKScript: RandomString(r, 10), - MinSlashingTxFee: int64(r.Intn(1000000000000000000)), - SlashingRate: RandomPostiveFloat64(r), - MinUnbondingTime: int64(r.Intn(1000000000000000000)), - UnbondingFee: int64(r.Intn(1000000000000000000)), - MinCommissionRate: RandomPostiveFloat64(r), - MaxActiveFinalityProviders: r.Intn(10), - DelegationCreationBaseGasFee: int64(r.Intn(1000000000000000000)), +func GenerateRandomBabylonParams(r *rand.Rand) indexertypes.BbnStakingParams { + return indexertypes.BbnStakingParams{ + Version: uint32(r.Intn(10)), + CovenantPks: GeneratePks(r.Intn(10)), + CovenantQuorum: uint32(r.Intn(10)), + MinStakingValueSat: int64(r.Intn(1000000000000000000)), + MaxStakingValueSat: int64(r.Intn(1000000000000000000)), + MinStakingTimeBlocks: uint32(r.Intn(1000000000000000000)), + MaxStakingTimeBlocks: uint32(r.Intn(1000000000000000000)), + SlashingPkScript: RandomString(r, 10), + MinSlashingTxFeeSat: int64(r.Intn(1000000000000000000)), + SlashingRate: fmt.Sprintf("%f", RandomPostiveFloat64(r)), + MinUnbondingTimeBlocks: uint32(r.Intn(1000000000000000000)), + UnbondingFeeSat: int64(r.Intn(1000000000000000000)), + MinCommissionRate: fmt.Sprintf("%f", RandomPostiveFloat64(r)), + MaxActiveFinalityProviders: uint32(r.Intn(10)), + DelegationCreationBaseGasFee: uint64(r.Intn(1000000000000000000)), } } -func GenerateRandomBTCParams(r *rand.Rand) types.BTCParams { - return types.BTCParams{ - Version: r.Intn(10), - BTCConfirmationDepth: r.Intn(10), +func GenerateRandomBTCParams(r *rand.Rand) indexertypes.BtcCheckpointParams { + return indexertypes.BtcCheckpointParams{ + Version: uint32(r.Intn(10)), + BtcConfirmationDepth: uint64(r.Intn(10)), } }