diff --git a/cmd/stakercli/daemon/daemoncommands.go b/cmd/stakercli/daemon/daemoncommands.go index c51c3d9..3cf70e7 100644 --- a/cmd/stakercli/daemon/daemoncommands.go +++ b/cmd/stakercli/daemon/daemoncommands.go @@ -2,6 +2,7 @@ package daemon import ( "context" + "errors" "strconv" "github.com/babylonlabs-io/btc-staker/cmd/stakercli/helpers" @@ -150,7 +151,7 @@ var stakeFromPhase1Cmd = cli.Command{ Required: true, }, }, - Action: stake, + Action: stakeFromPhase1TxBTC, } var unstakeCmd = cli.Command{ @@ -365,10 +366,36 @@ func stakeFromPhase1TxBTC(ctx *cli.Context) error { sctx := context.Background() 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 { diff --git a/staker/stakerapp.go b/staker/stakerapp.go index d7813ec..d57881d 100644 --- a/staker/stakerapp.go +++ b/staker/stakerapp.go @@ -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" @@ -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) +} diff --git a/stakerservice/service.go b/stakerservice/service.go index 45f5274..5faa942 100644 --- a/stakerservice/service.go +++ b/stakerservice/service.go @@ -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) + if err != nil { + return nil, err + } + + return nil, nil +} + func (s *StakerService) stakingDetails(_ *rpctypes.Context, stakingTxHash string) (*StakingDetails, error) { @@ -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"),