コード例 #1
0
// Generates a new validator with private key.
func GenPrivValidator() *PrivValidator {
	privKeyBytes := new([64]byte)
	copy(privKeyBytes[:32], CRandBytes(32))
	pubKeyBytes := ed25519.MakePublicKey(privKeyBytes)
	pubKey := acm.PubKeyEd25519(*pubKeyBytes)
	privKey := acm.PrivKeyEd25519(*privKeyBytes)
	return &PrivValidator{
		Address:    pubKey.Address(),
		PubKey:     pubKey,
		PrivKey:    privKey,
		LastHeight: 0,
		LastRound:  0,
		LastStep:   stepNone,
		filePath:   "",
	}
}
コード例 #2
0
func checkCommon(nodeAddr, pubkey, addr, amtS, nonceS string) (pub account.PubKey, addrBytes []byte, amt int64, nonce int64, err error) {
	if amtS == "" {
		err = fmt.Errorf("input must specify an amount with the --amt flag")
		return
	}

	if pubkey == "" && addr == "" {
		err = fmt.Errorf("at least one of --pubkey or --addr must be given")
		return
	}

	pubKeyBytes, err := hex.DecodeString(pubkey)
	if err != nil {
		err = fmt.Errorf("pubkey is bad hex: %v", err)
		return
	}

	addrBytes, err = hex.DecodeString(addr)
	if err != nil {
		err = fmt.Errorf("addr is bad hex: %v", err)
		return
	}

	amt, err = strconv.ParseInt(amtS, 10, 64)
	if err != nil {
		err = fmt.Errorf("amt is misformatted: %v", err)
	}

	if len(pubKeyBytes) > 0 {
		var pubArray [32]byte
		copy(pubArray[:], pubKeyBytes)
		pub = account.PubKeyEd25519(pubArray)
		addrBytes = pub.Address()
	}

	if nonceS == "" {
		if nodeAddr == "" {
			err = fmt.Errorf("input must specify a nonce with the --nonce flag or use --node-addr (or MINTX_NODE_ADDR) to fetch the nonce from a node")
			return
		}

		// fetch nonce from node
		client := cclient.NewClient(nodeAddr, "HTTP")
		ac, err2 := client.GetAccount(addrBytes)
		if err2 != nil {
			err = fmt.Errorf("Error connecting to node (%s) to fetch nonce: %s", nodeAddr, err2.Error())
			return
		}
		if ac == nil || ac.Account == nil {
			err = fmt.Errorf("unknown account %X", addrBytes)
			return
		}
		nonce = int64(ac.Account.Sequence) + 1
	} else {
		nonce, err = strconv.ParseInt(nonceS, 10, 64)
		if err != nil {
			err = fmt.Errorf("nonce is misformatted: %v", err)
			return
		}
	}

	return
}
コード例 #3
0
func randPubKey() account.PubKeyEd25519 {
	var pubKey [32]byte
	copy(pubKey[:], RandBytes(32))
	return account.PubKeyEd25519(pubKey)
}