Skip to content

Commit

Permalink
chore: add initial impl to btc staking from phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Nov 5, 2024
1 parent db1692a commit d76b933
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
35 changes: 31 additions & 4 deletions cmd/stakercli/daemon/daemoncommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daemon

import (
"context"
"errors"
"strconv"

"github.com/babylonlabs-io/btc-staker/cmd/stakercli/helpers"
Expand Down Expand Up @@ -150,7 +151,7 @@ var stakeFromPhase1Cmd = cli.Command{
Required: true,
},
},
Action: stake,
Action: stakeFromPhase1TxBTC,
}

var unstakeCmd = cli.Command{
Expand Down Expand Up @@ -365,10 +366,36 @@ func stakeFromPhase1TxBTC(ctx *cli.Context) error {
sctx := context.Background()

Check failure on line 366 in cmd/stakercli/daemon/daemoncommands.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

sctx declared and not used (typecheck)

stakingTransactionHash := ctx.String(stakingTransactionHashFlag)
stakingTx, err := client.StakingDetails(sctx, stakingTransactionHash)
if err != nil {
return err
if len(stakingTransactionHash) == 0 {
return errors.New("staking tx hash hex is empty")
}
// staking details is not good, because it loads from db, not BTC
// stakingTx, err := client.StakingDetails(sctx, stakingTransactionHash)

// stakingTx.

// sig, err := app.wc.SignBip322NativeSegwit(babylonAddrHash, stakerAddress)

// if err != nil {
// return nil, err
// }

// pop, err := cl.NewBabylonBip322Pop(
// babylonAddrHash,
// sig,
// stakerAddress,
// )

// if err := app.txTracker.AddTransactionSentToBTC(
// stakingTx,
// stakingOutputIdx,
// cmd.stakingTime,
// cmd.fpBtcPks,
// babylonPopToDbPop(cmd.pop),
// cmd.stakerAddress,
// ); err != nil {
// return nil, err
// }

// results, err := client.Stake(sctx, stakerAddress, stakingAmount, fpPks, stakingTimeBlocks, sendToBabylonFirst)
// if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions staker/stakerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand Down Expand Up @@ -2188,3 +2189,7 @@ func (app *StakerApp) UnbondStaking(
unbondingTxHash := tx.UnbondingTxData.UnbondingTx.TxHash()
return &unbondingTxHash, nil
}

func (app *StakerApp) TxDetailsBTC(stakingTxHash *chainhash.Hash) (*btcjson.GetTransactionResult, *btcutil.Tx, error) {
return app.wc.Tx(stakingTxHash)
}
17 changes: 17 additions & 0 deletions stakerservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ func (s *StakerService) stake(_ *rpctypes.Context,
}, nil
}

func (s *StakerService) bbnStakeFromBTCStakingTx(_ *rpctypes.Context,
btcStkTxHash string,
) (*struct{}, error) {
stkTxHash, err := chainhash.NewHashFromStr(btcStkTxHash)
if err != nil {
return nil, err
}

tx, _, err := s.staker.TxDetailsBTC(stkTxHash)

Check failure on line 137 in stakerservice/service.go

View workflow job for this annotation

GitHub Actions / lint_test / integration-tests

tx declared and not used

Check failure on line 137 in stakerservice/service.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

tx declared and not used (typecheck)

Check failure on line 137 in stakerservice/service.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

tx declared and not used) (typecheck)

Check failure on line 137 in stakerservice/service.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

tx declared and not used) (typecheck)

Check failure on line 137 in stakerservice/service.go

View workflow job for this annotation

GitHub Actions / lint_test / unit-tests

tx declared and not used
if err != nil {
return nil, err
}

return nil, nil
}

func (s *StakerService) stakingDetails(_ *rpctypes.Context,
stakingTxHash string) (*StakingDetails, error) {

Expand Down Expand Up @@ -551,6 +567,7 @@ func (s *StakerService) GetRoutes() RoutesMap {
"health": rpc.NewRPCFunc(s.health, ""),
// staking API
"stake": rpc.NewRPCFunc(s.stake, "stakerAddress,stakingAmount,fpBtcPks,stakingTimeBlocks,sendToBabylonFirst"),
"bbnStakeFromBTCStakingTx": rpc.NewRPCFunc(s.bbnStakeFromBTCStakingTx, "btcStkTxHash"),
"staking_details": rpc.NewRPCFunc(s.stakingDetails, "stakingTxHash"),
"spend_stake": rpc.NewRPCFunc(s.spendStake, "stakingTxHash"),
"list_staking_transactions": rpc.NewRPCFunc(s.listStakingTransactions, "offset,limit"),
Expand Down

0 comments on commit d76b933

Please sign in to comment.