func cliConvertPrivValidatorToErisKey(cmd *cobra.Command, args []string) { cmd.ParseFlags(args) if len(args) == 0 { exit(fmt.Errorf("Please enter the path to the priv_validator.json")) } pvf := args[0] b, err := ioutil.ReadFile(pvf) ifExit(err) pv := new(PrivValidator) wire.ReadJSON(pv, b, &err) ifExit(err) keyStore := crypto.NewKeyStorePlain(DefaultKeyStore) key := &crypto.Key{ Id: uuid.NewRandom(), Type: crypto.KeyType{crypto.CurveTypeEd25519, crypto.AddrTypeRipemd160}, Address: pv.Address, PrivateKey: pv.PrivKey[:], } fmt.Printf("%X\n", key.Address) ifExit(keyStore.StoreKey(key, "")) }
func unmarshalCheckResponse(body []byte) (response *ctypes.Response, err error) { response = new(ctypes.Response) wire.ReadJSON(response, body, &err) if err != nil { return nil, err } if response.Error != "" { return nil, fmt.Errorf(response.Error) } return response, nil }
func LoadPrivValidator(filePath string) *PrivValidator { privValJSONBytes, err := ioutil.ReadFile(filePath) if err != nil { Exit(err.Error()) } privVal := wire.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator) if err != nil { Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err)) } privVal.filePath = filePath return privVal }
// restore state from json blob // set tendermint config before calling func CoreRestore(chainID string, jsonBytes []byte) { var stJ State var err error wire.ReadJSON(&stJ, jsonBytes, &err) IfExit(err) st := new(sm.State) st.ChainID = chainID st.BondedValidators = stJ.BondedValidators st.LastBondedValidators = stJ.LastBondedValidators st.UnbondingValidators = stJ.UnbondingValidators stateDB := dbm.GetDB("state") // fill the accounts tree accounts := merkle.NewIAVLTree(wire.BasicCodec, acm.AccountCodec, 1000, stateDB) for _, account := range stJ.Accounts { accounts.Set(account.Address, account.Copy()) } // fill the storage tree for each contract for _, accStorage := range stJ.AccountsStorage { st := merkle.NewIAVLTree(wire.BasicCodec, wire.BasicCodec, 1024, stateDB) for _, accSt := range accStorage.Storage { set := st.Set(accSt.Key, accSt.Value) if !set { panic("failed to update storage tree") } } // TODO: sanity check vs acc.StorageRoot st.Save() } valInfos := merkle.NewIAVLTree(wire.BasicCodec, types.ValidatorInfoCodec, 0, stateDB) for _, valInfo := range stJ.ValidatorInfos { valInfos.Set(valInfo.Address, valInfo) } nameReg := merkle.NewIAVLTree(wire.BasicCodec, sm.NameRegCodec, 0, stateDB) for _, entry := range stJ.NameReg { nameReg.Set(entry.Name, entry) } // persists accounts/valInfos/nameReg trees st.SetAccounts(accounts) st.SetValidatorInfos(valInfos) st.SetNameReg(nameReg) st.SetDB(stateDB) st.Save() }
// genesis file with only one validator, using priv_validator.json func genesisFromPrivValBytes(chainID string, privJSON []byte) *stypes.GenesisDoc { var err error privVal := wire.ReadJSON(&types.PrivValidator{}, privJSON, &err).(*types.PrivValidator) if err != nil { Exit(fmt.Errorf("Error reading PrivValidator on stdin: %v\n", err)) } pubKey := privVal.PubKey amt := int64(1) << 50 genDoc := newGenDoc(chainID, 1, 1) genDocAddAccountAndValidator(genDoc, pubKey, amt, "", ptypes.DefaultPermFlags, ptypes.DefaultPermFlags, 0) return genDoc }
func coreConvertPrivValidatorToErisKey(b []byte) (key *kstore.Key, err error) { pv := new(PrivValidator) wire.ReadJSON(pv, b, &err) if err != nil { return nil, err } keyStore := kstore.NewKeyStorePlain(DefaultKeyStore) key = &kstore.Key{ Id: uuid.NewRandom(), Type: kstore.KeyType{kstore.CurveTypeEd25519, kstore.AddrTypeRipemd160}, Address: pv.Address, PrivateKey: pv.PrivKey[:], } err = keyStore.StoreKey(key, "") return key, err }
func (wsc *WSClient) receiveEventsRoutine() { for { _, data, err := wsc.ReadMessage() if err != nil { log.Info("WSClient failed to read message", "error", err, "data", string(data)) wsc.Stop() break } else { var response ctypes.Response wire.ReadJSON(&response, data, &err) if err != nil { log.Info("WSClient failed to parse message", "error", err) wsc.Stop() break } if strings.HasSuffix(response.ID, "#event") { wsc.EventsCh <- *response.Result.(*ctypes.ResultEvent) } else { wsc.ResultsCh <- response.Result } } } }