Skip to content

Commit

Permalink
Merge branch 'main' into fix-go-releaser
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Nov 12, 2024
2 parents 8a7a05e + 64a724d commit 67e2a35
Show file tree
Hide file tree
Showing 18 changed files with 663 additions and 419 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

* [#22](https://github.com/babylonlabs-io/covenant-emulator/pull/22) Go releaser setup
and move changelog reminder out

## v0.7.0

### Improvements

* [#25](https://github.com/babylonlabs-io/covenant-emulator/pull/25) Bump Babylon to v0.15.0

## v0.6.0

### Improvements

* [#24](https://github.com/babylonlabs-io/covenant-emulator/pull/24) Bump Babylon to v0.14.0

## v0.5.0

### Bug fixes

* [#23](https://github.com/babylonlabs-io/covenant-emulator/pull/23) Fix pre-approval flow

### Improvements

* [#20](https://github.com/babylonlabs-io/covenant-emulator/pull/20) Add signing behind
interface.
25 changes: 16 additions & 9 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ func (bc *BabylonController) QueryActiveDelegations(limit uint64) ([]*types.Dele
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_ACTIVE, limit)
}

func (bc *BabylonController) QueryVerifiedDelegations(limit uint64) ([]*types.Delegation, error) {
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_VERIFIED, limit)
}

// queryDelegationsWithStatus queries BTC delegations that need a Covenant signature
// with the given status (either pending or unbonding)
// it is only used when the program is running in Covenant mode
Expand Down Expand Up @@ -273,6 +277,7 @@ func DelegationRespToDelegation(del *btcstakingtypes.BTCDelegationResponse) (*ty
BtcPk: del.BtcPk.MustToBTCPK(),
FpBtcPks: fpBtcPks,
TotalSat: btcutil.Amount(del.TotalSat),
StakingTime: del.StakingTime,
StartHeight: del.StartHeight,
EndHeight: del.EndHeight,
StakingTxHex: del.StakingTxHex,
Expand All @@ -288,7 +293,6 @@ func UndelegationRespToUndelegation(undel *btcstakingtypes.BTCUndelegationRespon
var (
covenantSlashingSigs []*types.CovenantAdaptorSigInfo
covenantUnbondingSigs []*types.CovenantSchnorrSigInfo
err error
)

if undel.UnbondingTxHex == "" {
Expand Down Expand Up @@ -319,20 +323,17 @@ func UndelegationRespToUndelegation(undel *btcstakingtypes.BTCUndelegationRespon
covenantSlashingSigs = append(covenantSlashingSigs, covSigInfo)
}

delegatorUnbondingSig := new(bbntypes.BIP340Signature)
if undel.DelegatorUnbondingSigHex != "" {
delegatorUnbondingSig, err = bbntypes.NewBIP340SignatureFromHex(undel.DelegatorUnbondingSigHex)
if err != nil {
return nil, err
}
var spendStakeTxHex = ""
if undel.DelegatorUnbondingInfoResponse != nil {
spendStakeTxHex = undel.DelegatorUnbondingInfoResponse.SpendStakeTxHex
}

return &types.Undelegation{
UnbondingTxHex: undel.UnbondingTxHex,
SlashingTxHex: undel.SlashingTxHex,
CovenantSlashingSigs: covenantSlashingSigs,
CovenantUnbondingSigs: covenantUnbondingSigs,
DelegatorUnbondingSig: delegatorUnbondingSig,
SpendStakeTxHex: spendStakeTxHex,
}, nil
}

Expand All @@ -351,12 +352,18 @@ func (bc *BabylonController) CreateBTCDelegation(
unbondingValue int64,
unbondingSlashingTx *btcstakingtypes.BTCSlashingTx,
delUnbondingSlashingSig *bbntypes.BIP340Signature,
isPreApproval bool,
) (*types.TxResponse, error) {
fpBtcPks := make([]bbntypes.BIP340PubKey, 0, len(fpPks))
for _, v := range fpPks {
fpBtcPks = append(fpBtcPks, *bbntypes.NewBIP340PubKeyFromBTCPK(v))
}

var inclusionProof *btcstakingtypes.InclusionProof
if !isPreApproval {
inclusionProof = btcstakingtypes.NewInclusionProof(stakingTxInfo.Key, stakingTxInfo.Proof)
}

msg := &btcstakingtypes.MsgCreateBTCDelegation{
StakerAddr: bc.mustGetTxSigner(),
Pop: pop,
Expand All @@ -365,7 +372,7 @@ func (bc *BabylonController) CreateBTCDelegation(
StakingTime: stakingTime,
StakingValue: stakingValue,
StakingTx: stakingTxInfo.Transaction,
StakingTxInclusionProof: btcstakingtypes.NewInclusionProof(stakingTxInfo.Key, stakingTxInfo.Proof),
StakingTxInclusionProof: inclusionProof,
SlashingTx: slashingTx,
DelegatorSlashingSig: delSlashingSig,
UnbondingTx: unbondingTx,
Expand Down
4 changes: 2 additions & 2 deletions cmd/covd/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/urfave/cli"

covcfg "github.com/babylonlabs-io/covenant-emulator/config"
"github.com/babylonlabs-io/covenant-emulator/covenant"
"github.com/babylonlabs-io/covenant-emulator/keyring"
)

type covenantKey struct {
Expand Down Expand Up @@ -71,7 +71,7 @@ func createKey(ctx *cli.Context) error {
return fmt.Errorf("failed to load the config from %s: %w", covcfg.ConfigFile(homePath), err)
}

keyPair, err := covenant.CreateCovenantKey(
keyPair, err := keyring.CreateCovenantKey(
homePath,
chainID,
keyName,
Expand Down
20 changes: 19 additions & 1 deletion cmd/covd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"

covcfg "github.com/babylonlabs-io/covenant-emulator/config"
"github.com/babylonlabs-io/covenant-emulator/keyring"
"github.com/babylonlabs-io/covenant-emulator/log"
"github.com/babylonlabs-io/covenant-emulator/util"

Expand Down Expand Up @@ -57,7 +58,14 @@ func start(ctx *cli.Context) error {
return fmt.Errorf("failed to create rpc client for the consumer chain: %w", err)
}

ce, err := covenant.NewCovenantEmulator(cfg, bbnClient, ctx.String(passphraseFlag), logger)
pwd := ctx.String(passphraseFlag)

signer, err := newSignerFromConfig(cfg, pwd)
if err != nil {
return fmt.Errorf("failed to create signer from config: %w", err)
}

ce, err := covenant.NewCovenantEmulator(cfg, bbnClient, logger, signer)
if err != nil {
return fmt.Errorf("failed to start the covenant emulator: %w", err)
}
Expand All @@ -75,3 +83,13 @@ func start(ctx *cli.Context) error {

return srv.RunUntilShutdown()
}

func newSignerFromConfig(cfg *covcfg.Config, passphrase string) (*keyring.KeyringSigner, error) {
return keyring.NewKeyringSigner(
cfg.BabylonConfig.ChainID,
cfg.BabylonConfig.Key,
cfg.BabylonConfig.KeyDirectory,
cfg.BabylonConfig.KeyringBackend,
passphrase,
)
}
Loading

0 comments on commit 67e2a35

Please sign in to comment.