-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d0a9d3
commit cf98662
Showing
19 changed files
with
310 additions
and
102 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package indexerdbmodel | ||
|
||
const ( | ||
FinalityProviderDetailsCollection = "finality_provider_details" | ||
BTCDelegationDetailsCollection = "btc_delegation_details" | ||
TimeLockCollection = "timelock" | ||
GlobalParamsCollection = "global_params" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.