Skip to content

Commit afbd5de

Browse files
author
Bobbie Cochrane
committed
merged with upstream
2 parents 5895a35 + 4fea23b commit afbd5de

5 files changed

Lines changed: 483 additions & 16 deletions

File tree

README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ In order to support multiple versions of the Hyperledger fabric, this repository
1313
- Hyperledger fabric v0.5-developer-preview
1414
- IBM Bluemix Blockchain Service v0.4.2
1515

16-
- [v2.0](https://github.com/ibm-blockchain/learn-chaincode/tree/v2.0) (Coming Soon)
16+
- [v2.0](https://github.com/ibm-blockchain/learn-chaincode/tree/v2.0)
1717

1818
- Hyperledger fabric v0.6-developer-preview
1919

@@ -60,11 +60,11 @@ The following tasks take you through the process of building a pipeline that wil
6060
- Test your chaincode using the fabric REST API.
6161
- Repeat.
6262

63-
1. Fork this repository to your GitHub account. This can be accomplished quickly by scrolling up and clicking the **Fork** button at the top of this repository.
63+
1. Fork this repository to your GitHub account. This can be accomplished quickly by scrolling up and clicking the __Fork__ button at the top of this repository.
6464

6565
![Fork Button Screenshot](imgs/fork.png)
6666

67-
"Forking" the repository means creating a copy of this repository under your GitHub account. Note that the fork will fork the entire repository including all the branches. Toggle the **Branch** button on the left to see the available branches.
67+
"Forking" the repository means creating a copy of this repository under your GitHub account. Note that the fork will fork the entire repository including all the branches. Toggle the __Branch__ button on the left to see the available branches.
6868

6969
![Branch Button Screenshot](imgs/branch.png)
7070

@@ -101,16 +101,18 @@ The following tasks take you through the process of building a pipeline that wil
101101
# See what files have changed locally. You should see chaincode_start.go
102102
git status
103103
# Stage all changes in the local repository for commit
104-
git add -all
104+
git add --all
105105
# Commit all staged changes. Insert a short description after the -m argument
106106
git commit -m "Compiled my code"
107107
# Push local commits back to https://github.com/<YOUR_GITHUB_ID_HERE>/learn-chaincode/
108108
git push
109+
```
109110

110111
In order to turn a piece of Go code into chaincode, all you need to do is implement the chaincode shim interface. The three functions you have to implement are **Init**, **Invoke**, and **Query**. All three functions have the same prototype; they take in a 'stub', which is what you use to read from and write to the ledger, a function name, and an array of strings. The main difference between the functions is when they will be called. In this tutorial you will be building a chaincode to create generic assets.
111112

112113
### Dependencies
113114

115+
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
114116
The `import` statement lists a few dependencies that you will need for your chaincode to build successfully.
115117

116118
- `fmt` - contains `Println` for debugging/logging.
@@ -128,6 +130,12 @@ func (t *SimpleChaincode) Init(stub *shim.ChaincodeStub, function string, args [
128130
if len(args) != 1 {
129131
return nil, errors.New("Incorrect number of arguments. Expecting 1")
130132
}
133+
=======
134+
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
135+
if len(args) != 1 {
136+
return nil, errors.New("Incorrect number of arguments. Expecting 1")
137+
}
138+
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
131139

132140
err := stub.PutState("hello_world", []byte(args[0]))
133141
if err != nil {
@@ -153,8 +161,13 @@ This is done by using the stub function `stub.PutState`. The function interprets
153161
In your `chaincode_start.go` file, change the `Invoke` function so that it calls a generic write function.
154162
155163
```go
164+
<<<<<<< HEAD
156165
func (t *SimpleChaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
157166
fmt.Println("invoke is running " + function)
167+
=======
168+
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
169+
fmt.Println("invoke is running " + function)
170+
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
158171

159172
// Handle different functions
160173
if function == "init" {
@@ -171,6 +184,7 @@ func (t *SimpleChaincode) Invoke(stub *shim.ChaincodeStub, function string, args
171184
Now that it's looking for `write` let's make that function somewhere in your `chaincode_start.go` file.
172185
173186
```go
187+
<<<<<<< HEAD
174188
func (t *SimpleChaincode) write(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
175189
var key, value string
176190
var err error
@@ -187,6 +201,24 @@ func (t *SimpleChaincode) write(stub *shim.ChaincodeStub, args []string) ([]byte
187201
return nil, err
188202
}
189203
return nil, nil
204+
=======
205+
func (t *SimpleChaincode) write(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {
206+
var key, value string
207+
var err error
208+
fmt.Println("running write()")
209+
210+
if len(args) != 2 {
211+
return nil, errors.New("Incorrect number of arguments. Expecting 2. name of the key and value to set")
212+
}
213+
214+
key = args[0] //rename for fun
215+
value = args[1]
216+
err = stub.PutState(key, []byte(value)) //write the variable into the chaincode state
217+
if err != nil {
218+
return nil, err
219+
}
220+
return nil, nil
221+
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
190222
}
191223
```
192224
@@ -205,8 +237,13 @@ As the name implies, `Query` is called whenever you query your chaincode's state
205237
In your `chaincode_start.go` file, change the `Query` function so that it calls a generic read function, similar to what you did in `Invoke`.
206238
207239
```go
240+
<<<<<<< HEAD
208241
func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
209242
fmt.Println("query is running " + function)
243+
=======
244+
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
245+
fmt.Println("query is running " + function)
246+
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
210247

211248
// Handle different functions
212249
if function == "read" { //read a variable
@@ -221,9 +258,9 @@ func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args
221258
Now that it's looking for `read`, let's create that helper function somewhere in your `chaincode_start.go` file.
222259
223260
```go
224-
func (t *SimpleChaincode) read(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
225-
var key, jsonResp string
226-
var err error
261+
func (t *SimpleChaincode) read(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {
262+
var key, jsonResp string
263+
var err error
227264

228265
if len(args) != 1 {
229266
return nil, errors.New("Incorrect number of arguments. Expecting name of the key to query")

0 commit comments

Comments
 (0)