WIP: fsm in client

This commit is contained in:
programmer10110 2020-08-07 19:07:29 +03:00
parent 80b03b2572
commit 96e32dbe38
1 changed files with 12 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
dkgFSM "github.com/depools/dc4bc/fsm/state_machines/dkg_proposal_fsm"
"go.dedis.ch/kyber/v3"
"log"
"path/filepath"
@ -87,14 +88,22 @@ func (c *Client) Poll() {
var operation *Operation
if resp.IsOpRequired {
switch resp.State {
// if the new state is waiting for RPC to airgapped machine
case dkgFSM.StateDkgPubKeysSendingRequired, dkgFSM.StateDkgCommitsSendingRequired,
dkgFSM.StateDkgDealsSendingRequired:
bz, err := json.Marshal(resp.Data)
if err != nil {
panic(err)
}
operation = &Operation{
Type: OperationType(resp.State),
Payload: resp.Data, // TODO:marshall
Payload: bz,
}
default:
panic("not good state") // what should we do exactly?
}
// I.e., if FSM returned an Operation for us.
if operation != nil {
if err := c.state.PutOperation(operation); err != nil {
panic(err)