modify data put function

parent ec5a9afa
......@@ -3,9 +3,7 @@
<component name="ChangeListManager">
<list default="true" id="de83b181-e854-4be8-81f5-73a2fdb02762" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gongxianghui/deposit.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/gongxianghui/gongxianghui.go" beforeDir="false" afterPath="$PROJECT_DIR$/gongxianghui/gongxianghui.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gongxianghui/schema.go" beforeDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -15,19 +13,21 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<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="-3990">
<caret line="62" column="59" selection-start-line="62" selection-start-column="59" selection-end-line="62" selection-end-column="59" />
<state relative-caret-position="141">
<caret line="72" selection-start-line="72" selection-end-line="72" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<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="-522" />
<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>
</provider>
</entry>
</file>
......@@ -41,16 +41,17 @@
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/gongxianghui/schema.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui.go" />
<option value="$PROJECT_DIR$/gongxianghui/deposit.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui_test.go" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="1" />
<option name="y" value="25" />
<option name="width" value="639" />
<option name="height" value="455" />
<option name="x" value="120" />
<option name="y" value="27" />
<option name="width" value="1657" />
<option name="height" value="861" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
......@@ -130,25 +131,47 @@
</recent_temporary>
</component>
<component name="TestHistory">
<history-entry file="TestGXHCC_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.18 at 18h 01m 03s.xml">
<configuration name="TestGXHCC in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" />
</history-entry>
<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>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 09m 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 14h 09m 43s.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 45m 07s.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 48m 06s.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 48m 32s.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 55m 01s.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" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25595567" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.12908587" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.3308176" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.3308176" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
......@@ -157,7 +180,7 @@
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Statistic" order="10" />
<window_info active="true" anchor="bottom" id="Terminal" order="11" visible="true" weight="0.32955974" />
<window_info anchor="bottom" id="Terminal" order="11" weight="0.32955974" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
......@@ -169,6 +192,18 @@
<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">
......@@ -180,15 +215,17 @@
<entry file="file://$PROJECT_DIR$/gongxianghui/deposit.go">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go">
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-522" />
<state relative-caret-position="141">
<caret line="72" selection-start-line="72" selection-end-line="72" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go">
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-3990">
<caret line="62" column="59" selection-start-line="62" selection-start-column="59" selection-end-line="62" selection-end-column="59" />
<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>
</provider>
</entry>
......
......@@ -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 mapResult []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)
for k, v := range args[1:] {
if err := json.Unmarshal([]byte(v), &mapResult); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args index %d string not json string, err:%s", k, err)
}
Id ,ok:= mapResult["id"]
if err := json.Unmarshal([]byte(args[1]), &mapResult); 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"]
if !ok{
return "", fmt.Errorf("The id field must exist ")
}
......@@ -96,7 +96,7 @@ 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,mapResult){
if !SchemaCheck(schemaMap,v){
return "", fmt.Errorf("SchemaCheck fail,args index %d string doesn't match %s format", k,args[0])
}
putDate,_:=json.Marshal(mapResult)
......
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