示例#1
0
文件: cli.go 项目: alist/mint-client
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, ""))
}
示例#2
0
文件: cli.go 项目: alist/mint-client
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)))
}
示例#3
0
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)

	key, err := coreConvertPrivValidatorToErisKey(b)
	ifExit(err)

	fmt.Printf("%X\n", key.Address)
}
示例#4
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)))
}
示例#5
0
func cliIntsToStrings(cmd *cobra.Command, args []string) {
	cmd.ParseFlags(args)
	if len(args) != 2 {
		Exit(fmt.Errorf("Please enter PermFlag and SetBit integers"))
	}

	pf, sb := args[0], args[1]
	perms, err := strconv.Atoi(pf)
	IfExit(err)
	setbits, err := strconv.Atoi(sb)
	IfExit(err)

	m := coreIntsToStrings(types.PermFlag(perms), types.PermFlag(setbits))
	printStringPerms(m)
}
示例#6
0
func cliStringsToInts(cmd *cobra.Command, args []string) {
	cmd.ParseFlags(args)
	if len(args) == 0 {
		Exit(fmt.Errorf("Please enter at least one `<permission>:<value>` pair like `send:0 call:1 create_account:1`"))
	}

	bp := types.ZeroBasePermissions

	for _, a := range args {
		spl := strings.Split(a, ":")
		if len(spl) != 2 {
			Exit(fmt.Errorf("arguments must be like `send:1`, not %s", a))
		}
		name, v := spl[0], spl[1]
		vi := v[0] - '0'
		pf, err := types.PermStringToFlag(name)
		IfExit(err)
		bp.Set(pf, vi > 0)
	}
	printPerms(bp, BitmaskFlag)
}