From 393122d71e8990b819d095e8bfaae42718f30029 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Sun, 24 Nov 2024 18:34:22 +0530 Subject: [PATCH 1/7] fix icneption time --- internal/indexer/db/model/delegation.go | 36 ++++++++++++++----------- internal/v2/service/delegation.go | 28 ++++++++++--------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/internal/indexer/db/model/delegation.go b/internal/indexer/db/model/delegation.go index e07ae0a..de0c5e5 100644 --- a/internal/indexer/db/model/delegation.go +++ b/internal/indexer/db/model/delegation.go @@ -16,22 +16,28 @@ type CovenantSignature struct { SignatureHex string `bson:"signature_hex"` } +type BTCDelegationCreatedBbnBlock struct { + Height int64 `bson:"height"` + Timestamp int64 `bson:"timestamp"` // epoch time in seconds +} + type IndexerDelegationDetails struct { - StakingTxHashHex string `bson:"_id"` // Primary key - StakingTxHex string `bson:"staking_tx_hex"` - ParamsVersion uint32 `bson:"params_version"` - FinalityProviderBtcPksHex []string `bson:"finality_provider_btc_pks_hex"` - StakerBtcPkHex string `bson:"staker_btc_pk_hex"` - StakingTime uint32 `bson:"staking_time"` - StakingAmount uint64 `bson:"staking_amount"` - StakingOutputPkScript string `bson:"staking_output_pk_script"` - StakingOutputIdx uint32 `bson:"staking_output_idx"` - UnbondingTime uint32 `bson:"unbonding_time"` - UnbondingTx string `bson:"unbonding_tx"` - State indexertypes.DelegationState `bson:"state"` - StartHeight uint32 `bson:"start_height"` - EndHeight uint32 `bson:"end_height"` - CovenantUnbondingSignatures []CovenantSignature `bson:"covenant_unbonding_signatures"` + StakingTxHashHex string `bson:"_id"` // Primary key + StakingTxHex string `bson:"staking_tx_hex"` + ParamsVersion uint32 `bson:"params_version"` + FinalityProviderBtcPksHex []string `bson:"finality_provider_btc_pks_hex"` + StakerBtcPkHex string `bson:"staker_btc_pk_hex"` + StakingTime uint32 `bson:"staking_time"` + StakingAmount uint64 `bson:"staking_amount"` + StakingOutputPkScript string `bson:"staking_output_pk_script"` + StakingOutputIdx uint32 `bson:"staking_output_idx"` + UnbondingTime uint32 `bson:"unbonding_time"` + UnbondingTx string `bson:"unbonding_tx"` + State indexertypes.DelegationState `bson:"state"` + StartHeight uint32 `bson:"start_height"` + EndHeight uint32 `bson:"end_height"` + CovenantUnbondingSignatures []CovenantSignature `bson:"covenant_unbonding_signatures"` + BTCDelegationCreatedBbnBlock BTCDelegationCreatedBbnBlock `bson:"btc_delegation_created_bbn_block"` } func BuildDelegationPaginationToken(d IndexerDelegationDetails) (string, error) { diff --git a/internal/v2/service/delegation.go b/internal/v2/service/delegation.go index b4227ad..79428fc 100644 --- a/internal/v2/service/delegation.go +++ b/internal/v2/service/delegation.go @@ -12,12 +12,14 @@ import ( ) type DelegationStaking struct { - StakingTxHashHex string `json:"staking_tx_hash_hex"` - StakingTxHex string `json:"staking_tx_hex"` - StakingTime uint32 `json:"staking_time"` - StakingAmount uint64 `json:"staking_amount"` - StartHeight uint32 `json:"start_height,omitempty"` - EndHeight uint32 `json:"end_height,omitempty"` + StakingTxHashHex string `json:"staking_tx_hash_hex"` + StakingTxHex string `json:"staking_tx_hex"` + StakingTime uint32 `json:"staking_time"` + StakingAmount uint64 `json:"staking_amount"` + StartHeight uint32 `json:"start_height,omitempty"` + EndHeight uint32 `json:"end_height,omitempty"` + BbnInceptionHeight int64 `json:"bbn_inception_height"` + BbnInceptionTime int64 `json:"bbn_inception_time"` } type CovenantSignature struct { @@ -55,12 +57,14 @@ func (s *V2Service) GetDelegation(ctx context.Context, stakingTxHashHex string) FinalityProviderBtcPksHex: delegation.FinalityProviderBtcPksHex, StakerBtcPkHex: delegation.StakerBtcPkHex, DelegationStaking: DelegationStaking{ - StakingTxHashHex: delegation.StakingTxHashHex, - StakingTxHex: delegation.StakingTxHex, - StakingTime: delegation.StakingTime, - StakingAmount: delegation.StakingAmount, - StartHeight: delegation.StartHeight, - EndHeight: delegation.EndHeight, + StakingTxHashHex: delegation.StakingTxHashHex, + StakingTxHex: delegation.StakingTxHex, + StakingTime: delegation.StakingTime, + StakingAmount: delegation.StakingAmount, + StartHeight: delegation.StartHeight, + EndHeight: delegation.EndHeight, + BbnInceptionHeight: delegation.BTCDelegationCreatedBbnBlock.Height, + BbnInceptionTime: delegation.BTCDelegationCreatedBbnBlock.Timestamp, }, DelegationUnbonding: DelegationUnbonding{ UnbondingTime: delegation.UnbondingTime, From 461875e5f2ea1e35ea787b2fd5dabcdc91f7c026 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Sun, 24 Nov 2024 18:51:01 +0530 Subject: [PATCH 2/7] add substates --- internal/indexer/db/model/delegation.go | 33 +++++++++++----------- internal/indexer/types/delegation_state.go | 9 ++++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/internal/indexer/db/model/delegation.go b/internal/indexer/db/model/delegation.go index de0c5e5..a29e720 100644 --- a/internal/indexer/db/model/delegation.go +++ b/internal/indexer/db/model/delegation.go @@ -22,22 +22,23 @@ type BTCDelegationCreatedBbnBlock struct { } type IndexerDelegationDetails struct { - StakingTxHashHex string `bson:"_id"` // Primary key - StakingTxHex string `bson:"staking_tx_hex"` - ParamsVersion uint32 `bson:"params_version"` - FinalityProviderBtcPksHex []string `bson:"finality_provider_btc_pks_hex"` - StakerBtcPkHex string `bson:"staker_btc_pk_hex"` - StakingTime uint32 `bson:"staking_time"` - StakingAmount uint64 `bson:"staking_amount"` - StakingOutputPkScript string `bson:"staking_output_pk_script"` - StakingOutputIdx uint32 `bson:"staking_output_idx"` - UnbondingTime uint32 `bson:"unbonding_time"` - UnbondingTx string `bson:"unbonding_tx"` - State indexertypes.DelegationState `bson:"state"` - StartHeight uint32 `bson:"start_height"` - EndHeight uint32 `bson:"end_height"` - CovenantUnbondingSignatures []CovenantSignature `bson:"covenant_unbonding_signatures"` - BTCDelegationCreatedBbnBlock BTCDelegationCreatedBbnBlock `bson:"btc_delegation_created_bbn_block"` + StakingTxHashHex string `bson:"_id"` // Primary key + StakingTxHex string `bson:"staking_tx_hex"` + ParamsVersion uint32 `bson:"params_version"` + FinalityProviderBtcPksHex []string `bson:"finality_provider_btc_pks_hex"` + StakerBtcPkHex string `bson:"staker_btc_pk_hex"` + StakingTime uint32 `bson:"staking_time"` + StakingAmount uint64 `bson:"staking_amount"` + StakingOutputPkScript string `bson:"staking_output_pk_script"` + StakingOutputIdx uint32 `bson:"staking_output_idx"` + UnbondingTime uint32 `bson:"unbonding_time"` + UnbondingTx string `bson:"unbonding_tx"` + State indexertypes.DelegationState `bson:"state"` + SubState indexertypes.DelegationSubState `bson:"sub_state,omitempty"` + StartHeight uint32 `bson:"start_height"` + EndHeight uint32 `bson:"end_height"` + CovenantUnbondingSignatures []CovenantSignature `bson:"covenant_unbonding_signatures"` + BTCDelegationCreatedBbnBlock BTCDelegationCreatedBbnBlock `bson:"btc_delegation_created_bbn_block"` } func BuildDelegationPaginationToken(d IndexerDelegationDetails) (string, error) { diff --git a/internal/indexer/types/delegation_state.go b/internal/indexer/types/delegation_state.go index c6095ae..3060759 100644 --- a/internal/indexer/types/delegation_state.go +++ b/internal/indexer/types/delegation_state.go @@ -12,3 +12,12 @@ const ( StateWithdrawn DelegationState = "WITHDRAWN" StateSlashed DelegationState = "SLASHED" ) + +type DelegationSubState string + +const ( + SubStateTimelock DelegationSubState = "TIMELOCK" + SubStateEarlyUnbonding DelegationSubState = "EARLY_UNBONDING" + SubStateTimelockSlashing DelegationSubState = "TIMELOCK_SLASHING" + SubStateEarlyUnbondingSlashing DelegationSubState = "EARLY_UNBONDING_SLASHING" +) From c34f0d2a7d90d0b7fe9bca04972cc09eac3c6ad5 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Sun, 24 Nov 2024 19:28:10 +0530 Subject: [PATCH 3/7] api states --- internal/v2/service/delegation.go | 28 +++++--- internal/v2/types/delegation_states.go | 91 ++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 internal/v2/types/delegation_states.go diff --git a/internal/v2/service/delegation.go b/internal/v2/service/delegation.go index 79428fc..fb35c39 100644 --- a/internal/v2/service/delegation.go +++ b/internal/v2/service/delegation.go @@ -5,9 +5,9 @@ import ( "net/http" indexerdbmodel "github.com/babylonlabs-io/staking-api-service/internal/indexer/db/model" - indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" "github.com/babylonlabs-io/staking-api-service/internal/shared/db" "github.com/babylonlabs-io/staking-api-service/internal/shared/types" + v2types "github.com/babylonlabs-io/staking-api-service/internal/v2/types" "github.com/rs/zerolog/log" ) @@ -34,12 +34,12 @@ type DelegationUnbonding struct { } type StakerDelegationPublic struct { - ParamsVersion uint32 `json:"params_version"` - StakerBtcPkHex string `json:"staker_btc_pk_hex"` - FinalityProviderBtcPksHex []string `json:"finality_provider_btc_pks_hex"` - DelegationStaking DelegationStaking `json:"delegation_staking"` - DelegationUnbonding DelegationUnbonding `json:"delegation_unbonding"` - State indexertypes.DelegationState `json:"state"` + ParamsVersion uint32 `json:"params_version"` + StakerBtcPkHex string `json:"staker_btc_pk_hex"` + FinalityProviderBtcPksHex []string `json:"finality_provider_btc_pks_hex"` + DelegationStaking DelegationStaking `json:"delegation_staking"` + DelegationUnbonding DelegationUnbonding `json:"delegation_unbonding"` + State v2types.DelegationAPIState `json:"state"` } func (s *V2Service) GetDelegation(ctx context.Context, stakingTxHashHex string) (*StakerDelegationPublic, *types.Error) { @@ -52,6 +52,11 @@ func (s *V2Service) GetDelegation(ctx context.Context, stakingTxHashHex string) return nil, types.NewErrorWithMsg(http.StatusInternalServerError, types.InternalServiceError, "failed to get staker delegation") } + state, err := v2types.DeriveDelegationAPIState(delegation.State, delegation.SubState) + if err != nil { + return nil, types.NewErrorWithMsg(http.StatusInternalServerError, types.InternalServiceError, "failed to get delegation state") + } + delegationPublic := &StakerDelegationPublic{ ParamsVersion: delegation.ParamsVersion, FinalityProviderBtcPksHex: delegation.FinalityProviderBtcPksHex, @@ -73,7 +78,7 @@ func (s *V2Service) GetDelegation(ctx context.Context, stakingTxHashHex string) delegation.CovenantUnbondingSignatures, ), }, - State: delegation.State, + State: state, } return delegationPublic, nil } @@ -93,6 +98,11 @@ func (s *V2Service) GetDelegations(ctx context.Context, stakerPkHex string, pagi // Group delegations by state for _, delegation := range resultMap.Data { + state, err := v2types.DeriveDelegationAPIState(delegation.State, delegation.SubState) + if err != nil { + return nil, "", types.NewErrorWithMsg(http.StatusInternalServerError, types.InternalServiceError, "failed to get delegation state") + } + delegationPublic := &StakerDelegationPublic{ ParamsVersion: delegation.ParamsVersion, FinalityProviderBtcPksHex: delegation.FinalityProviderBtcPksHex, @@ -112,7 +122,7 @@ func (s *V2Service) GetDelegations(ctx context.Context, stakerPkHex string, pagi delegation.CovenantUnbondingSignatures, ), }, - State: delegation.State, + State: state, } delegationsPublic = append(delegationsPublic, delegationPublic) } diff --git a/internal/v2/types/delegation_states.go b/internal/v2/types/delegation_states.go new file mode 100644 index 0000000..1ba8e9e --- /dev/null +++ b/internal/v2/types/delegation_states.go @@ -0,0 +1,91 @@ +package v2types + +import ( + "fmt" + + indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" +) + +// DelegationAPIState represents the flattened state for frontend consumption +type DelegationAPIState string + +const ( + // Basic states + StatePending DelegationAPIState = "PENDING" + StateVerified DelegationAPIState = "VERIFIED" + StateActive DelegationAPIState = "ACTIVE" + + // Unbonding states + StateTimelockUnbonding DelegationAPIState = "TIMELOCK_UNBONDING" + StateEarlyUnbonding DelegationAPIState = "EARLY_UNBONDING" + + // Withdrawable states + StateTimelockWithdrawable DelegationAPIState = "TIMELOCK_WITHDRAWABLE" + StateEarlyUnbondingWithdrawable DelegationAPIState = "EARLY_UNBONDING_WITHDRAWABLE" + StateTimelockSlashingWithdrawable DelegationAPIState = "TIMELOCK_SLASHING_WITHDRAWABLE" + StateEarlyUnbondingSlashingWithdrawable DelegationAPIState = "EARLY_UNBONDING_SLASHING_WITHDRAWABLE" + + // Withdrawn states + StateTimelockWithdrawn DelegationAPIState = "TIMELOCK_WITHDRAWN" + StateEarlyUnbondingWithdrawn DelegationAPIState = "EARLY_UNBONDING_WITHDRAWN" + StateTimelockSlashingWithdrawn DelegationAPIState = "TIMELOCK_SLASHING_WITHDRAWN" + StateEarlyUnbondingSlashingWithdrawn DelegationAPIState = "EARLY_UNBONDING_SLASHING_WITHDRAWN" + + // Slashed states + StateTimelockSlashed DelegationAPIState = "TIMELOCK_SLASHED" + StateEarlyUnbondingSlashed DelegationAPIState = "EARLY_UNBONDING_SLASHED" +) + +// DeriveAPIState converts internal states to API states, returns error if combination is invalid +func DeriveDelegationAPIState(state indexertypes.DelegationState, subState indexertypes.DelegationSubState) (DelegationAPIState, error) { + switch state { + case indexertypes.StatePending: + return StatePending, nil + case indexertypes.StateVerified: + return StateVerified, nil + case indexertypes.StateActive: + return StateActive, nil + + case indexertypes.StateUnbonding: + switch subState { + case indexertypes.SubStateTimelock: + return StateTimelockUnbonding, nil + case indexertypes.SubStateEarlyUnbonding: + return StateEarlyUnbonding, nil + } + + case indexertypes.StateWithdrawable: + switch subState { + case indexertypes.SubStateTimelock: + return StateTimelockWithdrawable, nil + case indexertypes.SubStateEarlyUnbonding: + return StateEarlyUnbondingWithdrawable, nil + case indexertypes.SubStateTimelockSlashing: + return StateTimelockSlashingWithdrawable, nil + case indexertypes.SubStateEarlyUnbondingSlashing: + return StateEarlyUnbondingSlashingWithdrawable, nil + } + + case indexertypes.StateWithdrawn: + switch subState { + case indexertypes.SubStateTimelock: + return StateTimelockWithdrawn, nil + case indexertypes.SubStateEarlyUnbonding: + return StateEarlyUnbondingWithdrawn, nil + case indexertypes.SubStateTimelockSlashing: + return StateTimelockSlashingWithdrawn, nil + case indexertypes.SubStateEarlyUnbondingSlashing: + return StateEarlyUnbondingSlashingWithdrawn, nil + } + + case indexertypes.StateSlashed: + switch subState { + case indexertypes.SubStateTimelockSlashing: + return StateTimelockSlashed, nil + case indexertypes.SubStateEarlyUnbondingSlashing: + return StateEarlyUnbondingSlashed, nil + } + } + + return "", fmt.Errorf("invalid state/subState combination: state=%s, subState=%s", state, subState) +} From 29555f3a0032eb3a0de4518837c3382aa0c9e44f Mon Sep 17 00:00:00 2001 From: Gurjot Date: Sun, 24 Nov 2024 21:58:25 +0530 Subject: [PATCH 4/7] fix --- internal/v2/service/delegation.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/v2/service/delegation.go b/internal/v2/service/delegation.go index fb35c39..bab833d 100644 --- a/internal/v2/service/delegation.go +++ b/internal/v2/service/delegation.go @@ -108,12 +108,14 @@ func (s *V2Service) GetDelegations(ctx context.Context, stakerPkHex string, pagi FinalityProviderBtcPksHex: delegation.FinalityProviderBtcPksHex, StakerBtcPkHex: delegation.StakerBtcPkHex, DelegationStaking: DelegationStaking{ - StakingTxHashHex: delegation.StakingTxHashHex, - StakingTxHex: delegation.StakingTxHex, - StakingTime: delegation.StakingTime, - StakingAmount: delegation.StakingAmount, - StartHeight: delegation.StartHeight, - EndHeight: delegation.EndHeight, + StakingTxHashHex: delegation.StakingTxHashHex, + StakingTxHex: delegation.StakingTxHex, + StakingTime: delegation.StakingTime, + StakingAmount: delegation.StakingAmount, + StartHeight: delegation.StartHeight, + EndHeight: delegation.EndHeight, + BbnInceptionHeight: delegation.BTCDelegationCreatedBbnBlock.Height, + BbnInceptionTime: delegation.BTCDelegationCreatedBbnBlock.Timestamp, }, DelegationUnbonding: DelegationUnbonding{ UnbondingTime: delegation.UnbondingTime, From ab40faf279c9e3bce2994417e9a7305435d96644 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Sun, 24 Nov 2024 22:10:12 +0530 Subject: [PATCH 5/7] fix state --- internal/v2/service/delegation.go | 16 ++++++------ internal/v2/types/delegation_states.go | 36 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/internal/v2/service/delegation.go b/internal/v2/service/delegation.go index bab833d..db25e93 100644 --- a/internal/v2/service/delegation.go +++ b/internal/v2/service/delegation.go @@ -34,12 +34,12 @@ type DelegationUnbonding struct { } type StakerDelegationPublic struct { - ParamsVersion uint32 `json:"params_version"` - StakerBtcPkHex string `json:"staker_btc_pk_hex"` - FinalityProviderBtcPksHex []string `json:"finality_provider_btc_pks_hex"` - DelegationStaking DelegationStaking `json:"delegation_staking"` - DelegationUnbonding DelegationUnbonding `json:"delegation_unbonding"` - State v2types.DelegationAPIState `json:"state"` + ParamsVersion uint32 `json:"params_version"` + StakerBtcPkHex string `json:"staker_btc_pk_hex"` + FinalityProviderBtcPksHex []string `json:"finality_provider_btc_pks_hex"` + DelegationStaking DelegationStaking `json:"delegation_staking"` + DelegationUnbonding DelegationUnbonding `json:"delegation_unbonding"` + State v2types.DelegationState `json:"state"` } func (s *V2Service) GetDelegation(ctx context.Context, stakingTxHashHex string) (*StakerDelegationPublic, *types.Error) { @@ -52,7 +52,7 @@ func (s *V2Service) GetDelegation(ctx context.Context, stakingTxHashHex string) return nil, types.NewErrorWithMsg(http.StatusInternalServerError, types.InternalServiceError, "failed to get staker delegation") } - state, err := v2types.DeriveDelegationAPIState(delegation.State, delegation.SubState) + state, err := v2types.MapDelegationState(delegation.State, delegation.SubState) if err != nil { return nil, types.NewErrorWithMsg(http.StatusInternalServerError, types.InternalServiceError, "failed to get delegation state") } @@ -98,7 +98,7 @@ func (s *V2Service) GetDelegations(ctx context.Context, stakerPkHex string, pagi // Group delegations by state for _, delegation := range resultMap.Data { - state, err := v2types.DeriveDelegationAPIState(delegation.State, delegation.SubState) + state, err := v2types.MapDelegationState(delegation.State, delegation.SubState) if err != nil { return nil, "", types.NewErrorWithMsg(http.StatusInternalServerError, types.InternalServiceError, "failed to get delegation state") } diff --git a/internal/v2/types/delegation_states.go b/internal/v2/types/delegation_states.go index 1ba8e9e..9a11921 100644 --- a/internal/v2/types/delegation_states.go +++ b/internal/v2/types/delegation_states.go @@ -7,37 +7,37 @@ import ( ) // DelegationAPIState represents the flattened state for frontend consumption -type DelegationAPIState string +type DelegationState string const ( // Basic states - StatePending DelegationAPIState = "PENDING" - StateVerified DelegationAPIState = "VERIFIED" - StateActive DelegationAPIState = "ACTIVE" + StatePending DelegationState = "PENDING" + StateVerified DelegationState = "VERIFIED" + StateActive DelegationState = "ACTIVE" // Unbonding states - StateTimelockUnbonding DelegationAPIState = "TIMELOCK_UNBONDING" - StateEarlyUnbonding DelegationAPIState = "EARLY_UNBONDING" + StateTimelockUnbonding DelegationState = "TIMELOCK_UNBONDING" + StateEarlyUnbonding DelegationState = "EARLY_UNBONDING" // Withdrawable states - StateTimelockWithdrawable DelegationAPIState = "TIMELOCK_WITHDRAWABLE" - StateEarlyUnbondingWithdrawable DelegationAPIState = "EARLY_UNBONDING_WITHDRAWABLE" - StateTimelockSlashingWithdrawable DelegationAPIState = "TIMELOCK_SLASHING_WITHDRAWABLE" - StateEarlyUnbondingSlashingWithdrawable DelegationAPIState = "EARLY_UNBONDING_SLASHING_WITHDRAWABLE" + StateTimelockWithdrawable DelegationState = "TIMELOCK_WITHDRAWABLE" + StateEarlyUnbondingWithdrawable DelegationState = "EARLY_UNBONDING_WITHDRAWABLE" + StateTimelockSlashingWithdrawable DelegationState = "TIMELOCK_SLASHING_WITHDRAWABLE" + StateEarlyUnbondingSlashingWithdrawable DelegationState = "EARLY_UNBONDING_SLASHING_WITHDRAWABLE" // Withdrawn states - StateTimelockWithdrawn DelegationAPIState = "TIMELOCK_WITHDRAWN" - StateEarlyUnbondingWithdrawn DelegationAPIState = "EARLY_UNBONDING_WITHDRAWN" - StateTimelockSlashingWithdrawn DelegationAPIState = "TIMELOCK_SLASHING_WITHDRAWN" - StateEarlyUnbondingSlashingWithdrawn DelegationAPIState = "EARLY_UNBONDING_SLASHING_WITHDRAWN" + StateTimelockWithdrawn DelegationState = "TIMELOCK_WITHDRAWN" + StateEarlyUnbondingWithdrawn DelegationState = "EARLY_UNBONDING_WITHDRAWN" + StateTimelockSlashingWithdrawn DelegationState = "TIMELOCK_SLASHING_WITHDRAWN" + StateEarlyUnbondingSlashingWithdrawn DelegationState = "EARLY_UNBONDING_SLASHING_WITHDRAWN" // Slashed states - StateTimelockSlashed DelegationAPIState = "TIMELOCK_SLASHED" - StateEarlyUnbondingSlashed DelegationAPIState = "EARLY_UNBONDING_SLASHED" + StateTimelockSlashed DelegationState = "TIMELOCK_SLASHED" + StateEarlyUnbondingSlashed DelegationState = "EARLY_UNBONDING_SLASHED" ) -// DeriveAPIState converts internal states to API states, returns error if combination is invalid -func DeriveDelegationAPIState(state indexertypes.DelegationState, subState indexertypes.DelegationSubState) (DelegationAPIState, error) { +// MapDelegationState converts internal states to API states, returns error if combination is invalid +func MapDelegationState(state indexertypes.DelegationState, subState indexertypes.DelegationSubState) (DelegationState, error) { switch state { case indexertypes.StatePending: return StatePending, nil From eed3116c6cccba8a8b1489e83679912f0f1ca792 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Sun, 24 Nov 2024 22:12:39 +0530 Subject: [PATCH 6/7] fix --- internal/v2/types/delegation_states.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/v2/types/delegation_states.go b/internal/v2/types/delegation_states.go index 9a11921..bd1cc72 100644 --- a/internal/v2/types/delegation_states.go +++ b/internal/v2/types/delegation_states.go @@ -6,7 +6,7 @@ import ( indexertypes "github.com/babylonlabs-io/staking-api-service/internal/indexer/types" ) -// DelegationAPIState represents the flattened state for frontend consumption +// DelegationState represents the flattened state for frontend consumption type DelegationState string const ( @@ -36,7 +36,7 @@ const ( StateEarlyUnbondingSlashed DelegationState = "EARLY_UNBONDING_SLASHED" ) -// MapDelegationState converts internal states to API states, returns error if combination is invalid +// MapDelegationState consumes internal indexer states and maps them to the frontend-facing states func MapDelegationState(state indexertypes.DelegationState, subState indexertypes.DelegationSubState) (DelegationState, error) { switch state { case indexertypes.StatePending: From 32b3d79abea2765d460428a77b3a656160b8b337 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Sun, 24 Nov 2024 22:30:41 +0530 Subject: [PATCH 7/7] fix states --- internal/v2/types/delegation_states.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/v2/types/delegation_states.go b/internal/v2/types/delegation_states.go index bd1cc72..68c3a5a 100644 --- a/internal/v2/types/delegation_states.go +++ b/internal/v2/types/delegation_states.go @@ -80,9 +80,9 @@ func MapDelegationState(state indexertypes.DelegationState, subState indexertype case indexertypes.StateSlashed: switch subState { - case indexertypes.SubStateTimelockSlashing: + case indexertypes.SubStateTimelock: return StateTimelockSlashed, nil - case indexertypes.SubStateEarlyUnbondingSlashing: + case indexertypes.SubStateEarlyUnbonding: return StateEarlyUnbondingSlashed, nil } }