// New Transaction:  key --
// We create a new transaction, and track it with the user supplied key.  The
// user can then use this key to make subsequent calls to add inputs, outputs,
// and to sign. Then they can submit the transaction.
//
// When the transaction is submitted, we clear it from our working memory.
// Multiple transactions can be under construction at one time, but they need
// their own keys. Once a transaction is either submitted or deleted, the key
// can be reused.
func (AddressFromWords) Execute(state IState, args []string) error {

	if len(args) != 14 {
		return fmt.Errorf("Invalid Parameters")
	}
	name := args[1]

	na := state.GetFS().GetDB().GetRaw([]byte(fct.W_NAME), []byte(name))
	if na != nil {
		return fmt.Errorf("The name %s is already in use.  Names must be unique.", name)
	}

	var mnstr string
	for i := 2; i < 14; i++ {
		if len(args[i]) == 0 {
			return fmt.Errorf("Invalid mnemonic; the %d word has issues", i+1)
		}
		mnstr = mnstr + args[i] + " "
	}

	privateKey, err := wallet.MnemonicStringToPrivateKey(mnstr)
	if err != nil {
		return err
	}

	var fixed [64]byte
	copy(fixed[:], privateKey)
	publicKey := ed25519.GetPublicKey(&fixed)

	state.GetFS().GetWallet().AddKeyPair("fct", []byte(name), publicKey[:], fixed[:], false)

	return nil

}
Exemple #2
0
func main() {

	r := bufio.NewScanner(os.Stdin)

	fmt.Print("Enter 12 words from Koinify here: ")
	r.Scan()
	line := r.Text()
	args := strings.Fields(string(line))

	if len(args) == 12 {

		mnemonic := ""
		for _, v := range args {
			v = strings.ToLower(v)
			mnemonic = mnemonic + v + " "
		}
		mnemonic = strings.TrimSpace(mnemonic)
		private, err := wallet.MnemonicStringToPrivateKey(mnemonic)
		if err != nil {
			fmt.Print("\n\nThere was a problem with the 12 words you entered. Please check spelling against this list:\n")
			fmt.Print("https://github.com/FactomProject/go-bip39/blob/master/wordlist.go\n\n\n\n")
			panic(err)
		}
		pub, priv, err := wallet.GenerateKeyFromPrivateKey(private)
		if err != nil {
			panic(err)
		}

		we := new(wallet.WalletEntry)
		we.AddKey(pub, priv)
		we.SetName([]byte("test"))
		we.SetRCD(factoid.NewRCD_1(pub))
		we.SetType("fct")

		address, _ := we.GetAddress()

		adr := factoid.ConvertFctAddressToUserStr(address)

		fmt.Printf("\nFactoid Address: %v\n", adr)
		fmt.Printf("\nCheck your balance at http://explorer.factom.org/\n")
	} else {
		fmt.Printf("\n\nError: 12 and only 12 words are expected.\n")
	}

}