func()

in chaincode/src/forex/forex.go [53:78]


func (s *ForexChaincode) createUpdateForexPair(stub shim.ChaincodeStubInterface, args []string) sc.Response {

	if len(args) != 3 {
		return shim.Error("Expecting 3 arguments, base currency, counter currency , rate")
	}

	baseCurrency := args[0]
	counterCurrency := args[1]
	rate, err := strconv.ParseFloat(args[2], 64)
	pair := baseCurrency + ":" + counterCurrency

	if err != nil {
		return shim.Error("Unable to parse rate from arg[2]")
	}

	forexPair := forex{Pair: pair, Rate: rate}
	asBytes, _ := json.Marshal(forexPair)
	err = stub.PutState(pair, asBytes)

	if err != nil {
		return shim.Error("Unable to commit pair to ledger")

	}

	return shim.Success(nil)
}