Skip to content

Commit

Permalink
pass json serializable params
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Nov 22, 2024
1 parent 323cdcf commit f57a446
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/stakercli/daemon/daemoncommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,11 @@ func stakeFromPhase1TxBTC(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("error parsing file %s: %w", inputGlobalParamsFilePath, err)
}
fmt.Printf("globalParams: %v\n", globalParams)

stakerAddress := ctx.String(stakerAddressFlag)
_, err = client.BtcDelegationFromBtcStakingTx(sctx, stakerAddress, stakingTransactionHash, globalParams)
// TODO: pass global params and not nill
_, err = client.BtcDelegationFromBtcStakingTx(sctx, stakerAddress, stakingTransactionHash, nil)
return err
}

Expand Down
4 changes: 3 additions & 1 deletion itest/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ func TestStakeFromPhase1(t *testing.T) {
covenantPkSerializedHex := hex.EncodeToString(schnorr.SerializePubKey(coventantPrivKeys[0].PubKey()))
covenantPkHex := hex.EncodeToString(coventantPrivKeys[0].PubKey().SerializeCompressed())

fmt.Printf("covenantPkSerializedHex: %s\n", covenantPkSerializedHex)

lastParams := &parser.VersionedGlobalParams{
Version: 0,
ActivationHeight: 100,
Expand Down Expand Up @@ -996,7 +998,7 @@ func TestStakeFromPhase1(t *testing.T) {
stkTxHash := signedStkTx.TxHash().String()

// miner address and the staker addr are the same guy, maybe not
res, err := tmStakerApp.StakerClient.BtcDelegationFromBtcStakingTx(ctx, stakerAddrStr, stkTxHash, parsedGlobalParams)
res, err := tmStakerApp.StakerClient.BtcDelegationFromBtcStakingTx(ctx, stakerAddrStr, stkTxHash, &globalParams)
require.NoError(t, err)
require.NotNil(t, res)

Expand Down
2 changes: 1 addition & 1 deletion stakerservice/client/rpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *StakerServiceJSONRPCClient) BtcDelegationFromBtcStakingTx(
ctx context.Context,
stakerAddress string,
btcStkTxHash string,
globalParams *parser.ParsedGlobalParams,
globalParams *parser.GlobalParams,
) (*service.ResultBtcDelegationFromBtcStakingTx, error) {
result := new(service.ResultBtcDelegationFromBtcStakingTx)

Expand Down
16 changes: 14 additions & 2 deletions stakerservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *StakerService) btcDelegationFromBtcStakingTx(
_ *rpctypes.Context,
stakerAddress string,
btcStkTxHash string,
globalParams *parser.ParsedGlobalParams,
globalParams *parser.GlobalParams,
) (*ResultBtcDelegationFromBtcStakingTx, error) {
stkTxHash, err := chainhash.NewHashFromStr(btcStkTxHash)
if err != nil {
Expand All @@ -153,7 +153,14 @@ func (s *StakerService) btcDelegationFromBtcStakingTx(
}

wireStkTx := stkTx.MsgTx()
parsedStakingTx, err := ParseV0StakingTx(globalParams, s.staker.BtcParams(), wireStkTx)

parsedGlobalParams, err := parser.ParseGlobalParams(globalParams)
if err != nil {
s.logger.WithError(err).Info("err parse global params")
return nil, err
}

parsedStakingTx, err := ParseV0StakingTx(parsedGlobalParams, s.staker.BtcParams(), wireStkTx)
if err != nil {
s.logger.WithError(err).Info("err parse staking Tx with global params")
return nil, err
Expand All @@ -171,6 +178,11 @@ func ParseV0StakingTx(globalParams *parser.ParsedGlobalParams, btcParams *chainc
var lastErr error
for i := len(globalParams.Versions) - 1; i >= 0; i-- {
params := globalParams.Versions[i]
fmt.Printf("Parsing the v0 staking tx with the following covenant pks: \n")
for _, pk := range params.CovenantPks {
fmt.Printf("pk: %s\n", hex.EncodeToString(schnorr.SerializePubKey(pk)))
}

parsedStakingTx, err := btcstaking.ParseV0StakingTx(
wireStkTx,
params.Tag,
Expand Down

0 comments on commit f57a446

Please sign in to comment.