Skip to content

Commit

Permalink
Update local chain implementation for coordinator package
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba committed Jun 26, 2023
1 parent d55dfa2 commit 74e0933
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions pkg/coordinator/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/keep-network/keep-core/pkg/tbtc"
)

type localTbtcChain struct {
type localChain struct {
mutex sync.Mutex

depositRequests map[[32]byte]*tbtc.DepositChainRequest
Expand All @@ -32,16 +32,16 @@ type depositParameters = struct {
revealAheadPeriod uint32
}

func newLocalTbtcChain() *localTbtcChain {
return &localTbtcChain{
func newLocalTbtcChain() *localChain {
return &localChain{
depositRequests: make(map[[32]byte]*tbtc.DepositChainRequest),
pastDepositRevealedEvents: make(map[[32]byte][]*tbtc.DepositRevealedEvent),
pastNewWalletRegisteredEvents: make(map[[32]byte][]*coordinator.NewWalletRegisteredEvent),
depositSweepProposalValidations: make(map[[32]byte]bool),
}
}

func (lc *localTbtcChain) PastDepositRevealedEvents(
func (lc *localChain) PastDepositRevealedEvents(
filter *tbtc.DepositRevealedEventFilter,
) ([]*tbtc.DepositRevealedEvent, error) {
lc.mutex.Lock()
Expand All @@ -60,7 +60,7 @@ func (lc *localTbtcChain) PastDepositRevealedEvents(
return events, nil
}

func (lc *localTbtcChain) addPastDepositRevealedEvent(
func (lc *localChain) addPastDepositRevealedEvent(
filter *tbtc.DepositRevealedEventFilter,
event *tbtc.DepositRevealedEvent,
) error {
Expand Down Expand Up @@ -115,7 +115,7 @@ func buildPastDepositRevealedEventsKey(
return sha256.Sum256(buffer.Bytes()), nil
}

func (lc *localTbtcChain) GetDepositRequest(
func (lc *localChain) GetDepositRequest(
fundingTxHash bitcoin.Hash,
fundingOutputIndex uint32,
) (*tbtc.DepositChainRequest, error) {
Expand All @@ -132,7 +132,7 @@ func (lc *localTbtcChain) GetDepositRequest(
return request, nil
}

func (lc *localTbtcChain) setDepositRequest(
func (lc *localChain) setDepositRequest(
fundingTxHash bitcoin.Hash,
fundingOutputIndex uint32,
request *tbtc.DepositChainRequest,
Expand All @@ -145,7 +145,7 @@ func (lc *localTbtcChain) setDepositRequest(
lc.depositRequests[requestKey] = request
}

func (lc *localTbtcChain) PastNewWalletRegisteredEvents(
func (lc *localChain) PastNewWalletRegisteredEvents(
filter *coordinator.NewWalletRegisteredEventFilter,
) ([]*coordinator.NewWalletRegisteredEvent, error) {
lc.mutex.Lock()
Expand All @@ -164,7 +164,7 @@ func (lc *localTbtcChain) PastNewWalletRegisteredEvents(
return events, nil
}

func (lc *localTbtcChain) addPastNewWalletRegisteredEvent(
func (lc *localChain) addPastNewWalletRegisteredEvent(
filter *coordinator.NewWalletRegisteredEventFilter,
event *coordinator.NewWalletRegisteredEvent,
) error {
Expand Down Expand Up @@ -218,13 +218,13 @@ func buildPastNewWalletRegisteredEventsKey(
return sha256.Sum256(buffer.Bytes()), nil
}

func (lc *localTbtcChain) PastRedemptionRequestedEvents(
func (lc *localChain) PastRedemptionRequestedEvents(
filter *tbtc.RedemptionRequestedEventFilter,
) ([]*tbtc.RedemptionRequestedEvent, error) {
panic("unsupported")
}

func (lc *localTbtcChain) BuildDepositKey(fundingTxHash bitcoin.Hash, fundingOutputIndex uint32) *big.Int {
func (lc *localChain) BuildDepositKey(fundingTxHash bitcoin.Hash, fundingOutputIndex uint32) *big.Int {
depositKeyBytes := buildDepositRequestKey(fundingTxHash, fundingOutputIndex)

return new(big.Int).SetBytes(depositKeyBytes[:])
Expand All @@ -240,14 +240,14 @@ func buildDepositRequestKey(
return sha256.Sum256(append(fundingTxHash[:], fundingOutputIndexBytes...))
}

func (lc *localTbtcChain) BuildRedemptionKey(
func (lc *localChain) BuildRedemptionKey(
walletPublicKeyHash [20]byte,
redeemerOutputScript bitcoin.Script,
) (*big.Int, error) {
panic("unsupported")
}

func (lc *localTbtcChain) GetDepositParameters() (
func (lc *localChain) GetDepositParameters() (
dustThreshold uint64,
treasuryFeeDivisor uint64,
txMaxFee uint64,
Expand All @@ -264,7 +264,14 @@ func (lc *localTbtcChain) GetDepositParameters() (
nil
}

func (lc *localTbtcChain) setDepositParameters(
func (lc *localChain) GetPendingRedemptionRequest(
walletPublicKeyHash [20]byte,
redeemerOutputScript bitcoin.Script,
) (*tbtc.RedemptionRequest, error) {
panic("unsupported")
}

func (lc *localChain) setDepositParameters(
dustThreshold uint64,
treasuryFeeDivisor uint64,
txMaxFee uint64,
Expand All @@ -281,7 +288,7 @@ func (lc *localTbtcChain) setDepositParameters(
}
}

func (lc *localTbtcChain) GetRedemptionParameters() (
func (lc *localChain) GetRedemptionParameters() (
dustThreshold uint64,
treasuryFeeDivisor uint64,
txMaxFee uint64,
Expand All @@ -294,7 +301,7 @@ func (lc *localTbtcChain) GetRedemptionParameters() (
panic("unsupported")
}

func (lc *localTbtcChain) ValidateDepositSweepProposal(
func (lc *localChain) ValidateDepositSweepProposal(
proposal *tbtc.DepositSweepProposal,
depositsExtraInfo []struct {
*tbtc.Deposit
Expand All @@ -321,7 +328,7 @@ func (lc *localTbtcChain) ValidateDepositSweepProposal(
return nil
}

func (lc *localTbtcChain) setDepositSweepProposalValidationResult(
func (lc *localChain) setDepositSweepProposalValidationResult(
proposal *tbtc.DepositSweepProposal,
depositsExtraInfo []struct {
*tbtc.Deposit
Expand Down Expand Up @@ -362,7 +369,7 @@ func buildDepositSweepProposalValidationKey(
return sha256.Sum256(buffer.Bytes()), nil
}

func (lc *localTbtcChain) SubmitDepositSweepProposalWithReimbursement(
func (lc *localChain) SubmitDepositSweepProposalWithReimbursement(
proposal *tbtc.DepositSweepProposal,
) error {
lc.mutex.Lock()
Expand All @@ -373,26 +380,26 @@ func (lc *localTbtcChain) SubmitDepositSweepProposalWithReimbursement(
return nil
}

func (lc *localTbtcChain) SubmitRedemptionProposalWithReimbursement(
func (lc *localChain) SubmitRedemptionProposalWithReimbursement(
proposal *tbtc.RedemptionProposal,
) error {
panic("unsupported")
}

func (lc *localTbtcChain) GetDepositSweepMaxSize() (uint16, error) {
func (lc *localChain) GetDepositSweepMaxSize() (uint16, error) {
panic("unsupported")
}

func (lc *localTbtcChain) ValidateRedemptionProposal(
func (lc *localChain) ValidateRedemptionProposal(
proposal *tbtc.RedemptionProposal,
) error {
panic("unsupported")
}

func (lc *localTbtcChain) GetRedemptionMaxSize() (uint16, error) {
func (lc *localChain) GetRedemptionMaxSize() (uint16, error) {
panic("unsupported")
}

func (lc *localTbtcChain) GetRedemptionRequestMinAge() (uint32, error) {
func (lc *localChain) GetRedemptionRequestMinAge() (uint32, error) {
panic("unsupported")
}

0 comments on commit 74e0933

Please sign in to comment.