{"action":"created","comment":{"url":"https://api.github.com/repos/hyperledger/education/pulls/comments/146620027","pull_request_review_id":71588334,"id":146620027,"diff_hunk":"@@ -0,0 +1,190 @@\n+// SPDX-License-Identifier: Apache-2.0\n+\n+/*\n+ * Sample Chaincode based on Demonstrated Scenario\n+ */\n+\n+package main\n+\n+/* Imports\n+ * 4 utility libraries for formatting, handling bytes, reading and writing JSON, and string manipulation\n+ * 2 specific Hyperledger Fabric specific libraries for Smart Contracts\n+ */\n+import (\n+\t\"bytes\"\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"strconv\"\n+\n+\t\"github.com/hyperledger/fabric/core/chaincode/shim\"\n+\tsc \"github.com/hyperledger/fabric/protos/peer\"\n+)\n+\n+// Define the Smart Contract structure\n+type SmartContract struct {\n+}\n+\n+// Define Tuna structure, with 4 properties.  Structure tags are used by encoding/json library\n+type Tuna struct {\n+\tVessel string `json:\"vessel\"`\n+\tTimestamp string `json:\"timestamp\"`\n+\tLocation  string `json:\"location\"`\n+\tHolder  string `json:\"holder\"`\n+}\n+\n+/*\n+ * The Init method is called when the Smart Contract \"tuna-chaincode\" is instantiated by the blockchain network\n+ * Best practice is to have any Ledger initialization in separate function -- see initLedger()\n+ */\n+func (s *SmartContract) Init(APIstub shim.ChaincodeStubInterface) sc.Response {\n+\treturn shim.Success(nil)\n+}\n+\n+/*\n+ * The Invoke method is called when an application requests to run the Smart Contract \"tuna-chaincode\"\n+ * The application also specifies the particular smart contract function to call with arguments\n+ */\n+func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response {\n+\n+\t// Retrieve the requested Smart Contract function and arguments\n+\tfunction, args := APIstub.GetFunctionAndParameters()\n+\t// Route to the appropriate handler function to interact with the ledger appropriately\n+\tif function == \"queryTuna\" {\n+\t\treturn s.queryTuna(APIstub, args)\n+\t} else if function == \"initLedger\" {\n+\t\treturn s.initLedger(APIstub)\n+\t} else if function == \"recordTuna\" {\n+\t\treturn s.recordTuna(APIstub, args)\n+\t} else if function == \"queryAllTuna\" {\n+\t\treturn s.queryAllTuna(APIstub)\n+\t} else if function == \"changeTunaHolder\" {\n+\t\treturn s.changeTunaHolder(APIstub, args)\n+\t}\n+\n+\treturn shim.Error(\"Invalid Smart Contract function name.\")\n+}\n+\n+func (s *SmartContract) queryTuna(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {\n+\n+\tif len(args) != 1 {\n+\t\treturn shim.Error(\"Incorrect number of arguments. Expecting 1\")\n+\t}\n+\n+\ttunaAsBytes, _ := APIstub.GetState(args[0])\n+\treturn shim.Success(tunaAsBytes)\n+}\n+\n+/*\n+ * The Init method is called when the Smart Contract \"tuna-chaincode\" is instantiated by the Fabric network\n+ * Best practice is to have any Ledger initialization in separate function -- see initLedger()\n+ */\n+func (s *SmartContract) initLedger(APIstub shim.ChaincodeStubInterface) sc.Response {\n+\ttuna := []Tuna{\n+\t\tTuna{Vessel: \"923F\", Location: \"67.0006, -70.5476\", Timestamp: \"1504054225\", Holder: \"Miriam\"},\n+\t\tTuna{Vessel: \"M83T\", Location: \"91.2395, -49.4594\", Timestamp: \"1504057825\", Holder: \"Dave\"},\n+\t\tTuna{Vessel: \"T012\", Location: \"58.0148, 59.01391\", Timestamp: \"1493517025\", Holder: \"Igor\"},\n+\t\tTuna{Vessel: \"P490\", Location: \"-45.0945, 0.7949\", Timestamp: \"1496105425\", Holder: \"Amalea\"},\n+\t\tTuna{Vessel: \"S439\", Location: \"-107.6043, 19.5003\", Timestamp: \"1493512301\", Holder: \"Rafa\"},\n+\t\tTuna{Vessel: \"J205\", Location: \"-155.2304, -15.8723\", Timestamp: \"1494117101\", Holder: \"Shen\"},\n+\t\tTuna{Vessel: \"S22L\", Location: \"103.8842, 22.1277\", Timestamp: \"1496104301\", Holder: \"Leila\"},\n+\t\tTuna{Vessel: \"EI89\", Location: \"-132.3207, -34.0983\", Timestamp: \"1485066691\", Holder: \"Yuan\"},\n+\t\tTuna{Vessel: \"129R\", Location: \"153.0054, 12.6429\", Timestamp: \"1485153091\", Holder: \"Carlo\"},\n+\t\tTuna{Vessel: \"49W4\", Location: \"51.9435, 8.2735\", Timestamp: \"1487745091\", Holder: \"Fatima\"},\n+\t}\n+\n+\ti := 0\n+\tfor i < len(tuna) {\n+\t\tfmt.Println(\"i is \", i)\n+\t\ttunaAsBytes, _ := json.Marshal(tuna[i])\n+\t\tAPIstub.PutState(strconv.Itoa(i+1), tunaAsBytes)\n+\t\tfmt.Println(\"Added\", tuna[i])\n+\t\ti = i + 1\n+\t}\n+\n+\treturn shim.Success(nil)\n+}\n+\n+func (s *SmartContract) recordTuna(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {\n+\n+\tif len(args) != 5 {\n+\t\treturn shim.Error(\"Incorrect number of arguments. Expecting 5\")\n+\t}\n+\n+\tvar tuna = Tuna{ Vessel: args[1], Location: args[2], Timestamp: args[3], Holder: args[4] }\n+\n+\ttunaAsBytes, _ := json.Marshal(tuna)\n+\tAPIstub.PutState(args[0], tunaAsBytes)\n+\n+\treturn shim.Success(nil)\n+}\n+\n+func (s *SmartContract) queryAllTuna(APIstub shim.ChaincodeStubInterface) sc.Response {","path":"LFS171x/fabric-material/chaincode/tuna-app/tuna-chaincode.go","position":121,"original_position":121,"commit_id":"9bf4ca3400a3a5a6ee150f7a9ec3c5d124c7b817","original_commit_id":"b3781e8f7977409c94c89381a14d83aa078e83bf","user":{"login":"tkuhrt","id":5951734,"avatar_url":"https://avatars2.githubusercontent.com/u/5951734?v=4","gravatar_id":"","url":"https://api.github.com/users/tkuhrt","html_url":"https://github.com/tkuhrt","followers_url":"https://api.github.com/users/tkuhrt/followers","following_url":"https://api.github.com/users/tkuhrt/following{/other_user}","gists_url":"https://api.github.com/users/tkuhrt/gists{/gist_id}","starred_url":"https://api.github.com/users/tkuhrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkuhrt/subscriptions","organizations_url":"https://api.github.com/users/tkuhrt/orgs","repos_url":"https://api.github.com/users/tkuhrt/repos","events_url":"https://api.github.com/users/tkuhrt/events{/privacy}","received_events_url":"https://api.github.com/users/tkuhrt/received_events","type":"User","site_admin":false},"body":"Comment about what this function does","created_at":"2017-10-24T16:37:03Z","updated_at":"2017-10-24T16:37:03Z","html_url":"https://github.com/hyperledger/education/pull/7#discussion_r146620027","pull_request_url":"https://api.github.com/repos/hyperledger/education/pulls/7","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/hyperledger/education/pulls/comments/146620027"},"html":{"href":"https://github.com/hyperledger/education/pull/7#discussion_r146620027"},"pull_request":{"href":"https://api.github.com/repos/hyperledger/education/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/hyperledger/education/pulls/7","id":148276669,"html_url":"https://github.com/hyperledger/education/pull/7","diff_url":"https://github.com/hyperledger/education/pull/7.diff","patch_url":"https://github.com/hyperledger/education/pull/7.patch","issue_url":"https://api.github.com/repos/hyperledger/education/issues/7","number":7,"state":"open","locked":false,"title":"Add Hyperledger Fabric code to Hyperledger education repo","user":{"login":"alexandrag2254","id":11288264,"avatar_url":"https://avatars3.githubusercontent.com/u/11288264?v=4","gravatar_id":"","url":"https://api.github.com/users/alexandrag2254","html_url":"https://github.com/alexandrag2254","followers_url":"https://api.github.com/users/alexandrag2254/followers","following_url":"https://api.github.com/users/alexandrag2254/following{/other_user}","gists_url":"https://api.github.com/users/alexandrag2254/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrag2254/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrag2254/subscriptions","organizations_url":"https://api.github.com/users/alexandrag2254/orgs","repos_url":"https://api.github.com/users/alexandrag2254/repos","events_url":"https://api.github.com/users/alexandrag2254/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrag2254/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-10-24T01:20:15Z","updated_at":"2017-10-24T16:37:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7deed214f3d2f4c395b428c1b349f7d58e8b0a8","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/hyperledger/education/pulls/7/commits","review_comments_url":"https://api.github.com/repos/hyperledger/education/pulls/7/comments","review_comment_url":"https://api.github.com/repos/hyperledger/education/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hyperledger/education/issues/7/comments","statuses_url":"https://api.github.com/repos/hyperledger/education/statuses/9bf4ca3400a3a5a6ee150f7a9ec3c5d124c7b817","head":{"label":"hyperledger:add-fabric","ref":"add-fabric","sha":"9bf4ca3400a3a5a6ee150f7a9ec3c5d124c7b817","user":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"repo":{"id":101315501,"name":"education","full_name":"hyperledger/education","owner":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hyperledger/education","description":"Hyperledger training material","fork":false,"url":"https://api.github.com/repos/hyperledger/education","forks_url":"https://api.github.com/repos/hyperledger/education/forks","keys_url":"https://api.github.com/repos/hyperledger/education/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hyperledger/education/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hyperledger/education/teams","hooks_url":"https://api.github.com/repos/hyperledger/education/hooks","issue_events_url":"https://api.github.com/repos/hyperledger/education/issues/events{/number}","events_url":"https://api.github.com/repos/hyperledger/education/events","assignees_url":"https://api.github.com/repos/hyperledger/education/assignees{/user}","branches_url":"https://api.github.com/repos/hyperledger/education/branches{/branch}","tags_url":"https://api.github.com/repos/hyperledger/education/tags","blobs_url":"https://api.github.com/repos/hyperledger/education/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hyperledger/education/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hyperledger/education/git/refs{/sha}","trees_url":"https://api.github.com/repos/hyperledger/education/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hyperledger/education/statuses/{sha}","languages_url":"https://api.github.com/repos/hyperledger/education/languages","stargazers_url":"https://api.github.com/repos/hyperledger/education/stargazers","contributors_url":"https://api.github.com/repos/hyperledger/education/contributors","subscribers_url":"https://api.github.com/repos/hyperledger/education/subscribers","subscription_url":"https://api.github.com/repos/hyperledger/education/subscription","commits_url":"https://api.github.com/repos/hyperledger/education/commits{/sha}","git_commits_url":"https://api.github.com/repos/hyperledger/education/git/commits{/sha}","comments_url":"https://api.github.com/repos/hyperledger/education/comments{/number}","issue_comment_url":"https://api.github.com/repos/hyperledger/education/issues/comments{/number}","contents_url":"https://api.github.com/repos/hyperledger/education/contents/{+path}","compare_url":"https://api.github.com/repos/hyperledger/education/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hyperledger/education/merges","archive_url":"https://api.github.com/repos/hyperledger/education/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hyperledger/education/downloads","issues_url":"https://api.github.com/repos/hyperledger/education/issues{/number}","pulls_url":"https://api.github.com/repos/hyperledger/education/pulls{/number}","milestones_url":"https://api.github.com/repos/hyperledger/education/milestones{/number}","notifications_url":"https://api.github.com/repos/hyperledger/education/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hyperledger/education/labels{/name}","releases_url":"https://api.github.com/repos/hyperledger/education/releases{/id}","deployments_url":"https://api.github.com/repos/hyperledger/education/deployments","created_at":"2017-08-24T16:23:44Z","updated_at":"2017-10-24T05:53:44Z","pushed_at":"2017-10-24T16:15:40Z","git_url":"git://github.com/hyperledger/education.git","ssh_url":"git@github.com:hyperledger/education.git","clone_url":"https://github.com/hyperledger/education.git","svn_url":"https://github.com/hyperledger/education","homepage":null,"size":83,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":4,"default_branch":"master"}},"base":{"label":"hyperledger:master","ref":"master","sha":"1ddf5d53af7fbb420d03ce5206a006353439992d","user":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"repo":{"id":101315501,"name":"education","full_name":"hyperledger/education","owner":{"login":"hyperledger","id":7657900,"avatar_url":"https://avatars2.githubusercontent.com/u/7657900?v=4","gravatar_id":"","url":"https://api.github.com/users/hyperledger","html_url":"https://github.com/hyperledger","followers_url":"https://api.github.com/users/hyperledger/followers","following_url":"https://api.github.com/users/hyperledger/following{/other_user}","gists_url":"https://api.github.com/users/hyperledger/gists{/gist_id}","starred_url":"https://api.github.com/users/hyperledger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hyperledger/subscriptions","organizations_url":"https://api.github.com/users/hyperledger/orgs","repos_url":"https://api.github.com/users/hyperledger/repos","events_url":"https://api.github.com/users/hyperledger/events{/privacy}","received_events_url":"https://api.github.com/users/hyperledger/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hyperledger/education","description":"Hyperledger training material","fork":false,"url":"https://api.github.com/repos/hyperledger/education","forks_url":"https://api.github.com/repos/hyperledger/education/forks","keys_url":"https://api.github.com/repos/hyperledger/education/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hyperledger/education/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hyperledger/education/teams","hooks_url":"https://api.github.com/repos/hyperledger/education/hooks","issue_events_url":"https://api.github.com/repos/hyperledger/education/issues/events{/number}","events_url":"https://api.github.com/repos/hyperledger/education/events","assignees_url":"https://api.github.com/repos/hyperledger/education/assignees{/user}","branches_url":"https://api.github.com/repos/hyperledger/education/branches{/branch}","tags_url":"https://api.github.com/repos/hyperledger/education/tags","blobs_url":"https://api.github.com/repos/hyperledger/education/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hyperledger/education/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hyperledger/education/git/refs{/sha}","trees_url":"https://api.github.com/repos/hyperledger/education/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hyperledger/education/statuses/{sha}","languages_url":"https://api.github.com/repos/hyperledger/education/languages","stargazers_url":"https://api.github.com/repos/hyperledger/education/stargazers","contributors_url":"https://api.github.com/repos/hyperledger/education/contributors","subscribers_url":"https://api.github.com/repos/hyperledger/education/subscribers","subscription_url":"https://api.github.com/repos/hyperledger/education/subscription","commits_url":"https://api.github.com/repos/hyperledger/education/commits{/sha}","git_commits_url":"https://api.github.com/repos/hyperledger/education/git/commits{/sha}","comments_url":"https://api.github.com/repos/hyperledger/education/comments{/number}","issue_comment_url":"https://api.github.com/repos/hyperledger/education/issues/comments{/number}","contents_url":"https://api.github.com/repos/hyperledger/education/contents/{+path}","compare_url":"https://api.github.com/repos/hyperledger/education/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hyperledger/education/merges","archive_url":"https://api.github.com/repos/hyperledger/education/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hyperledger/education/downloads","issues_url":"https://api.github.com/repos/hyperledger/education/issues{/number}","pulls_url":"https://api.github.com/repos/hyperledger/education/pulls{/number}","milestones_url":"https://api.github.com/repos/hyperledger/education/milestones{/number}","notifications_url":"https://api.github.com/repos/hyperledger/education/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hyperledger/education/labels{/name}","releases_url":"https://api.github.com/repos/hyperledger/education/releases{/id}","deployments_url":"https://api.github.com/repos/hyperledger/education/deployments","created_at":"2017-08-24T16:23:44Z","updated_at":"2017-10-24T05:53:44Z","pushed_at":"2017-10-24T16:15:40Z","git_url":"git://github.com/hyperledger/education.git","ssh_url":"git@github.com:hyperledger/education.git","clone_url":"https://github.com/hyperledger/education.git","svn_url":"https://github.com/hyperledger/education","homepage":null,"size":83,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hyperledger/education/pulls/7"},"html":{"href":"https://github.com/hyperledger/education/pull/7"},"issue":{"href":"https://api.github.com/repos/hyperledger/education/issues/7"},"comments":{"href":"https://api.github.com/repos/hyperledger/education/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/hyperledger/education/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/hyperledger/education/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hyperledger/education/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/hyperledger/education/statuses/9bf4ca3400a3a5a6ee150f7a9ec3c5d124c7b817"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tkuhrt"}}