mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
* REST api added for asset transfer in Golang Signed-off-by: Basil K Y <techiebasil@gmail.com> * add go.sum to git Signed-off-by: Basil K Y <techiebasil@gmail.com> * fix golint error Signed-off-by: Basil K Y <techiebasil@gmail.com> Signed-off-by: Basil K Y <techiebasil@gmail.com>
25 lines
786 B
Go
25 lines
786 B
Go
package web
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// Query handles chaincode query requests.
|
|
func (setup OrgSetup) Query(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Println("Received Query request")
|
|
queryParams := r.URL.Query()
|
|
chainCodeName := queryParams.Get("chaincodeid")
|
|
channelID := queryParams.Get("channelid")
|
|
function := queryParams.Get("function")
|
|
args := r.URL.Query()["args"]
|
|
fmt.Printf("channel: %s, chaincode: %s, function: %s, args: %s\n", channelID, chainCodeName, function, args)
|
|
network := setup.Gateway.GetNetwork(channelID)
|
|
contract := network.GetContract(chainCodeName)
|
|
evaluateResponse, err := contract.EvaluateTransaction(function, args...)
|
|
if err != nil {
|
|
fmt.Fprintf(w, "Error: %s", err)
|
|
return
|
|
}
|
|
fmt.Fprintf(w, "Response: %s", evaluateResponse)
|
|
}
|