// Create and initialize a state object. func CreateState(messageRouter common.MessageRouter) (s *State, err error) { s = new(State) // check that we have a non-nil messageSender if messageRouter == nil { err = fmt.Errorf("Cannot initialize with a nil messageRouter") return } // create a signature keypair for this state pubKey, secKey, err := crypto.CreateKeyPair() if err != nil { return } // calculate the value of an empty hash (default for storedEntropyStage2 on all hosts is a blank array) emptyHash, err := crypto.CalculateTruncatedHash(s.storedEntropyStage2[:]) if err != nil { return } // set state variables to their defaults s.messageRouter = messageRouter s.self = new(participant) s.self.address = messageRouter.AddMessageHandler(s) s.self.publicKey = pubKey s.secretKey = secKey for i := range s.previousEntropyStage1 { s.previousEntropyStage1[i] = emptyHash } s.participantIndex = 255 s.currentStep = 1 s.wallets = make(map[string]uint64) return }