func getCurrencyConversion()

in solution/transfer.go [156:179]


func getCurrencyConversion(stub shim.ChaincodeStubInterface, forexContract string, baseCurrency string, counterCurrency string) (float64, error) {

	if forexContract == "" {
		return 0.0, errors.New("Forex contract is empty, unable to complete transaction")
	}

	// invoke the forex contract to get the exchange rate for the pair
	stringArgs := []string{"getForexPair", baseCurrency, counterCurrency}
	args := util.ArrayToChaincodeArgs(stringArgs)
	response := stub.InvokeChaincode(forexContract, args, "")

	if response.Status != shim.OK {
		return 0.0, errors.New("Unable to get exchange rate from Forex Contract" + response.Message)
	}

	responseForex := &forexPair{}
	err := json.Unmarshal(response.GetPayload(), responseForex)

	if err != nil {
		return 0.0, errors.New("Unable to unmarshal exchange rate from Forex Contract" + err.Error())
	}

	return responseForex.Rate, nil
}