add gongxianghui_auth code

parent 77fa04d6
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="de83b181-e854-4be8-81f5-73a2fdb02762" name="Default Changelist" comment=""> <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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gongxianghui/gongxianghui.go" beforeDir="false" afterPath="$PROJECT_DIR$/gongxianghui/gongxianghui.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/gongxianghui/gongxianghui.go" beforeDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -12,26 +12,12 @@ ...@@ -12,26 +12,12 @@
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300" />
<file pinned="false" current-in-tab="false"> </component>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go"> <component name="FindInProjectRecents">
<provider selected="true" editor-type-id="text-editor"> <findStrings>
<state relative-caret-position="407"> <find>user</find>
<caret line="186" column="14" lean-forward="true" selection-start-line="186" selection-start-column="14" selection-end-line="186" selection-end-column="14" /> </findStrings>
</state>
</provider>
</entry>
</file>
<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="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>
</file>
</leaf>
</component> </component>
<component name="GOROOT" path="/usr/local/go" /> <component name="GOROOT" path="/usr/local/go" />
<component name="Git.Settings"> <component name="Git.Settings">
...@@ -44,14 +30,19 @@ ...@@ -44,14 +30,19 @@
<option value="$PROJECT_DIR$/gongxianghui/deposit.go" /> <option value="$PROJECT_DIR$/gongxianghui/deposit.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui_test.go" /> <option value="$PROJECT_DIR$/gongxianghui/gongxianghui_test.go" />
<option value="$PROJECT_DIR$/gongxianghui/gongxianghui.go" /> <option value="$PROJECT_DIR$/gongxianghui/gongxianghui.go" />
<option value="$PROJECT_DIR$/github.com/gongxianghui/gongxianghui_test.go" />
<option value="$PROJECT_DIR$/github.com/gongxianghui_test/gongxianghui_test.go" />
<option value="$PROJECT_DIR$/github.com/gongxianghui/gongxianghui.go" />
<option value="$PROJECT_DIR$/github.com/gongxianghui_test/gongxianghui.go" />
<option value="$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go" />
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds" extendedState="6"> <component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="120" /> <option name="x" value="1" />
<option name="y" value="27" /> <option name="y" value="25" />
<option name="width" value="1657" /> <option name="width" value="639" />
<option name="height" value="861" /> <option name="height" value="455" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView"> <component name="ProjectView">
...@@ -59,7 +50,6 @@ ...@@ -59,7 +50,6 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" />
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
<expand> <expand>
...@@ -69,13 +59,13 @@ ...@@ -69,13 +59,13 @@
</path> </path>
<path> <path>
<item name="chaincode" type="b2602c69:ProjectViewProjectNode" /> <item name="chaincode" type="b2602c69:ProjectViewProjectNode" />
<item name="chaincode" type="462c0819:PsiDirectoryNode" /> <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
<item name="gongxianghui" type="462c0819:PsiDirectoryNode" />
</path> </path>
</expand> </expand>
<select /> <select />
</subPane> </subPane>
</pane> </pane>
<pane id="Scope" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
...@@ -87,6 +77,7 @@ ...@@ -87,6 +77,7 @@
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" /> <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" /> <property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="editor.preferences.fonts.default" />
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
...@@ -100,16 +91,38 @@ ...@@ -100,16 +91,38 @@
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager" selected="Go Test.TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui"> <component name="RunManager" selected="Go Test.TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test">
<configuration name="TestGXHCC in github.com/hyperledger/chaincode/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true"> <configuration name="TestGXH in github.com/hyperledger/chaincode/github.com/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" /> <module name="chaincode" />
<working_directory value="$PROJECT_DIR$/gongxianghui" /> <working_directory value="$PROJECT_DIR$/github.com/gongxianghui" />
<framework value="gotest" /> <framework value="gotest" />
<kind value="PACKAGE" /> <kind value="PACKAGE" />
<package value="github.com/hyperledger/chaincode/gongxianghui" /> <package value="github.com/hyperledger/chaincode/github.com/gongxianghui" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGXH$" />
<method v="2" />
</configuration>
<configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" />
<working_directory value="$PROJECT_DIR$/github.com/gongxianghui_test" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/hyperledger/chaincode/github.com/gongxianghui_test" />
<directory value="$PROJECT_DIR$/" /> <directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" /> <filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGXHCC$" /> <pattern value="^TestGXHDataPutAuth$" />
<method v="2" />
</configuration>
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/github.com/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" />
<working_directory value="$PROJECT_DIR$/github.com/gongxianghui" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/hyperledger/chaincode/github.com/gongxianghui" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGXHSchema$" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true"> <configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
...@@ -123,56 +136,69 @@ ...@@ -123,56 +136,69 @@
<pattern value="^TestGXHSchema$" /> <pattern value="^TestGXHSchema$" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="TestGXHSchemaAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="chaincode" />
<working_directory value="$PROJECT_DIR$/github.com/gongxianghui_test" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/hyperledger/chaincode/github.com/gongxianghui_test" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestGXHSchemaAuth$" />
<method v="2" />
</configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Go Test.TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" />
<item itemvalue="Go Test.TestGXHSchemaAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" />
<item itemvalue="Go Test.TestGXH in github.com/hyperledger/chaincode/github.com/gongxianghui" />
<item itemvalue="Go Test.TestGXHSchema in github.com/hyperledger/chaincode/github.com/gongxianghui" />
<item itemvalue="Go Test.TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" /> <item itemvalue="Go Test.TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" />
<item itemvalue="Go Test.TestGXHCC in github.com/hyperledger/chaincode/gongxianghui" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
<component name="TestHistory"> <component name="TestHistory">
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 08m 03s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 11h 58m 38s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 09m 01s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 36m 05s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 09m 43s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 36m 55s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 45m 07s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 37m 25s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 48m 06s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 38m 00s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 48m 32s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 39m 54s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 14h 55m 01s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 40m 19s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 20h 01m 24s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 15h 40m 45s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 20h 01m 40s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 16h 14m 06s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
<history-entry file="TestGXHSchema_in_github_com_hyperledger_chaincode_gongxianghui - 2020.02.21 at 20h 03m 09s.xml"> <history-entry file="TestGXHDataPutAuth_in_github_com_hyperledger_chaincode_github_com_gongxianghui_test - 2020.02.27 at 18h 22m 13s.xml">
<configuration name="TestGXHSchema in github.com/hyperledger/chaincode/gongxianghui" configurationId="GoTestRunConfiguration" /> <configuration name="TestGXHDataPutAuth in github.com/hyperledger/chaincode/github.com/gongxianghui_test" configurationId="GoTestRunConfiguration" />
</history-entry> </history-entry>
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="67" y="25" width="1853" height="925" extended-state="6" /> <frame x="71" y="32" width="2489" height="1568" extended-state="6" />
<editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.12908587" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.21466611" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.3308176" /> <window_info anchor="bottom" id="Run" order="2" weight="0.32962447" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.39986092" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" /> <window_info anchor="bottom" id="TODO" order="6" />
...@@ -180,7 +206,7 @@ ...@@ -180,7 +206,7 @@
<window_info anchor="bottom" id="Version Control" order="8" /> <window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" /> <window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Statistic" order="10" /> <window_info anchor="bottom" id="Statistic" order="10" />
<window_info anchor="bottom" id="Terminal" order="11" weight="0.32955974" /> <window_info anchor="bottom" id="Terminal" order="11" visible="true" weight="0.31223923" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" /> <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="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
...@@ -193,27 +219,112 @@ ...@@ -193,27 +219,112 @@
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/gongxianghui/schema.go"> <entry file="file://$PROJECT_DIR$/gongxianghui/schema.go" />
<entry file="file://$PROJECT_DIR$/gongxianghui/deposit.go" />
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go" />
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go" />
<entry file="file:///usr/local/go/src/crypto/x509/x509.go">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="676" column="4" selection-start-line="676" selection-start-column="4" selection-end-line="676" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/bytes/bytes.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="76"> <state relative-caret-position="3306">
<caret line="8" selection-start-line="8" selection-end-line="8" /> <caret line="178" column="43" selection-start-line="178" selection-start-column="43" selection-end-line="178" selection-end-column="43" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/deposit.go"> <entry file="file://$PROJECT_DIR$/../fabric/core/chaincode/shim/mockstub.go">
<provider selected="true" editor-type-id="text-editor" /> <provider selected="true" editor-type-id="text-editor">
<state>
<caret line="141" column="1" selection-start-line="141" selection-start-column="1" selection-end-line="141" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/fmt/errors.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="211">
<caret line="16" column="5" selection-start-line="16" selection-start-column="5" selection-end-line="16" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/crypto/x509/pkix/pkix.go">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="126" column="18" selection-start-line="126" selection-start-column="18" selection-end-line="126" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/encoding/asn1/asn1.go">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="220" column="5" selection-start-line="220" selection-start-column="5" selection-end-line="220" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../fabric/core/chaincode/shim/response.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="541">
<caret line="34" column="16" selection-start-line="34" selection-start-column="16" selection-end-line="34" selection-end-column="16" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../fabric/protos/peer/proposal_response.pb.go">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret line="109" column="5" selection-start-line="109" selection-start-column="5" selection-end-line="109" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui_auth/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1276">
<caret line="164" column="70" selection-start-line="164" selection-start-column="70" selection-end-line="164" selection-end-column="70" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="462">
<caret line="37" selection-start-line="37" selection-end-line="37" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="519">
<caret line="90" column="83" selection-start-line="90" selection-start-column="78" selection-end-line="90" selection-end-column="83" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/github.com/gongxianghui_auth/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-7612">
<caret line="107" column="83" selection-start-line="107" selection-start-column="83" selection-end-line="107" selection-end-column="83" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="107" column="4" selection-start-line="107" selection-start-column="4" selection-end-line="119" selection-end-column="66" />
</state>
</provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui.go"> <entry file="file://$PROJECT_DIR$/src/github.com/gongxianghui_auth/gongxianghui.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="407"> <state relative-caret-position="396">
<caret line="186" column="14" lean-forward="true" selection-start-line="186" selection-start-column="14" selection-end-line="186" selection-end-column="14" /> <caret line="26" column="61" selection-start-line="26" selection-start-column="4" selection-end-line="26" selection-end-column="61" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/gongxianghui/gongxianghui_test.go"> <entry file="file://$PROJECT_DIR$/../fabric/core/chaincode/shim/interfaces.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1278"> <state relative-caret-position="880">
<caret line="76" column="80" selection-start-line="76" selection-start-column="80" selection-end-line="76" selection-end-column="80" /> <caret line="44" column="4" selection-start-line="44" selection-start-column="4" selection-end-line="44" selection-end-column="4" />
</state> </state>
</provider> </provider>
</entry> </entry>
......
package main package main
import ( import (
"bytes"
"crypto/x509"
"encoding/json" "encoding/json"
"encoding/pem"
"fmt" "fmt"
"github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer" pb "github.com/hyperledger/fabric/protos/peer"
...@@ -55,7 +58,8 @@ func (t *GXHCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response { ...@@ -55,7 +58,8 @@ func (t *GXHCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
} }
return shim.Success([]byte(res)) return shim.Success([]byte(res))
case "cert":
testCertificate(stub)
default: default:
return shim.Error(fmt.Sprintf("Unsupported function %s", functionName)) return shim.Error(fmt.Sprintf("Unsupported function %s", functionName))
...@@ -84,18 +88,18 @@ func put(args []string, stub shim.ChaincodeStubInterface) (string, error) { ...@@ -84,18 +88,18 @@ 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]), &Result); 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 array, err:%s", err)
} }
for k, mapres := range Result{ for k, mapres := range Result{
Id ,ok:= mapres["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 ")
} }
if result,err := stub.GetState(args[0]+Id.(string));err!=nil{ //if result,err := stub.GetState(args[0]+Id.(string));err!=nil{
return "", fmt.Errorf("get %s data happen err: ", args[0]+Id.(string)) // return "", fmt.Errorf("get %s data happen err: ", args[0]+Id.(string))
}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,mapres){ 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])
} }
...@@ -278,6 +282,7 @@ func (this *Schema) put(args []string, stub shim.ChaincodeStubInterface) (string ...@@ -278,6 +282,7 @@ func (this *Schema) put(args []string, stub shim.ChaincodeStubInterface) (string
/* /*
if update Schema 那么我们没有办法比较旧有的一个模板, if update Schema 那么我们没有办法比较旧有的一个模板,
Schema 的 update,不支持部分修改,因为存在增加和删除某些字段的情况。
TODO,增加版本管理 TODO,增加版本管理
*/ */
func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (string, error) { func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
...@@ -318,6 +323,36 @@ func (this *Schema) get(args string, stub shim.ChaincodeStubInterface) (string, ...@@ -318,6 +323,36 @@ func (this *Schema) get(args string, stub shim.ChaincodeStubInterface) (string,
return string(result), nil return string(result), nil
} }
func testCertificate(stub shim.ChaincodeStubInterface) pb.Response{
creatorByte,_:= stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----BEGIN")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
fmt.Println("cert %v ",cert)
result,err := json.Marshal(cert)
if err!=nil{
fmt.Println("Marshal err:",err)
}
fmt.Println("cert marshal:",string(result))
fmt.Println("cert Subject %v ",cert.Subject)
uname:=cert.Subject.CommonName
fmt.Println("Name:"+uname)
return shim.Success([]byte("Called testCertificate "+uname))
}
func main() { func main() {
err := shim.Start(&GXHCC{}) err := shim.Start(&GXHCC{})
if err != nil { if err != nil {
......
package main
import (
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
"testing"
)
func TestGXHCC(t *testing.T) {
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
response:= stub.MockInit("init",nil)
fmt.Println(string(response.Payload))
input := `{"aname":"alibusi","aname":"alibus","atype":"type","alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"","aader":"aader","amob":"1234567890"}}`
responseByPut := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(input)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPut.Status,responseByPut.Message,string(responseByPut.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(input)})
fmt.Printf("Invoke status %d,message %s and payload %s \n",responseByget.Status,responseByget.Message,string(responseByget.Payload))
return
input2 := `{"id":"1","aname":"aaa","atype":"aaa","alinkman":"cc","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"aaa","aader":"aader","amob":"1234567890"}}`
responseByPut2 := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(input2)})
fmt.Printf("Invoke22 status %d,message %s and payload %s\n",responseByPut2.Status,responseByPut2.Message,string(responseByPut2.Payload))
responseByget2 := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke22 status %d,message %s and payload %s",responseByget2.Status,responseByget2.Message,string(responseByget2.Payload))
}
func TestGXHSchema(t *testing.T){
input := `{"id":"1","aname":"alibusi","aname":"alibus","atype":"type","alinkman":"","aader":"aader",
"amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"",
"aader":"aader","amob":"1234567890"}}`
inputarrary := `[{"id":"1","aname":"alibusi","atype":"type","alinkman":"",
"aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890"}},{"id":"2","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890"}}]`
update := `{"alinkman":"张三","id":"1","backup":{}}`
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
response:= stub.MockInit("init",nil)
fmt.Println("MockInit Payload: ",string(response.Payload))
fmt.Println()
fmt.Println("========================================invoke schema put============================================")
fmt.Println()
fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(input)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
responseByGet := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByGet.Status,responseByGet.Message,string(responseByGet.Payload))
fmt.Println()
fmt.Println("========================================invoke data put============================================")
fmt.Println()
fmt.Println()
responseByPut := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(inputarrary)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByPut.Status,responseByPut.Message,string(responseByPut.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget.Status,responseByget.Message,string(responseByget.Payload))
fmt.Println()
fmt.Println("========================================invoke data update============================================")
fmt.Println()
fmt.Println()
responseByUpdate := stub.MockInvoke("invoke1",[][]byte{[]byte("update"), []byte("alibusi"),[]byte(update)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByUpdate.Status,responseByUpdate.Message,string(responseByUpdate.Payload))
responseByget2 := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget2.Status,responseByget2.Message,string(responseByget2.Payload))
//inputfail := `{"id":"2","atype":"type","alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"","aader":"aader","amob":"1234567890"}}`
//fmt.Println()
//fmt.Println("========================================fail input data============================================")
//
//
//responseByPutfail := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(inputfail)})
//fmt.Printf("Invoke status %d,message %s and payload %s\n",
// responseByPutfail.Status,responseByPutfail.Message,string(responseByPutfail.Payload))
//responseBygetfail := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
//fmt.Printf("Invoke status %d,message %s and payload %s \n",
// responseBygetfail.Status,responseBygetfail.Message,string(responseBygetfail.Payload))
}
func TestGXH(t *testing.T){
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
stub.MockInit("init",nil)
stub.MockInvoke("invoke1",[][]byte{[]byte("cert")})
}
\ No newline at end of file
package main
import (
"bytes"
"crypto/x509"
"encoding/json"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type GXHCC struct {
}
//type Schema struct {
//}
type SchemaParameters struct {
Value interface{} //默认值 这里特别说明一下如果这里是backUp 字段,我们不进行更深一步的校验,包括格式
Read []string // 字段的读权限,“”,不存在权限,
Write []string //字段的写权限
}
type Schema struct {
Parameters map[string]SchemaParameters
SchemaWrite []string //schema 的写权限,主要是用在 schema update 部分
Read []string
Write []string
}
var (
defValue = "***" //查询用户权限不足的情况下默认返回值
)
// Init does nothing for this cc
func (t *GXHCC) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success([]byte("GXHCC init successful! "))
}
// Invoke for this chaincode exposes
func (t *GXHCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
// get arguments and transient
functionName, args := stub.GetFunctionAndParameters()
switch functionName {
case "authority":
case "schema":
res, err := SchemaProcess(args, stub)
if err != nil {
return shim.Error(fmt.Sprintf("SchemaProcess function err: %s", err))
}
return shim.Success([]byte(res))
case "put":
res, err := put(args, stub)
if err != nil {
return shim.Error(fmt.Sprintf("put function err: %s", err))
}
return shim.Success([]byte(res))
case "get":
res, err := get(args, stub)
if err != nil {
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("update function err: %s", err))
}
return shim.Success([]byte(res))
default:
return shim.Error(fmt.Sprintf("Unsupported function %s", functionName))
}
return shim.Success([]byte("GXHCC invoke successful "))
}
/*
put
args 字段说明:
1:args[0]代表我们具体操作的表,
2:args[1:]后面的数据表示要记录到数据库的数据,每一个string 必须是json字符串,并且需要每一个json 字符串都必须包含id 字段
*/
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 Result []map[string]interface{}
commonName, err := getCertificateCommonName(stub)
if err != nil {
return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err)
}
schema := &Schema{}
result, err := schema.get(args[0], stub)
if err != nil {
return "", err
}
if err := json.Unmarshal([]byte(result), &schema); err != nil {
return "", fmt.Errorf("json Unmarshal schemaRes err: %s ", err)
}
if !authorityCheck(schema.Write, commonName) {
return "", fmt.Errorf("The current user does not have write permission to %s ", args[0])
}
if err := json.Unmarshal([]byte(args[1]), &Result); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json array, err:%s", err)
}
for k, mapres := range Result {
Id, ok := mapres["id"]
if !ok {
return "", fmt.Errorf("The id field must exist ")
}
//if result, err := stub.GetState(args[0] + Id.(string)); err != nil {
// return "", fmt.Errorf("get %s data happen err: ", args[0]+Id.(string))
//}
//else if result != nil {
// return "", fmt.Errorf("%s data already exist", args[0]+Id.(string))
//}
if !SchemaCheck(schema.Parameters, mapres) {
return "", fmt.Errorf("SchemaCheck fail,args index %d string doesn't match %s format", k, args[0])
}
putDate, _ := json.Marshal(mapres)
if err := stub.PutState(args[0]+Id.(string), putDate); err != nil {
return "", fmt.Errorf("PutState fail, err :%s", err)
}
}
return fmt.Sprintf("%s put data success!", args[0]), nil
}
/*
修改一个表的一条数据的一个或者多个字段值
*/
func update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 {
return "", fmt.Errorf("Expected 2 parameters to function update! ")
}
commonName, err := getCertificateCommonName(stub)
if err != nil {
return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err)
}
schema := &Schema{}
schemaRes, err := schema.get(args[0], stub)
if err != nil {
return "", err
}
if err := json.Unmarshal([]byte(schemaRes), &schema); err != nil {
return "", fmt.Errorf("json Unmarshal schemaRes err: %s ", err)
}
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 string not json string,err: %s", err)
}
Id, ok := mapResult["id"]
if !ok {
return "", fmt.Errorf("The id field must exist ")
}
if !authorityCheck(schema.Write, commonName) {
if ok, err := parsauthorityCheck(schema.Parameters, mapResult, commonName); !ok {
return "", fmt.Errorf("parsauthorityCheck err: %s", err)
}
}
result, err := stub.GetState(args[0] + Id.(string))
if err != nil || result == nil {
return "", fmt.Errorf("GetState data fail,please check your parameters ")
}
if err := json.Unmarshal(result, &allMap); err != nil {
return "", fmt.Errorf("result parameters Unmarshal fail err:%s ", err)
}
if err := Deassign(mapResult, allMap); err != nil {
return "", err
}
resultByte, _ := json.Marshal(allMap)
if err := stub.PutState(args[0]+Id.(string), resultByte); err != nil {
return "", fmt.Errorf("updateState date fail, err :%s ", err)
}
return fmt.Sprintf("%s update data success!", args[0]), nil
}
func get(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 {
return "", fmt.Errorf("Expected 2 parameters to function get!")
}
commonName, err := getCertificateCommonName(stub)
if err != nil {
return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err)
}
var parameters map[string]interface{}
var mapResult map[string]interface{}
if err := json.Unmarshal([]byte(args[1]), &parameters); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
}
Id, ok := parameters["id"]
if !ok {
return "", fmt.Errorf("The id field must exist ")
}
result, err := stub.GetState(args[0] + Id.(string))
if err != nil || result == nil {
return "", fmt.Errorf("GetState data fail,please check your parameters ")
}
schema := &Schema{}
schemaRes, err := schema.get(args[0], stub)
if err != nil {
return "", err
}
if err := json.Unmarshal([]byte(schemaRes), &schema); err != nil {
return "", fmt.Errorf("json Unmarshal schemaRes err: %s ", err)
}
if err := json.Unmarshal(result, &mapResult); err != nil {
return "", fmt.Errorf(" Unmarshal fail,result err: %s", err)
}
if !authorityCheck(schema.Read, commonName) {
if filteredData, err := dataFilter(schema.Parameters, mapResult, commonName); err != nil {
return "", fmt.Errorf(" dataFilter fail, err: %s", err)
} else {
result, _ := json.Marshal(filteredData)
return string(result), nil
}
} else {
return string(result), nil
}
}
/*
重新赋值,并检查相应的格式是否正确
*/
func Deassign(upMap, result map[string]interface{}) error {
if len(upMap) > len(result) {
return fmt.Errorf("Deassign fail,reassigned data length greater than the original data length! ")
}
for k, v := range upMap {
if resultV, ok := result[k]; ok {
if resultMap, resultok := resultV.(map[string]interface{}); resultok {
if vMap, ok := v.(map[string]interface{}); !ok {
return fmt.Errorf("Deassign fail, format doesn't match! ")
} else {
Deassign(vMap, resultMap)
}
} else {
result[k] = v
}
} else {
return fmt.Errorf("Deassign fail %s key nonentity ", k)
}
}
return nil
}
func SchemaCheck(schema map[string]SchemaParameters, checkmap map[string]interface{}) bool {
if len(schema) != len(checkmap) {
return false
}
for k, v := range checkmap {
if schemaV, ok := schema[k]; !ok {
return false
} else {
if parameterS, ok := schemaV.Value.(map[string]interface{}); ok {
if parameterC, ok := v.(map[string]interface{}); !ok {
return false
}else{
if !BackUpCheck(parameterS,parameterC){
return false
}
}
//else {
// var backUp map[string]SchemaParameters
// backUpByte,_ := json.Marshal(parameterS)
// if err := json.Unmarshal(backUpByte,&backUp);err != nil{
// return false
// }
// if !SchemaCheck(backUp, parameterC) {
// return false
// }
//}
}
}
}
return true
}
func BackUpCheck(backUp map[string]interface{}, checkmap map[string]interface{}) bool {
if len(backUp) != len(checkmap) {
return false
}
for k, _ := range checkmap {
if _, ok := backUp[k]; !ok {
return false
}
}
return true
}
func SchemaProcess(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) < 2 {
return "", fmt.Errorf("Expect features with 2 or more parameters to play! ")
}
schema := &Schema{}
switch args[0] {
case "put":
return schema.put(args[1:], stub)
case "update":
return schema.update(args[1:], stub)
case "get":
return schema.get(args[1], stub)
default:
return "", fmt.Errorf(fmt.Sprintf("Unsupported schema function of %s", args[0]))
}
}
/*
put
args 字段说明:
1:args[0]代表我们具体操作的表,
2:args[1:]后面的数据表示要记录到数据库的数据,每一个string 必须是json字符串,并且需要每一个json 字符串都必须包含id 字段
我们可以发现json字符串都被我们解析成了map[string]interface{}类型的map,其中key代表表模板的字段,interface可以是一个结构,我们当前将他看做我们表模板字段的初始值。
*/
func (this *Schema) put(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 {
return "", fmt.Errorf("Expected 2 parameters to function put!")
}
var schema Schema
if err := json.Unmarshal([]byte(args[1]), &schema); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
} else {
if backupValue, ok := schema.Parameters["backup"]; ok {
if _,ok := backupValue.Value.(map[string]interface{}); !ok {
return "", fmt.Errorf("parameters Unmarshal fail,extra string not json string,err: %s", err)
}
//var backUp map[string]SchemaParameters
//backUpByte, _ := json.Marshal(backupValue.Value)
//if err := json.Unmarshal(backUpByte, &backUp); err != nil {
// return "", fmt.Errorf("backup value parameters struct err %s ", err)
//}
}
}
_, ok := schema.Parameters["id"]
if !ok {
return "", fmt.Errorf("The id field must exist ")
}
if value, _ := stub.GetState(args[0]); value != nil {
return "", fmt.Errorf("the parameter %s already exists and cannot be added", args[0])
}
putDate, _ := json.Marshal(schema) //处理重复字段
if err := stub.PutState(args[0], putDate); err != nil {
return "", fmt.Errorf("PutState fail,err: %s", err)
}
return fmt.Sprintf("%s schema put success!", args[0]), nil
}
/*
if update Schema 那么我们没有办法比较旧有的一个模板,
Schema 的 update,不支持部分修改,因为存在增加和删除某些字段的情况。
TODO,增加版本管理
*/
func (this *Schema) update(args []string, stub shim.ChaincodeStubInterface) (string, error) {
if len(args) != 2 {
return "", fmt.Errorf("expected 2 parameters to function put! ")
}
var schema Schema
if err := json.Unmarshal([]byte(args[1]), &schema); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail,args string not json string,err: %s", err)
} else {
if backupValue, ok := schema.Parameters["backup"]; ok { //保证backup 对应的参数格式为map[string]interface{}
if _,ok := backupValue.Value.(map[string]interface{}); !ok {
return "", fmt.Errorf("parameters Unmarshal fail,extra string not json string,err: %s", err)
}
}
}
_, ok := schema.Parameters["id"]
if !ok {
return "", fmt.Errorf("The id field must exist ")
}
result, err := stub.GetState(args[0])
if err != nil || result == nil {
return "", fmt.Errorf("%s schema data doesn't exist,please check your parameters ",args[0])
}
if err := json.Unmarshal([]byte(result), &schema); err != nil {
return "", fmt.Errorf("parameters Unmarshal fail, err: %s", err)
}
commonName, err := getCertificateCommonName(stub)
if err != nil {
return "", fmt.Errorf("getCertificateCommonName happen err: %s ", err)
}
if !authorityCheck(schema.SchemaWrite,commonName){
return "", fmt.Errorf("The current user does not have update permission to %s schema ", args[0])
}
if err = stub.PutState(args[0], []byte(args[1]));err != nil{
return "", fmt.Errorf("%s schema data PutState fail,please try again ",args[0])
}
return fmt.Sprintf("%s schema update success!", args[0]), err
}
func (this *Schema) get(args string, stub shim.ChaincodeStubInterface) (string, error) {
result, err := stub.GetState(args)
if err != nil || result == nil {
return "", fmt.Errorf("GetSchema data fail,please check your parameters ")
}
return string(result), nil
}
func getCertificateCommonName(stub shim.ChaincodeStubInterface) (string, error) {
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----BEGIN")
if certStart == -1 {
return "", fmt.Errorf("No certificate found ")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
return "", fmt.Errorf("Could not decode the PEM structure ")
}
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
return "", fmt.Errorf("ParseCertificate failed")
}
return cert.Subject.CommonName, nil
}
/*
检查一组参数的权限是否匹配
*/
func parsauthorityCheck(schema map[string]SchemaParameters, checkmap map[string]interface{}, commonName string) (bool, error) {
for k, v := range checkmap {
if schemaV, ok := schema[k]; !ok {
return false, fmt.Errorf("Update data parameter mismatch with schema structure! ")
} else {
if _, ok := schemaV.Value.(map[string]interface{}); ok {
if _, ok := v.(map[string]interface{}); !ok {
return false, fmt.Errorf("Update data parameter mismatch with schema structure! ")
}
}
// if !authorityCheck(schemaV.Write, commonName) {
// return false, fmt.Errorf("%s field permission check does not match", k)
// }
// else {
// if res, err := parsauthorityCheck(parameterS, parameterC, commonName); !res {
// return res, err
// }
// }
//} else {
if !authorityCheck(schemaV.Write, commonName) {
return false, fmt.Errorf("%s field permission check does not match", k)
}
//}
}
}
return true, nil
}
/*
根据权限拼装数据,进行数据过滤
*/
func dataFilter(schema map[string]SchemaParameters, checkmap map[string]interface{}, commonName string) (map[string]interface{}, error) {
for k, v := range checkmap {
if schemaV, ok := schema[k]; !ok {
return nil, fmt.Errorf("Update data parameter mismatch with schema structure! ")
} else {
if _, ok := schemaV.Value.(map[string]SchemaParameters); ok {
if _, ok := v.(map[string]interface{}); !ok {
return nil, fmt.Errorf("Update data parameter mismatch with schema structure! ")
}
if !authorityCheck(schemaV.Read, commonName) {
checkmap[k] = defValue
}
//else {
// if _, err := dataFilter(parameterS, parameterC, commonName); err!=nil {
// return nil, err
// }
//}
} else {
if !authorityCheck(schemaV.Read, commonName) {
checkmap[k] = defValue
}
}
}
}
return checkmap, nil
}
func authorityCheck(authority []string, commonName string) bool {
if len(authority) == 0 {
return true
}
for _, v := range authority {
if v == commonName {
return true
}
}
return false
}
func main() {
err := shim.Start(&GXHCC{})
if err != nil {
fmt.Printf("Error starting EncCC chaincode: %s", err)
}
}
package main
import (
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
"testing"
)
var schema = `{"Parameters":{"Alinkman":{"Value":"Alinkman","Read":"","Write":""},"Amob":{"Value":"Amob","Read":"","Write":""},
"Aname":{"Value":"Aname","Read":"","Write":""},"Atype":{"Value":"Atype","Read":"","Write":""},"Backup":{"Value":[{"Value":"1",
"Read":"","Write":""},{"Value":"Aname","Read":"","Write":""},{"Value":"Atype","Read":"","Write":""},{"Value":"Alinkman","Read":"","Write":""}],
"Read":"","Write":""},"id":{"Value":"1","Read":"","Write":""}},"Read":"","Write":"","ParametersRead":true,"ParametersWrite":true}`
func TestGXHCC(t *testing.T) {
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
response:= stub.MockInit("init",nil)
fmt.Println(string(response.Payload))
input := `{"aname":"alibusi","aname":"alibus","atype":"type","alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"","aader":"aader","amob":"1234567890"}}`
responseByPut := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(input)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPut.Status,responseByPut.Message,string(responseByPut.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(input)})
fmt.Printf("Invoke status %d,message %s and payload %s \n",responseByget.Status,responseByget.Message,string(responseByget.Payload))
return
input2 := `{"id":"1","aname":"aaa","atype":"aaa","alinkman":"cc","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"aaa","aader":"aader","amob":"1234567890"}}`
responseByPut2 := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(input2)})
fmt.Printf("Invoke22 status %d,message %s and payload %s\n",responseByPut2.Status,responseByPut2.Message,string(responseByPut2.Payload))
responseByget2 := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke22 status %d,message %s and payload %s",responseByget2.Status,responseByget2.Message,string(responseByget2.Payload))
}
func TestGXHSchema(t *testing.T){
input := `{"id":"1","aname":"alibusi","aname":"alibus","atype":"type","alinkman":"","aader":"aader",
"amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"",
"aader":"aader","amob":"1234567890"}}`
inputarrary := `[{"id":"1","aname":"alibusi","atype":"type","alinkman":"",
"aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890"}},{"id":"2","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type",
"alinkman":"","aader":"aader","amob":"1234567890"}}]`
update := `{"alinkman":"张三","id":"1","backup":{}}`
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
response:= stub.MockInit("init",nil)
fmt.Println("MockInit Payload: ",string(response.Payload))
fmt.Println()
fmt.Println("========================================invoke schema put============================================")
fmt.Println()
fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(input)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
responseByGet := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByGet.Status,responseByGet.Message,string(responseByGet.Payload))
fmt.Println()
fmt.Println("========================================invoke data put============================================")
fmt.Println()
fmt.Println()
responseByPut := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(inputarrary)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByPut.Status,responseByPut.Message,string(responseByPut.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget.Status,responseByget.Message,string(responseByget.Payload))
fmt.Println()
fmt.Println("========================================invoke data update============================================")
fmt.Println()
fmt.Println()
responseByUpdate := stub.MockInvoke("invoke1",[][]byte{[]byte("update"), []byte("alibusi"),[]byte(update)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByUpdate.Status,responseByUpdate.Message,string(responseByUpdate.Payload))
responseByget2 := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget2.Status,responseByget2.Message,string(responseByget2.Payload))
//inputfail := `{"id":"2","atype":"type","alinkman":"","aader":"aader","amob":"1234567890","backup":{"id":"1","aname":"alibusi","atype":"type","alinkman":"","aader":"aader","amob":"1234567890"}}`
//fmt.Println()
//fmt.Println("========================================fail input data============================================")
//
//
//responseByPutfail := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(inputfail)})
//fmt.Printf("Invoke status %d,message %s and payload %s\n",
// responseByPutfail.Status,responseByPutfail.Message,string(responseByPutfail.Payload))
//responseBygetfail := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
//fmt.Printf("Invoke status %d,message %s and payload %s \n",
// responseBygetfail.Status,responseBygetfail.Message,string(responseBygetfail.Payload))
}
/*
以下部分是增加权限内容的测试
*/
var (
authInput = `{"Parameters":{"alinkman":{"Value":"Alinkman","Read":["user"],"Write":["admin"]},"amob":{"Value":"Amob","Read":[],"Write":[]},"aname":
{"Value":"Aname","Read":["admin"],"Write":["admin"]},"atype":{"Value":"Atype","Read":["admin"],"Write":["admin"]},"backup":{"Value":{"aname":
{"Value":"Aname","Read":["admin"],"Write":["admin"]},"atype":{"Value":"Atype","Read":["admin"],"Write":["admin"]}},"Read":["admin"],"Write":["admin"]},
"id":{"Value":"1","Read":[],"Write":[]}},"Read":[],"Write":["user"]}
`
inputUpdate = `{"id":"1","aname":"alibusi","atype":"newtype","alinkman":"newalinkman",
"amob":"new1234567890","backup":{"aname":"alibusi","atype":"type"}}`
inputarrary = `[{"id":"1","aname":"alibusi","atype":"type","alinkman":"alinkman",
"amob":"1234567890","backup":{"aname":"alibusi","atype":"type"}},{"id":"2","aname":"alibusi","atype":"type","alinkman":"alinkman",
"amob":"1234567890","backup":{"aname":"alibusi","atype":"type"}}]`
)
func TestGXHSchemaAuth(t *testing.T){
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
stub.MockInit("init",nil)
fmt.Println()
fmt.Println("========================================invoke schema put============================================")
fmt.Println()
fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(authInput)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget.Status,responseByget.Message,string(responseByget.Payload))
}
func TestGXHDataPutAuth(t *testing.T){
cc := new(GXHCC)
stub := shim.NewMockStub("GXHCC",cc)
stub.MockInit("init",nil)
fmt.Println()
fmt.Println("========================================invoke schema put============================================")
fmt.Println()
fmt.Println()
responseByPutschema := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("put"),[]byte("alibusi"),[]byte(authInput)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",
responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
responseByget := stub.MockInvoke("invoke1",[][]byte{[]byte("schema"), []byte("get"),[]byte("alibusi")})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget.Status,responseByget.Message,string(responseByget.Payload))
fmt.Println()
fmt.Println("========================================invoke data put============================================")
fmt.Println()
fmt.Println()
responseByPut := stub.MockInvoke("invoke1",[][]byte{[]byte("put"), []byte("alibusi"),[]byte(inputarrary)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByPut.Status,responseByPut.Message,string(responseByPut.Payload))
responseByget = stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget.Status,responseByget.Message,string(responseByget.Payload))
fmt.Println()
fmt.Println("========================================invoke data update============================================")
fmt.Println()
fmt.Println()
responseByUpdate := stub.MockInvoke("invoke1",[][]byte{[]byte("update"), []byte("alibusi"),[]byte(inputUpdate)})
fmt.Printf("Invoke status %d,message %s ,and payload %s\n",
responseByUpdate.Status,responseByUpdate.Message,string(responseByUpdate.Payload))
responseByget2 := stub.MockInvoke("invoke1",[][]byte{[]byte("get"), []byte("alibusi"),[]byte(`{"id":"1"}`)})
fmt.Printf("Invoke status %d,message %s ,and payload %s \n",
responseByget2.Status,responseByget2.Message,string(responseByget2.Payload))
}
\ No newline at end of file
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