From cc19453a810f66c6bcd255805fe1273d132813b2 Mon Sep 17 00:00:00 2001 From: projet Date: Sat, 6 Apr 2019 20:05:25 +0200 Subject: [PATCH] last debug before prod push --- monnethic_environment_&_strcture_build.go | 10 +++------ monnethic_functions.go | 26 +++++++++++++++++------ monnethic_use_test.go | 21 +++++++++++++++--- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/monnethic_environment_&_strcture_build.go b/monnethic_environment_&_strcture_build.go index bae27f2..4ce41f1 100644 --- a/monnethic_environment_&_strcture_build.go +++ b/monnethic_environment_&_strcture_build.go @@ -24,11 +24,7 @@ package main import ( "bytes" - "encoding/json" "fmt" - "strconv" - "strings" - "time" "github.com/hyperledger/fabric/core/chaincode/shim" 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 { fmt.Println("ex02 Invoke") function, args := stub.GetFunctionAndParameters() - if function == "invoke" { +/* if function == "invoke" { // Make payment of X units from A to B return t.invoke(stub, args) } else if function == "delete" { @@ -80,7 +76,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { } else if function == "register" { // register a new user into the ledger return t.register(stub, args) - } else if function == "registerUser" { + } else*/ if function == "registerUser" { // initiate a new account return t.registerUser(stub, args) } else if function == "readUser" { @@ -201,4 +197,4 @@ func getQueryResultForQueryString(stub shim.ChaincodeStubInterface, queryString fmt.Printf("- getQueryResultForQueryString queryResult:\n%s\n", buffer.String()) return buffer.Bytes(), nil -} \ No newline at end of file +} diff --git a/monnethic_functions.go b/monnethic_functions.go index 8a3061d..2bc009e 100644 --- a/monnethic_functions.go +++ b/monnethic_functions.go @@ -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 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 + "\"}" return shim.Error(jsonResp) } else if valAsbytes == nil { - jsonResp = "{\"Error\":\"Wallet does not exist: " + id + "\"}"* + jsonResp = "{\"Error\":\"Wallet does not exist: " + id + "\"}" 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 valAsbytes, err := stub.GetState(Id) //get the marble from chaincode state if err != nil { - jsonResp = "{\"Error\":\"Failed to get state for " + Id + "\"}"* + jsonResp = "{\"Error\":\"Failed to get state for " + Id + "\"}" return shim.Error(jsonResp) } else if valAsbytes == nil { jsonResp = "{\"Error\":\"Wallet does not exist: " + Id + "\"}" @@ -356,14 +372,12 @@ func (t *SimpleChaincode) deleteWallet(stub shim.ChaincodeStubInterface, args [] return shim.Error(jsonResp) } - err = json.Unmarshal([]byte(valAsbytes), &walletJSON) if err != nil { jsonResp = "{\"Error\":\"Failed to decode JSON of: " + Id + "\"}" return shim.Error(jsonResp) } - err = stub.DelState(Id) //remove the wallet from chaincode state if err != nil { 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()) return shim.Success(buffer.Bytes()) -} \ No newline at end of file +} diff --git a/monnethic_use_test.go b/monnethic_use_test.go index a104d01..9d2afe5 100644 --- a/monnethic_use_test.go +++ b/monnethic_use_test.go @@ -1,5 +1,20 @@ -// Transaction makes payment of X units from A to B -func (t *SimpleChaincode) invoke(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" +) + + +// 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 Aval, Bval int // Asset holdings 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.Success(nil) -} \ No newline at end of file +}