Beispiel #1
0
func LookupAddress(adrType string, adr string) (string, error) {
	if Utility.IsValidAddress(adr) && strings.HasPrefix(adr, adrType) {
		baddr := fct.ConvertUserStrToAddress(adr)
		adr = hex.EncodeToString(baddr)
	} else if Utility.IsValidHexAddress(adr) {
		// the address is good enough.
	} else if Utility.IsValidNickname(adr) {
		we := factoidState.GetDB().GetRaw([]byte(fct.W_NAME), []byte(adr))

		if we != nil {
			we2 := we.(wallet.IWalletEntry)

			if we2.GetType() == "ec" {
				if strings.ToLower(adrType) == "fct" {
					return "", fmt.Errorf("%s is an entry credit address, not a factoid address.", adr)
				}
			} else if we2.GetType() == "fct" {
				if strings.ToLower(adrType) == "ec" {
					return "", fmt.Errorf("%s is a factoid address, not an entry credit address.", adr)
				}
			}

			addr, _ := we2.GetAddress()
			adr = hex.EncodeToString(addr.Bytes())
		} else {
			return "", fmt.Errorf("Name %s is undefined.", adr)
		}
	} else {
		return "", fmt.Errorf("Invalid Name.  Check that you have entered the name correctly.")
	}

	return adr, nil
}
Beispiel #2
0
func CommitChain(name string, data []byte) error {
	type walletcommit struct {
		Message string
	}

	type commit struct {
		CommitChainMsg string
	}

	in := new(walletcommit)
	json.Unmarshal(data, in)
	msg, err := hex.DecodeString(in.Message)
	if err != nil {
		return fmt.Errorf("Could not decode message:", err)
	}

	var we fct.IBlock

	if Utility.IsValidAddress(name) && strings.HasPrefix(name, "EC") {
		addr := fct.ConvertUserStrToAddress(name)
		we = factoidState.GetDB().GetRaw([]byte(fct.W_ADDRESS_PUB_KEY), addr)
	} else if Utility.IsValidHexAddress(name) {
		addr, err := hex.DecodeString(name)
		if err == nil {
			we = factoidState.GetDB().GetRaw([]byte(fct.W_ADDRESS_PUB_KEY), addr)
		}
	} else {
		we = factoidState.GetDB().GetRaw([]byte(fct.W_NAME), []byte(name))
	}

	if we == nil {
		return fmt.Errorf("Unknown address")
	}

	signed := make([]byte, 0)
	switch we.(type) {
	case wallet.IWalletEntry:
		signed = factoidState.GetWallet().SignCommit(we.(wallet.IWalletEntry), msg)
	default:
		return fmt.Errorf("Cannot use non Entry Credit Address for Chain Commit")
	}

	com := new(commit)
	com.CommitChainMsg = hex.EncodeToString(signed)
	j, err := json.Marshal(com)
	if err != nil {
		return fmt.Errorf("Could not create json post:", err)
	}

	resp, err := http.Post(
		fmt.Sprintf("http://%s:%d/v1/commit-chain", ipaddressFD, portNumberFD),
		"application/json",
		bytes.NewBuffer(j))
	if err != nil {
		return fmt.Errorf("Could not post to server:", err)
	}
	resp.Body.Close()

	return nil
}
Beispiel #3
0
func ecbalance(addr string) error {
	if Utility.IsValidAddress(addr) && strings.HasPrefix(addr, "FA") {
		fmt.Println("Not a valid Entry Credit Address")
		return fmt.Errorf("Not a valid Entry Credit Address")
	}
	if b, err := factom.ECBalance(addr); err != nil {
		fmt.Println("Address undefined or invalid")
		return err
	} else {
		fmt.Println("Balance of ", addr, " = ", b)
	}

	return nil
}
Beispiel #4
0
func fctbalance(addr string) error {
	if Utility.IsValidAddress(addr) && strings.HasPrefix(addr, "EC") {
		fmt.Println("Not a valid Entry Credit Address")
		return fmt.Errorf("Not a valid Entry Credit Address")
	}

	if b, err := factom.FctBalance(addr); err != nil {
		fmt.Println("Address undefined or invalid: " + err.Error())
		return err
	} else {
		fmt.Println("Balance of ", addr, " = ", fct.ConvertDecimal(uint64(b)))
	}

	return nil
}