-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1f8cbe
commit 6f4f0c1
Showing
2 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package tbtcpg | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ipfs/go-log/v2" | ||
"go.uber.org/zap" | ||
|
||
"github.com/keep-network/keep-core/pkg/bitcoin" | ||
"github.com/keep-network/keep-core/pkg/tbtc" | ||
) | ||
|
||
type MovedFundsSweepTask struct { | ||
chain Chain | ||
btcChain bitcoin.Chain | ||
} | ||
|
||
func NewMovedFundsSweepTask( | ||
chain Chain, | ||
btcChain bitcoin.Chain, | ||
) *MovedFundsSweepTask { | ||
return &MovedFundsSweepTask{ | ||
chain: chain, | ||
btcChain: btcChain, | ||
} | ||
} | ||
|
||
func (mfst *MovedFundsSweepTask) Run(request *tbtc.CoordinationProposalRequest) ( | ||
tbtc.CoordinationProposal, | ||
bool, | ||
error, | ||
) { | ||
walletPublicKeyHash := request.WalletPublicKeyHash | ||
|
||
taskLogger := logger.With( | ||
zap.String("task", mfst.ActionType().String()), | ||
zap.String("walletPKH", fmt.Sprintf("0x%x", walletPublicKeyHash)), | ||
) | ||
|
||
walletChainData, err := mfst.chain.GetWallet(walletPublicKeyHash) | ||
if err != nil { | ||
return nil, false, fmt.Errorf( | ||
"cannot get wallet's chain data: [%w]", | ||
err, | ||
) | ||
} | ||
|
||
if walletChainData.State != tbtc.StateLive && | ||
walletChainData.State != tbtc.StateMovingFunds { | ||
taskLogger.Infof("wallet not in Live or MoveFunds state") | ||
return nil, false, nil | ||
} | ||
|
||
if walletChainData.PendingMovedFundsSweepRequestsCount == 0 { | ||
taskLogger.Infof("wallet has no pending moved funds sweep requests") | ||
return nil, false, nil | ||
} | ||
|
||
movingFundsTxHash, movingFundsOutputIdx, err := mfst.FindMovingFundsTxData( | ||
walletPublicKeyHash, | ||
) | ||
if err != nil { | ||
return nil, false, fmt.Errorf( | ||
"cannot find moving funds transaction data: [%w]", | ||
err, | ||
) | ||
} | ||
|
||
proposal, err := mfst.ProposeMovedFundsSweep( | ||
taskLogger, | ||
walletPublicKeyHash, | ||
movingFundsTxHash, | ||
movingFundsOutputIdx, | ||
0, | ||
) | ||
if err != nil { | ||
return nil, false, fmt.Errorf( | ||
"cannot prepare moved funds sweep proposal: [%w]", | ||
err, | ||
) | ||
} | ||
|
||
return proposal, true, nil | ||
} | ||
|
||
func (mfst *MovedFundsSweepTask) FindMovingFundsTxData( | ||
walletPublicKeyHash [20]byte, | ||
) ( | ||
txHash bitcoin.Hash, | ||
txOutputIdx uint32, | ||
err error, | ||
) { | ||
// TODO: Implement | ||
return bitcoin.Hash{}, 0, nil | ||
} | ||
|
||
func (mfst *MovedFundsSweepTask) ActionType() tbtc.WalletActionType { | ||
return tbtc.ActionMovedFundsSweep | ||
} | ||
|
||
func (mfst *MovedFundsSweepTask) ProposeMovedFundsSweep( | ||
taskLogger log.StandardLogger, | ||
walletPublicKeyHash [20]byte, | ||
movingFundsTxHash bitcoin.Hash, | ||
movingFundsTxIndex uint32, | ||
fee int64, | ||
) (*tbtc.MovedFundsSweepProposal, error) { | ||
// TODO: Implement | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters