Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 committed Nov 21, 2024
1 parent 822566e commit 5110a92
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions internal/db/model/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 5110a92

Please sign in to comment.