Ejemplo n.º 1
0
func cliConvertErisKeyToPrivValidator(cmd *cobra.Command, args []string) {
	cmd.ParseFlags(args)
	if len(args) == 0 {
		exit(fmt.Errorf("Please enter the address of your key"))
	}

	addr := args[0]
	addrBytes, err := hex.DecodeString(addr)
	ifExit(err)

	keyStore := crypto.NewKeyStorePlain(DefaultKeyStore)
	key, err := keyStore.GetKey(addrBytes, "")
	ifExit(err)

	pub, err := key.Pubkey()
	ifExit(err)

	var pubKey account.PubKeyEd25519
	copy(pubKey[:], pub)

	var privKey account.PrivKeyEd25519
	copy(privKey[:], key.PrivateKey)

	privVal := PrivValidator{
		Address: addrBytes,
		PubKey:  pubKey,
		PrivKey: privKey,
	}

	fmt.Println(string(wire.JSONBytes(privVal)))
}
Ejemplo n.º 2
0
func prettyPrint(o interface{}) (string, error) {
	var prettyJSON bytes.Buffer
	err := json.Indent(&prettyJSON, wire.JSONBytes(o), "", "\t")
	if err != nil {
		return "", err
	}
	return string(prettyJSON.Bytes()), nil
}
Ejemplo n.º 3
0
func (c *ClientJSON) RequestResponse(s rpctypes.RPCRequest) (b []byte, err error) {
	b = wire.JSONBytes(s)
	buf := bytes.NewBuffer(b)
	resp, err := http.Post(c.addr, "text/json", buf)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	return ioutil.ReadAll(resp.Body)
}
Ejemplo n.º 4
0
func (privVal *PrivValidator) save() {
	if privVal.filePath == "" {
		PanicSanity("Cannot save PrivValidator: filePath not set")
	}
	jsonBytes := wire.JSONBytes(privVal)
	err := WriteFileAtomic(privVal.filePath, jsonBytes)
	if err != nil {
		// `@; BOOM!!!
		PanicCrisis(err)
	}
}
Ejemplo n.º 5
0
func TestErisToMint(t *testing.T) {
	keyPath := path.Join(DefaultKeyStore, addr)
	if err := os.MkdirAll(keyPath, 0700); err != nil {
		t.Fatal(err)
	}
	if err := ioutil.WriteFile(path.Join(keyPath, addr), []byte(erisKey), 0600); err != nil {
		t.Fatal(err)
	}

	addrBytes, _ := hex.DecodeString(addr)

	pv, err := coreConvertErisKeyToPrivValidator(addrBytes)
	if err != nil {
		t.Fatal(err)
	}

	if string(wire.JSONBytes(pv)) != mintKey {
		t.Fatalf("got \n%s \n\n expected \n %s\n", string(wire.JSONBytes(pv)), mintKey)
	}

	os.RemoveAll(DefaultKeyStore)
}
Ejemplo n.º 6
0
func cliConvertErisKeyToPrivValidator(cmd *cobra.Command, args []string) {
	cmd.ParseFlags(args)
	if len(args) == 0 {
		exit(fmt.Errorf("Please enter the address of your key"))
	}

	addr := args[0]
	addrBytes, err := hex.DecodeString(addr)
	ifExit(err)

	privVal, err := coreConvertErisKeyToPrivValidator(addrBytes)
	ifExit(err)

	fmt.Println(string(wire.JSONBytes(privVal)))
}
Ejemplo n.º 7
0
func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
	wire.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err)
	wire.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
	for i, in := range tx.Inputs {
		in.WriteSignBytes(w, n, err)
		if i != len(tx.Inputs)-1 {
			wire.WriteTo([]byte(","), w, n, err)
		}
	}
	wire.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err)
	wire.WriteTo(wire.JSONBytes(tx.PubKey), w, n, err)
	wire.WriteTo([]byte(`,"unbond_to":[`), w, n, err)
	for i, out := range tx.UnbondTo {
		out.WriteSignBytes(w, n, err)
		if i != len(tx.UnbondTo)-1 {
			wire.WriteTo([]byte(","), w, n, err)
		}
	}
	wire.WriteTo([]byte(`]}]}`), w, n, err)
}