Beispiel #1
0
func HandleFactoidSetup(ctx *web.Context, seed string) {
	// Make sure we have a seed.
	if len(seed) == 0 {
		msg := "You must supply some random seed. For example (don't use this!)\n" +
			"factom-cli setup 'woe!#in31!%234ng)%^&$%oeg%^&*^jp45694a;gmr@#t4 q34y'\n" +
			"would make a nice seed.  The more random the better.\n\n" +
			"Note that if you create an address before you call Setup, you must\n" +
			"use those address(s) as you access the fountians."

		reportResults(ctx, msg, false)
	}
	setFountian := false
	keys, _ := Wallet.GetWalletNames()
	if len(keys) == 0 {
		setFountian = true
		for i := 1; i <= 10; i++ {
			name := fmt.Sprintf("%02d-Fountain", i)
			_, err := Wallet.GenerateFctAddress([]byte(name), 1, 1)
			if err != nil {
				reportResults(ctx, err.Error(), false)
				return
			}
		}
	}

	seedprime := fct.Sha([]byte(fmt.Sprintf("%s%v", seed, time.Now().UnixNano()))).Bytes()
	Wallet.NewSeed(seedprime)

	if setFountian {
		reportResults(ctx, "New seed set, fountain addresses defined", true)
	} else {
		reportResults(ctx, "New seed set, no fountain addresses defined", true)
	}
}
Beispiel #2
0
func initWallet() {
	fmt.Printf("\ninitWallet\n")
	keys, _ := Wallet.GetWalletNames()
	if len(keys) == 0 {
		for i := 1; i <= 10; i++ {
			name := fmt.Sprintf("%02d-Fountain", i)
			_, err := Wallet.GenerateFctAddress([]byte(name), 1, 1)
			if err != nil {
				fmt.Printf("\nError - %v\n", err)
				return
			}
		}
	}
	fmt.Printf("initWallet done\n")
}
Beispiel #3
0
// Specifying a fee overrides either not being connected, or the current fee.
// Params:
//   key (limit printout to this key)
//   fee (specify the transation fee)
func GetTransactions(ctx *web.Context) ([]byte, error) {
	connected := true

	var _ = connected

	exch, err := GetFee(ctx) // The Fee will be zero if we have no connection.
	if err != nil {
		connected = false
	}

	keys, transactions, err := Wallet.GetTransactions()
	if err != nil {
		return nil, err
	}

	var out bytes.Buffer
	for i, trans := range transactions {

		fee, _ := trans.CalculateFee(uint64(exch))
		cprt := ""
		cin, err := trans.TotalInputs()
		if err != nil {
			cprt = cprt + err.Error()
		}
		cout, err := trans.TotalOutputs()
		if err != nil {
			cprt = cprt + err.Error()
		}
		cecout, err := trans.TotalECs()
		if err != nil {
			cprt = cprt + err.Error()
		}

		if len(cprt) == 0 {
			v := int64(cin) - int64(cout) - int64(cecout)
			sign := ""
			if v < 0 {
				sign = "-"
				v = -v
			}
			cprt = fmt.Sprintf(" Currently will pay: %s%s",
				sign,
				strings.TrimSpace(fct.ConvertDecimal(uint64(v))))
			if sign == "-" || fee > uint64(v) {
				cprt = cprt + "\n\nWARNING: Currently your transaction fee may be too low"
			}
		}

		out.WriteString(fmt.Sprintf("%s:  Fee Due: %s  %s\n\n%s\n",
			strings.TrimSpace(strings.TrimRight(string(keys[i]), "\u0000")),
			strings.TrimSpace(fct.ConvertDecimal(fee)),
			cprt,
			transactions[i].String()))
	}

	output := out.Bytes()
	// now look for the addresses, and replace them with our names. (the transactions
	// in flight also have a Factom address... We leave those alone.

	names, vs := Wallet.GetWalletNames()

	for i, name := range names {
		we, ok := vs[i].(wallet.IWalletEntry)
		if !ok {
			return nil, fmt.Errorf("Database is corrupt")
		}

		address, err := we.GetAddress()
		if err != nil {
			continue
		} // We shouldn't get any of these, but ignore them if we do.
		adrstr := []byte(hex.EncodeToString(address.Bytes()))

		output = bytes.Replace(output, adrstr, name, -1)
	}

	return output, nil
}