modify update err

parent 5e4cc8af
......@@ -16,8 +16,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="141">
<caret line="72" selection-start-line="72" selection-end-line="72" />
<state relative-caret-position="407">
<caret line="186" column="14" lean-forward="true" selection-start-line="186" selection-start-column="14" selection-end-line="186" selection-end-column="14" />
</state>
</provider>
</entry>
......@@ -25,8 +25,8 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="271">
<caret line="57" column="17" lean-forward="true" selection-start-line="57" selection-start-column="17" selection-end-line="57" selection-end-column="17" />
<state relative-caret-position="1278">
<caret line="76" column="80" selection-start-line="76" selection-start-column="80" selection-end-line="76" selection-end-column="80" />
</state>
</provider>
</entry>
......@@ -42,8 +42,8 @@
<list>
<option value="$PROJECT_DIR$/gongxianghui/schema.go" />
<option value="$PROJECT_DIR$/gongxianghui/deposit.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui_test.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui.go" />
</list>
</option>
</component>
......@@ -131,15 +131,6 @@
</recent_temporary>
</component>
<component name="TestHistory">
<history-entry file="TestGXHCC_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 10h 01m 08s.xml">
<configuration name="TestGXHCC in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 10h 03m 03s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 06m 50s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 08m 03s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
......@@ -161,6 +152,15 @@
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 55m 01s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 20h 01m 24s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 20h 01m 40s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 20h 03m 09s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
</component>
<component name="ToolWindowManager">
<frame x="67" y="25" width="1853" height="925" extended-state="6" />
......@@ -192,18 +192,6 @@
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/gongxianghui/gongxianghui.go</url>
<line>72</line>
<properties />
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/gongxianghui/schema.go">
<provider selected="true" editor-type-id="text-editor">
......@@ -217,15 +205,15 @@
</entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="141">
<caret line="72" selection-start-line="72" selection-end-line="72" />
<state relative-caret-position="407">
<caret line="186" column="14" lean-forward="true" selection-start-line="186" selection-start-column="14" selection-end-line="186" selection-end-column="14" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="271">
<caret line="57" column="17" lean-forward="true" selection-start-line="57" selection-start-column="17" selection-end-line="57" selection-end-column="17" />
<state relative-caret-position="1278">
<caret line="76" column="80" selection-start-line="76" selection-start-column="80" selection-end-line="76" selection-end-column="80" />
</state>
</provider>
</entry>
......
......@@ -45,13 +45,13 @@ func (t *GXHCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
case "get":
res,err := get(args,stub)
if err!=nil{
return shim.Error(fmt.Sprintf("put function err: %s", err))
return shim.Error(fmt.Sprintf("get function err: %s", err))
}
return shim.Success([]byte(res))
case "update":
res,err := update(args,stub)
if err!=nil{
return shim.Error(fmt.Sprintf("put function err: %s", err))
return shim.Error(fmt.Sprintf("update function err: %s", err))
}
return shim.Success([]byte(res))
......@@ -74,7 +74,7 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) < 2 {
return "", fmt.Errorf("Expected more than 2 parameters to function put!")
}
var mapResult []map[string]interface{}
var Result []map[string]interface{}
var schemaMap map[string]interface{}
schema := &Schema{}
result, err := schema.get(args[0], stub)
......@@ -83,11 +83,11 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
}
json.Unmarshal([]byte(result),&schemaMap)
if err := json.Unmarshal([]byte(args[1]), &mapResult); err != nil {
if err := json.Unmarshal([]byte(args[1]), &Result); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string, err:%s", err)
}
for k, v := range mapResult{
Id ,ok:= v["id"]
for k, mapres := range Result{
Id ,ok:= mapres["id"]
if !ok{
return "", fmt.Errorf("The id field must exist ")
}
......@@ -96,10 +96,10 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
}else if result!=nil{
return "", fmt.Errorf("%s data already exist", args[0]+Id.(string))
}
if !SchemaCheck(schemaMap,v){
if !SchemaCheck(schemaMap,mapres){
return "", fmt.Errorf("SchemaCheck fail,args index %d string doesn't match %s format", k,args[0])
}
putDate,_:=json.Marshal(mapResult)
putDate,_:=json.Marshal(mapres)
if err := stub.PutState(args[0]+Id.(string), putDate); err != nil {
return "", fmt.Errorf("PutState fail, err :%s", err)
}
......@@ -113,12 +113,12 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
*/
func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 {
return "", fmt.Errorf("Expected 2 parameters to function put! ")
return "", fmt.Errorf("Expected 2 parameters to function update! ")
}
var mapResult map[string]interface{}
var allMap map[string]interface{}
if err := json.Unmarshal([]byte(args[1]), &mapResult); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args index %d string not json string,err: ", err)
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
}
Id ,ok:= mapResult["id"]
......@@ -135,7 +135,7 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if err := Deassign(mapResult, allMap); err != nil {
return "", err
} else {
resultByte, _:= json.Marshal(mapResult)
resultByte, _:= json.Marshal(allMap)
if err := stub.PutState(args[0]+Id.(string), resultByte);err!=nil{
return "", fmt.Errorf("updateState date fail, err :%s ", err)
}
......@@ -146,11 +146,11 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
func get(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 {
return "", fmt.Errorf("Expected 2 parameters to function put!")
return "", fmt.Errorf("Expected 2 parameters to function get!")
}
var mapResult map[string]interface{}
if err := json.Unmarshal([]byte(args[1]), &mapResult); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args index string not json string,err: %s", err)
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
}
Id := mapResult["id"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment