mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
fix(rest-api): handle JSON array in chaincode arguments
Signed-off-by: SurbhiAgarwal1 <agarwalsurbhi1807@gmail.com>
This commit is contained in:
parent
bf7e75c6c1
commit
e4e7122a5f
1 changed files with 17 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
|
@ -18,6 +19,22 @@ func (setup *OrgSetup) Invoke(w http.ResponseWriter, r *http.Request) {
|
||||||
channelID := r.FormValue("channelid")
|
channelID := r.FormValue("channelid")
|
||||||
function := r.FormValue("function")
|
function := r.FormValue("function")
|
||||||
args := r.Form["args"]
|
args := r.Form["args"]
|
||||||
|
|
||||||
|
if len(args) == 1 {
|
||||||
|
var parsed []string
|
||||||
|
err := json.Unmarshal([]byte(args[0]), &parsed)
|
||||||
|
if err == nil {
|
||||||
|
args = parsed
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Warning: failed to parse args as JSON: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
fmt.Fprintf(w, "Error: args is empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("channel: %s, chaincode: %s, function: %s, args: %s\n", channelID, chainCodeName, function, args)
|
fmt.Printf("channel: %s, chaincode: %s, function: %s, args: %s\n", channelID, chainCodeName, function, args)
|
||||||
network := setup.Gateway.GetNetwork(channelID)
|
network := setup.Gateway.GetNetwork(channelID)
|
||||||
contract := network.GetContract(chainCodeName)
|
contract := network.GetContract(chainCodeName)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue