modify update err

parent 5e4cc8af
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go"> <entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="141"> <state relative-caret-position="407">
<caret line="72" selection-start-line="72" selection-end-line="72" /> <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> </state>
</provider> </provider>
</entry> </entry>
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go"> <entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="271"> <state relative-caret-position="1278">
<caret line="57" column="17" lean-forward="true" selection-start-line="57" selection-start-column="17" selection-end-line="57" selection-end-column="17" /> <caret line="76" column="80" selection-start-line="76" selection-start-column="80" selection-end-line="76" selection-end-column="80" />
</state> </state>
</provider> </provider>
</entry> </entry>
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
<list> <list>
<option value="$PROJECT_DIR$/gongxianghui/schema.go" /> <option value="$PROJECT_DIR$/gongxianghui/schema.go" />
<option value="$PROJECT_DIR$/gongxianghui/deposit.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_test.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui.go" />
</list> </list>
</option> </option>
</component> </component>
...@@ -131,15 +131,6 @@ ...@@ -131,15 +131,6 @@
</recent_temporary> </recent_temporary>
</component> </component>
<component name="TestHistory"> <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"> <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" /> <configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
...@@ -161,6 +152,15 @@ ...@@ -161,6 +152,15 @@
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 55m 01s.xml"> <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" /> <configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry> </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>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="67" y="25" width="1853" height="925" extended-state="6" /> <frame x="67" y="25" width="1853" height="925" extended-state="6" />
...@@ -192,18 +192,6 @@ ...@@ -192,18 +192,6 @@
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" /> <option name="version" value="1" />
</component> </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"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/gongxianghui/schema.go"> <entry file="file://$PROJECT_DIR$/gongxianghui/schema.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
...@@ -217,15 +205,15 @@ ...@@ -217,15 +205,15 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go"> <entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="141"> <state relative-caret-position="407">
<caret line="72" selection-start-line="72" selection-end-line="72" /> <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> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go"> <entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="271"> <state relative-caret-position="1278">
<caret line="57" column="17" lean-forward="true" selection-start-line="57" selection-start-column="17" selection-end-line="57" selection-end-column="17" /> <caret line="76" column="80" selection-start-line="76" selection-start-column="80" selection-end-line="76" selection-end-column="80" />
</state> </state>
</provider> </provider>
</entry> </entry>
......
...@@ -45,13 +45,13 @@ func (t *GXHCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response { ...@@ -45,13 +45,13 @@ func (t *GXHCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
case "get": case "get":
res,err := get(args,stub) res,err := get(args,stub)
if err!=nil{ 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)) return shim.Success([]byte(res))
case "update": case "update":
res,err := update(args,stub) res,err := update(args,stub)
if err!=nil{ 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)) return shim.Success([]byte(res))
...@@ -74,7 +74,7 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -74,7 +74,7 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) < 2 { if len(args) < 2 {
return "", fmt.Errorf("Expected more than 2 parameters to function put!") 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{} var schemaMap map[string]interface{}
schema := &Schema{} schema := &Schema{}
result, err := schema.get(args[0], stub) result, err := schema.get(args[0], stub)
...@@ -83,11 +83,11 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -83,11 +83,11 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
} }
json.Unmarshal([]byte(result),&schemaMap) 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) return "", fmt.Errorf("parameters Unmarshal fail,args string not json string, err:%s", err)
} }
for k, v := range mapResult{ for k, mapres := range Result{
Id ,ok:= v["id"] Id ,ok:= mapres["id"]
if !ok{ if !ok{
return "", fmt.Errorf("The id field must exist ") return "", fmt.Errorf("The id field must exist ")
} }
...@@ -96,10 +96,10 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -96,10 +96,10 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
}else if result!=nil{ }else if result!=nil{
return "", fmt.Errorf("%s data already exist", args[0]+Id.(string)) 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]) 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 { if err := stub.PutState(args[0]+Id.(string), putDate); err != nil {
return "", fmt.Errorf("PutState fail, err :%s", err) return "", fmt.Errorf("PutState fail, err :%s", err)
} }
...@@ -113,12 +113,12 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -113,12 +113,12 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
*/ */
func update(args []string, stub shim.ChaincodeStubInterface) (string, error) { func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 { 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 mapResult map[string]interface{}
var allMap map[string]interface{} var allMap map[string]interface{}
if err := json.Unmarshal([]byte(args[1]), &mapResult); err != nil { 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"] Id ,ok:= mapResult["id"]
...@@ -135,7 +135,7 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -135,7 +135,7 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if err := Deassign(mapResult, allMap); err != nil { if err := Deassign(mapResult, allMap); err != nil {
return "", err return "", err
} else { } else {
resultByte, _:= json.Marshal(mapResult) resultByte, _:= json.Marshal(allMap)
if err := stub.PutState(args[0]+Id.(string), resultByte);err!=nil{ if err := stub.PutState(args[0]+Id.(string), resultByte);err!=nil{
return "", fmt.Errorf("updateState date fail, err :%s ", err) return "", fmt.Errorf("updateState date fail, err :%s ", err)
} }
...@@ -146,11 +146,11 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -146,11 +146,11 @@ func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
func get(args []string, stub shim.ChaincodeStubInterface) (string, error) { func get(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 { 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{} var mapResult map[string]interface{}
if err := json.Unmarshal([]byte(args[1]), &mapResult); err != nil { 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"] 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