Esempio n. 1
0
func VerifyAddressType(address string) (string, bool) {
	var resp string = "Not a Valid Factoid Address"
	var pass bool = false

	if strings.HasPrefix(address, "FA") {
		if factoid.ValidateFUserStr(address) {
			resp = "Factoid - Public"
			pass = true
		}
	} else if strings.HasPrefix(address, "EC") {
		if factoid.ValidateECUserStr(address) {
			resp = "Entry Credit - Public"
			pass = true
		}
	} else if strings.HasPrefix(address, "Fs") {
		if factoid.ValidateFPrivateUserStr(address) {
			resp = "Factoid - Private"
			pass = true
		}
	} else if strings.HasPrefix(address, "Es") {
		if factoid.ValidateECPrivateUserStr(address) {
			resp = "Entry Credit - Private"
			pass = true
		}
	}

	//  Add Netki resolution here
	//else if (checkNetki) {
	//	if (factoid.ValidateECPrivateUserStr(address)) {
	//		resp = "{\"AddressType\":\"Factoid - Public\", \"TypeCode\":4 ,\"Success\":true}"
	//	}
	//}

	return resp, pass
}
Esempio n. 2
0
func IsValidAddress(address string) bool {

	if !fct.ValidateFUserStr(address) && !fct.ValidateECUserStr(address) {
		return false
	}

	return true
}
Esempio n. 3
0
func (AddECOutput) Execute(state IState, args []string) error {

	if len(args) != 4 {
		return fmt.Errorf("Invalid Parameters")
	}
	key := args[1]
	adr := args[2]
	amt := args[3]

	ib := state.GetFS().GetDB().GetRaw([]byte(fct.DB_BUILD_TRANS), []byte(key))
	trans, ok := ib.(fct.ITransaction)
	if ib == nil || !ok {
		return fmt.Errorf("Unknown Transaction")
	}

	var addr fct.IAddress
	if !fct.ValidateECUserStr(adr) {
		if len(adr) != 64 {
			if len(adr) > 32 {
				return fmt.Errorf("Invalid Address or Name.  Check that you entered it correctly.")
			}

			we := state.GetFS().GetDB().GetRaw([]byte(fct.W_NAME), []byte(adr))

			if we != nil {
				we2 := we.(wallet.IWalletEntry)
				addr, _ = we2.GetAddress()
				adr = hex.EncodeToString(addr.Bytes())
			} else {
				return fmt.Errorf("Name is undefined.")
			}
		} else {
			if badHexChar.FindStringIndex(adr) != nil {
				return fmt.Errorf("Looks like an invalid hex address. Check that you entered it correctly.")
			}
		}
	} else {
		addr = fct.NewAddress(fct.ConvertUserStrToAddress(adr))
	}
	amount, _ := fct.ConvertFixedPoint(amt)
	bamount, _ := strconv.ParseInt(amount, 10, 64)
	err := state.GetFS().GetWallet().AddECOutput(trans, addr, uint64(bamount))
	if err != nil {
		return err
	}

	fmt.Println("Added Output of ", amt, " to be paid to ", args[2],
		fct.ConvertECAddressToUserStr(addr))

	return nil
}
Esempio n. 4
0
func SilentAddECOutput(txKey string, outputAddress string, outputSize string) error {
	ib := myState.GetFS().GetDB().GetRaw([]byte(fct.DB_BUILD_TRANS), []byte(txKey))
	trans, ok := ib.(fct.ITransaction)
	if ib == nil || !ok {
		return fmt.Errorf("Unknown Transaction")
	}

	var addr fct.IAddress
	if !fct.ValidateECUserStr(outputAddress) {
		if len(outputAddress) != 64 {
			if len(outputAddress) > 32 {
				return fmt.Errorf("Invalid Address or Name.  Check that you entered it correctly.")
			}

			we := myState.GetFS().GetDB().GetRaw([]byte(fct.W_NAME), []byte(outputAddress))

			if we != nil {
				we2 := we.(wallet.IWalletEntry)
				addr, _ = we2.GetAddress()
				outputAddress = hex.EncodeToString(addr.Bytes())
			} else {
				return fmt.Errorf("Name is undefined.")
			}
		} else {
			if badHexChar.FindStringIndex(outputAddress) != nil {
				return fmt.Errorf("Looks like an invalid hex address. Check that you entered it correctly.")
			}
		}
	} else {
		addr = fct.NewAddress(fct.ConvertUserStrToAddress(outputAddress))
	}
	amount, _ := fct.ConvertFixedPoint(outputSize)
	bamount, _ := strconv.ParseInt(amount, 10, 64)
	err := myState.GetFS().GetWallet().AddECOutput(trans, addr, uint64(bamount))
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 5
0
// &key=<key>&name=<name or address>&amount=<amount>
// If no amount is specified, a zero is returned.
func getParams_(ctx *web.Context, params string, ec bool) (
	trans fct.ITransaction,
	key string,
	name string,
	address fct.IAddress,
	amount int64,
	ok bool) {

	key = ctx.Params["key"]
	name = ctx.Params["name"]
	StrAmount := ctx.Params["amount"]

	if len(StrAmount) == 0 {
		StrAmount = "0"
	}

	if len(key) == 0 || len(name) == 0 {
		str := fmt.Sprintln("Missing Parameters: key='", key, "' name='", name, "' amount='", StrAmount, "'")
		reportResults(ctx, str, false)
		ok = false
		return
	}

	msg, valid := ValidateKey(key)
	if !valid {
		reportResults(ctx, msg, false)
		ok = false
		return
	}

	amount, err := strconv.ParseInt(StrAmount, 10, 64)
	if err != nil {
		str := fmt.Sprintln("Error parsing amount.\n", err)
		reportResults(ctx, str, false)
		ok = false
		return
	}

	// Get the transaction
	trans, err = getTransaction(ctx, key)
	if err != nil {
		reportResults(ctx, "Failure to locate the transaction", false)
		ok = false
		return
	}

	// Get the input/output/ec address.  Which could be a name.  First look and see if it is
	// a name.  If it isn't, then look and see if it is an address.  Someone could
	// do a weird Address as a name and fool the code, but that seems unlikely.
	// Could check for that some how, but there are many ways around such checks.

	if len(name) <= fct.ADDRESS_LENGTH {
		we := Wallet.GetRaw([]byte(fct.W_NAME), []byte(name))
		if we != nil {
			address, err = we.(wallet.IWalletEntry).GetAddress()
			if we.(wallet.IWalletEntry).GetType() == "ec" {
				if !ec {
					reportResults(ctx, "Was Expecting a Factoid Address", false)
					ok = false
					return
				}
			} else {
				if ec {
					reportResults(ctx, "Was Expecting an Entry Credit Address", false)
					ok = false
					return
				}
			}
			if err != nil || address == nil {
				reportResults(ctx, "Should not get an error geting a address from a Wallet Entry", false)
				ok = false
				return
			}
			ok = true
			return
		}
	}
	if (!ec && !fct.ValidateFUserStr(name)) || (ec && !fct.ValidateECUserStr(name)) {
		reportResults(ctx, fmt.Sprintf("The address specified isn't defined or is invalid: %s", name), false)
		ctx.WriteHeader(httpBad)
		ok = false
		return
	}
	baddr := fct.ConvertUserStrToAddress(name)

	address = fct.NewAddress(baddr)

	ok = true
	return
}