last debug before prod push

This commit is contained in:
projet 2019-04-06 20:05:25 +02:00
parent 9c53af96cf
commit cc19453a81
3 changed files with 41 additions and 16 deletions

View file

@ -24,11 +24,7 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"strconv"
"strings"
"time"
"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"
@ -68,7 +64,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
fmt.Println("ex02 Invoke") fmt.Println("ex02 Invoke")
function, args := stub.GetFunctionAndParameters() function, args := stub.GetFunctionAndParameters()
if function == "invoke" { /* if function == "invoke" {
// Make payment of X units from A to B // Make payment of X units from A to B
return t.invoke(stub, args) return t.invoke(stub, args)
} else if function == "delete" { } else if function == "delete" {
@ -80,7 +76,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
} else if function == "register" { } else if function == "register" {
// register a new user into the ledger // register a new user into the ledger
return t.register(stub, args) return t.register(stub, args)
} else if function == "registerUser" { } else*/ if function == "registerUser" {
// initiate a new account // initiate a new account
return t.registerUser(stub, args) return t.registerUser(stub, args)
} else if function == "readUser" { } else if function == "readUser" {
@ -201,4 +197,4 @@ func getQueryResultForQueryString(stub shim.ChaincodeStubInterface, queryString
fmt.Printf("- getQueryResultForQueryString queryResult:\n%s\n", buffer.String()) fmt.Printf("- getQueryResultForQueryString queryResult:\n%s\n", buffer.String())
return buffer.Bytes(), nil return buffer.Bytes(), nil
} }

View file

@ -1,4 +1,20 @@
func (t *SimpleChaincode) registerUser(stub shim.ChaincodeStubInterface, args []string) pb.Response { package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
func (t *SimpleChaincode) registerUser(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var err error var err error
if len(args) != 5 { if len(args) != 5 {
@ -315,7 +331,7 @@ func (t *SimpleChaincode) readWallet(stub shim.ChaincodeStubInterface, args []st
jsonResp = "{\"Error\":\"Failed to get state for " + id + "\"}" jsonResp = "{\"Error\":\"Failed to get state for " + id + "\"}"
return shim.Error(jsonResp) return shim.Error(jsonResp)
} else if valAsbytes == nil { } else if valAsbytes == nil {
jsonResp = "{\"Error\":\"Wallet does not exist: " + id + "\"}"* jsonResp = "{\"Error\":\"Wallet does not exist: " + id + "\"}"
return shim.Error(jsonResp) return shim.Error(jsonResp)
} }
@ -339,7 +355,7 @@ func (t *SimpleChaincode) deleteWallet(stub shim.ChaincodeStubInterface, args []
// to maintain the color~name index, we need to read the marble first and get its color // to maintain the color~name index, we need to read the marble first and get its color
valAsbytes, err := stub.GetState(Id) //get the marble from chaincode state valAsbytes, err := stub.GetState(Id) //get the marble from chaincode state
if err != nil { if err != nil {
jsonResp = "{\"Error\":\"Failed to get state for " + Id + "\"}"* jsonResp = "{\"Error\":\"Failed to get state for " + Id + "\"}"
return shim.Error(jsonResp) return shim.Error(jsonResp)
} else if valAsbytes == nil { } else if valAsbytes == nil {
jsonResp = "{\"Error\":\"Wallet does not exist: " + Id + "\"}" jsonResp = "{\"Error\":\"Wallet does not exist: " + Id + "\"}"
@ -356,14 +372,12 @@ func (t *SimpleChaincode) deleteWallet(stub shim.ChaincodeStubInterface, args []
return shim.Error(jsonResp) return shim.Error(jsonResp)
} }
err = json.Unmarshal([]byte(valAsbytes), &walletJSON) err = json.Unmarshal([]byte(valAsbytes), &walletJSON)
if err != nil { if err != nil {
jsonResp = "{\"Error\":\"Failed to decode JSON of: " + Id + "\"}" jsonResp = "{\"Error\":\"Failed to decode JSON of: " + Id + "\"}"
return shim.Error(jsonResp) return shim.Error(jsonResp)
} }
err = stub.DelState(Id) //remove the wallet from chaincode state err = stub.DelState(Id) //remove the wallet from chaincode state
if err != nil { if err != nil {
return shim.Error("Failed to delete state:" + err.Error()) return shim.Error("Failed to delete state:" + err.Error())
@ -707,4 +721,4 @@ func (t *SimpleChaincode) getAllEntities(stub shim.ChaincodeStubInterface, args
fmt.Printf("- getAllEntities queryResult:\n%s\n", buffer.String()) fmt.Printf("- getAllEntities queryResult:\n%s\n", buffer.String())
return shim.Success(buffer.Bytes()) return shim.Success(buffer.Bytes())
} }

View file

@ -1,5 +1,20 @@
// Transaction makes payment of X units from A to B package main
func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response {
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
// Transaction makes payment of X units from A to B func (t *SimpleChaincode)
invoke(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var A, B string // Entities var A, B string // Entities
var Aval, Bval int // Asset holdings var Aval, Bval int // Asset holdings
var X int // Transaction value var X int // Transaction value
@ -126,4 +141,4 @@ func (t *SimpleChaincode) register(stub shim.ChaincodeStubInterface, args []stri
return shim.Error(err.Error()) return shim.Error(err.Error())
} }
return shim.Success(nil) return shim.Success(nil)
} }