Skip to content

Commit

Permalink
TbtcChain GetDKGState replaced with a real implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pdyraga committed Dec 2, 2022
1 parent 814ea66 commit 0fa98da
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions pkg/chain/ethereum/tbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,31 @@ func convertPubKeyToChainFormat(publicKey *ecdsa.PublicKey) ([64]byte, error) {
return serialized, nil
}

// TODO: Implement a real GetDKGState function.
func (tc *TbtcChain) GetDKGState() (tbtc.DKGState, error) {
return tc.mockWalletRegistry.GetDKGState()
walletCreationState, err := tc.walletRegistry.GetWalletCreationState()
if err != nil {
return 0, err
}

var state tbtc.DKGState

switch walletCreationState {
case 0:
state = tbtc.Idle
case 1:
state = tbtc.AwaitingSeed
case 2:
state = tbtc.AwaitingResult
case 3:
state = tbtc.Challenge
default:
err = fmt.Errorf(
"unexpected wallet creation state: [%v]",
walletCreationState,
)
}

return state, err
}

// CalculateDKGResultHash calculates Keccak-256 hash of the DKG result. Operation
Expand Down Expand Up @@ -619,14 +641,3 @@ func (mwr *mockWalletRegistry) OnSignatureRequested(
cancelCtx()
})
}

func (mwr *mockWalletRegistry) GetDKGState() (tbtc.DKGState, error) {
mwr.currentDkgMutex.RLock()
defer mwr.currentDkgMutex.RUnlock()

if mwr.currentDkgStartBlock != nil {
return tbtc.AwaitingResult, nil
}

return tbtc.Idle, nil
}

0 comments on commit 0fa98da

Please sign in to comment.