From 5110a92ac38db498f9519285cd887ba62ddc5539 Mon Sep 17 00:00:00 2001 From: Gurjot Date: Thu, 21 Nov 2024 15:08:10 +0530 Subject: [PATCH] fix --- internal/db/model/delegation.go | 70 ++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/internal/db/model/delegation.go b/internal/db/model/delegation.go index fb12365..c504920 100644 --- a/internal/db/model/delegation.go +++ b/internal/db/model/delegation.go @@ -16,23 +16,27 @@ type CovenantSignature struct { SignatureHex string `bson:"signature_hex"` } +type BTCDelegationCreatedBbnBlock struct { + Height int64 `bson:"height"` + Timestamp int64 `bson:"timestamp"` // epoch time in seconds +} + type BTCDelegationDetails struct { - StakingTxHashHex string `bson:"_id"` // Primary key - StakingTxHex string `bson:"staking_tx_hex"` - StakingTime uint32 `bson:"staking_time"` - StakingAmount uint64 `bson:"staking_amount"` - StakingOutputIdx uint32 `bson:"staking_output_idx"` - StakerBtcPkHex string `bson:"staker_btc_pk_hex"` - FinalityProviderBtcPksHex []string `bson:"finality_provider_btc_pks_hex"` - StartHeight uint32 `bson:"start_height"` - EndHeight uint32 `bson:"end_height"` - State types.DelegationState `bson:"state"` - ParamsVersion uint32 `bson:"params_version"` - UnbondingTime uint32 `bson:"unbonding_time"` - UnbondingTx string `bson:"unbonding_tx"` - CovenantUnbondingSignatures []CovenantSignature `bson:"covenant_unbonding_signatures"` - BTCDelegationCreatedBbnHeight int64 `bson:"btc_delegation_created_bbn_height"` - BTCDelegationCreatedBbnTimestamp int64 `bson:"btc_delegation_created_bbn_timestamp"` // epoch time in seconds + StakingTxHashHex string `bson:"_id"` // Primary key + StakingTxHex string `bson:"staking_tx_hex"` + StakingTime uint32 `bson:"staking_time"` + StakingAmount uint64 `bson:"staking_amount"` + StakingOutputIdx uint32 `bson:"staking_output_idx"` + StakerBtcPkHex string `bson:"staker_btc_pk_hex"` + FinalityProviderBtcPksHex []string `bson:"finality_provider_btc_pks_hex"` + StartHeight uint32 `bson:"start_height"` + EndHeight uint32 `bson:"end_height"` + State types.DelegationState `bson:"state"` + ParamsVersion uint32 `bson:"params_version"` + UnbondingTime uint32 `bson:"unbonding_time"` + UnbondingTx string `bson:"unbonding_tx"` + CovenantUnbondingSignatures []CovenantSignature `bson:"covenant_unbonding_signatures"` + BTCDelegationCreatedBlock BTCDelegationCreatedBbnBlock `bson:"btc_delegation_created_bbn_block"` } func FromEventBTCDelegationCreated( @@ -88,22 +92,24 @@ func FromEventBTCDelegationCreated( stakingValue := btcutil.Amount(stakingTx.TxOut[stakingOutputIdx].Value) return &BTCDelegationDetails{ - StakingTxHashHex: stakingTx.TxHash().String(), - StakingTxHex: event.StakingTxHex, - StakingTime: uint32(stakingTime), - StakingAmount: uint64(stakingValue), - StakingOutputIdx: uint32(stakingOutputIdx), - StakerBtcPkHex: event.StakerBtcPkHex, - FinalityProviderBtcPksHex: event.FinalityProviderBtcPksHex, - ParamsVersion: uint32(paramsVersion), - UnbondingTime: uint32(unbondingTime), - UnbondingTx: event.UnbondingTx, - State: types.StatePending, // initial state will always be PENDING - StartHeight: uint32(0), // it should be set when the inclusion proof is received - EndHeight: uint32(0), // it should be set when the inclusion proof is received - CovenantUnbondingSignatures: []CovenantSignature{}, - BTCDelegationCreatedBbnHeight: bbnBlockHeight, - BTCDelegationCreatedBbnTimestamp: bbnBlockTime, + StakingTxHashHex: stakingTx.TxHash().String(), + StakingTxHex: event.StakingTxHex, + StakingTime: uint32(stakingTime), + StakingAmount: uint64(stakingValue), + StakingOutputIdx: uint32(stakingOutputIdx), + StakerBtcPkHex: event.StakerBtcPkHex, + FinalityProviderBtcPksHex: event.FinalityProviderBtcPksHex, + ParamsVersion: uint32(paramsVersion), + UnbondingTime: uint32(unbondingTime), + UnbondingTx: event.UnbondingTx, + State: types.StatePending, // initial state will always be PENDING + StartHeight: uint32(0), // it should be set when the inclusion proof is received + EndHeight: uint32(0), // it should be set when the inclusion proof is received + CovenantUnbondingSignatures: []CovenantSignature{}, + BTCDelegationCreatedBlock: BTCDelegationCreatedBbnBlock{ + Height: bbnBlockHeight, + Timestamp: bbnBlockTime, + }, }, nil }