Skip to content

Commit

Permalink
Implemented validation of moved funds sweep proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Feb 28, 2024
1 parent 4cb0a46 commit e2d160b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
21 changes: 20 additions & 1 deletion pkg/chain/ethereum/tbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,26 @@ func (tc *TbtcChain) ValidateMovedFundsSweepProposal(
walletPublicKeyHash [20]byte,
proposal *tbtc.MovedFundsSweepProposal,
) error {
// TODO: Implement
abiProposal := tbtcabi.WalletProposalValidatorMovedFundsSweepProposal{
WalletPubKeyHash: walletPublicKeyHash,
MovingFundsTxHash: proposal.MovingFundsTxHash,
MovingFundsTxOutputIndex: proposal.MovingFundsTxOutputIndex,
MovedFundsSweepTxFee: proposal.SweepTxFee,
}

valid, err := tc.walletProposalValidator.ValidateMovedFundsSweepProposal(
abiProposal,
)
if err != nil {
return fmt.Errorf("validation failed: [%v]", err)
}

// Should never happen because `validateMovedFundsSweepProposal` returns
// true or reverts (returns an error) but do the check just in case.
if !valid {
return fmt.Errorf("unexpected validation result")
}

return nil
}

Expand Down
15 changes: 14 additions & 1 deletion pkg/tbtc/moved_funds_sweep.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tbtc

import (
"fmt"
"math/big"
"time"

Expand Down Expand Up @@ -63,6 +64,18 @@ func ValidateMovedFundsSweepProposal(
) error
},
) error {
// TODO: Implement
validateProposalLogger.Infof("calling chain for proposal validation")

err := chain.ValidateMovedFundsSweepProposal(
walletPublicKeyHash,
proposal,
)

if err != nil {
return fmt.Errorf("moved funds sweep proposal is invalid: [%v]", err)
}

validateProposalLogger.Infof("moved funds sweep proposal is valid")

return nil
}
2 changes: 1 addition & 1 deletion pkg/tbtcpg/moved_funds_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/keep-network/keep-core/pkg/tbtcpg"
)

func TestFindMovingFundsTxData(t *testing.T) {
func TestMovedFundsSweepAction_FindMovingFundsTxData(t *testing.T) {
walletPublicKeyHash := hexToByte20(
"92a6ec889a8fa34f731e639edede4c75e184307c",
)
Expand Down

0 comments on commit e2d160b

Please sign in to comment.