// Generates a new Address
func GenerateAddress(addressType, addressName string) error {
	var err error
	var Addr string
	switch addressType {
	case "ec":
		Addr, err = factom.GenerateEntryCreditAddress(addressName)
	case "factoid":
		Addr, err = factom.GenerateFactoidAddress(addressName)
	default:
		panic("Expected ec|factoid name")
	}

	if err != nil {
		fmt.Println(err)
		return err
	}

	fmt.Println(addressType, " = ", Addr)
	return nil
}
Exemple #2
0
// Generates a new Address
func generateaddress(args []string) {

	os.Args = args
	flag.Parse()
	args = flag.Args()
	if len(args) < 2 {
		man("generatefactoidaddress")
		os.Exit(1)
	}

	msg, valid := ValidateKey(args[1])
	if !valid {
		fmt.Println(msg)
		os.Exit(1)
	}

	var err error
	var Addr string
	if len(args) == 2 {
		switch args[0] {
		case "ec":
			Addr, err = factom.GenerateEntryCreditAddress(args[1])
		case "fct":
			Addr, err = factom.GenerateFactoidAddress(args[1])
		default:
			panic("Expected ec|fct name")
		}
	} else {
		switch args[0] {
		case "ec":
			Addr, err = factom.GenerateEntryCreditAddressFromHumanReadablePrivateKey(args[1], args[2])
			if err == nil {
				break
			}
			Addr, err = factom.GenerateEntryCreditAddressFromPrivateKey(args[1], args[2])
			if err == nil {
				break
			}
		case "fct":
			Addr, err = factom.GenerateFactoidAddressFromHumanReadablePrivateKey(args[1], args[2])
			if err == nil {
				break
			}
			if strings.Contains(err.Error(), "unexpected end of JSON input") == false {
				break
			}
			Addr, err = factom.GenerateFactoidAddressFromMnemonic(args[1], args[2])
			if err == nil {
				break
			}
			if strings.Contains(err.Error(), "unexpected end of JSON input") == false {
				break
			}
			Addr, err = factom.GenerateFactoidAddressFromPrivateKey(args[1], args[2])
			if err == nil {
				break
			}
			if strings.Contains(err.Error(), "unexpected end of JSON input") == false {
				break
			}
		default:
			panic("Expected ec|fct name")
		}
	}

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(args[0], " = ", Addr)
	return

}