Skip to content

Commit d7d0b0e

Browse files
author
Bobbie Cochrane
committed
still correcting my merge
1 parent fad73dc commit d7d0b0e

1 file changed

Lines changed: 0 additions & 47 deletions

File tree

README.md

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,10 @@ Init is called when you first deploy your chaincode. As the name implies, this f
125125
In your `chaincode_start.go` file, change the `Init` function so that it stores the first element in the `args` argument to the key "hello_world".
126126

127127
```go
128-
func (t *SimpleChaincode) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
129-
if len(args) != 1 {
130-
return nil, errors.New("Incorrect number of arguments. Expecting 1")
131-
}
132-
=======
133128
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
134129
if len(args) != 1 {
135130
return nil, errors.New("Incorrect number of arguments. Expecting 1")
136131
}
137-
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
138132

139133
err := stub.PutState("hello_world", []byte(args[0]))
140134
if err != nil {
@@ -146,27 +140,16 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string
146140
```
147141

148142
This is done by using the stub function `stub.PutState`. The function interprets the first argument sent in the deployment request as the value to be stored under the key 'hello_world' in the ledger. Where did this argument come from, and what is a deploy request? All will be explained after we finish implementing the chaincode interface. If an error occurs because the wrong number of arguments was passed in or because something went wrong when writing to the ledger, then this function will return an error. Otherwise, it exits cleanly, returning nothing.
149-
<<<<<<< HEAD
150143

151144
### Invoke()
152145

153-
=======
154-
155-
### Invoke()
156-
157-
>>>>>>> 87d7fc6... Fixed a few of the paths to include 'src', and added the branching option to the 'git clone'
158146
`Invoke` is called when you want to call chaincode functions to do real work. Invocations will be captured as a transactions, which get grouped into blocks on the chain. When you need to update the ledger, you will do so by invoking your chaincode. The structure of `Invoke` is simple. It receives a `function` and an array of arguments. Based on what function was passed in through the `function` parameter in the invoke request, `Invoke` will either call a helper function or return an error.
159147

160148
In your `chaincode_start.go` file, change the `Invoke` function so that it calls a generic write function.
161149

162150
```go
163-
<<<<<<< HEAD
164-
func (t *SimpleChaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
165-
fmt.Println("invoke is running " + function)
166-
=======
167151
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
168152
fmt.Println("invoke is running " + function)
169-
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
170153

171154
// Handle different functions
172155
if function == "init" {
@@ -183,24 +166,6 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function stri
183166
Now that it's looking for `write` let's make that function somewhere in your `chaincode_start.go` file.
184167

185168
```go
186-
<<<<<<< HEAD
187-
func (t *SimpleChaincode) write(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
188-
var key, value string
189-
var err error
190-
fmt.Println("running write()")
191-
192-
if len(args) != 2 {
193-
return nil, errors.New("Incorrect number of arguments. Expecting 2\. name of the key and value to set")
194-
}
195-
196-
key = args[0] //rename for fun
197-
value = args[1]
198-
err = stub.PutState(key, []byte(value)) //write the variable into the chaincode state
199-
if err != nil {
200-
return nil, err
201-
}
202-
return nil, nil
203-
=======
204169
func (t *SimpleChaincode) write(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {
205170
var key, value string
206171
var err error
@@ -217,32 +182,20 @@ func (t *SimpleChaincode) write(stub shim.ChaincodeStubInterface, args []string)
217182
return nil, err
218183
}
219184
return nil, nil
220-
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
221185
}
222186
```
223187

224188
You're probably thinking that this `write` function looks similar to `Init`. It is very similar. Both functions check for a certain number of arguments, and then write a key/value pair to the ledger. However, you'll notice that `write` uses two arguments, allowing you to pass in both the key and the value for the call to `PutState`. Basically, this function allows you to store any key/value pair you want into the blockchain ledger.
225-
<<<<<<< HEAD
226-
227-
### Query()
228-
229-
=======
230189

231190
### Query()
232191

233-
>>>>>>> 87d7fc6... Fixed a few of the paths to include 'src', and added the branching option to the 'git clone'
234192
As the name implies, `Query` is called whenever you query your chaincode's state. Queries do not result in blocks being added to the chain, and you cannot use functions like `PutState` inside of `Query` or any helper functions it calls. You will use `Query` to read the value of your chaincode state's key/value pairs.
235193

236194
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`.
237195

238196
```go
239-
<<<<<<< HEAD
240-
func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
241-
fmt.Println("query is running " + function)
242-
=======
243197
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
244198
fmt.Println("query is running " + function)
245-
>>>>>>> 4fea23b9bedde404858f7ee58cd33f2f7433dd4b
246199

247200
// Handle different functions
248201
if function == "read" { //read a variable

0 commit comments

Comments
 (0)