version de préprod

This commit is contained in:
projet 2019-04-03 19:55:37 +02:00
parent 06dfc409b5
commit 60b5414944

View file

@ -54,11 +54,11 @@ type owner struct {
}
type wallet struct {
ObjectType string `json:"docType"` //docType is used to distinguish the various type$
Id string `json:"id"` //the fieldtags are needed to keep case from bounci$
WalletType string `json:"walletType"`
Sold int `json:"sold"`
Owner string `json:"owner"`
ObjectType string `json:"docType"` //docType is used to distinguish the various type$
Id string `json:"id"` //the fieldtags are needed to keep case from bounci$
WalletType string `json:"walletType"`
Sold float64 `json:"sold"`
Owner string `json:"owner"`
}
@ -148,7 +148,10 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
} else if function == "getHistoryForWallet" {
// make a transaction of X units from a wallet to an other
return t.getHistoryForWallet(stub, args)
}
} else if function == "getAllWallets" {
// get All Wallets
return t.getAllWallets(stub, args)
}
return shim.Error("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\" \"register\"")
}
@ -526,7 +529,7 @@ func (t *SimpleChaincode) initWallet(stub shim.ChaincodeStubInterface, args []st
walletId := args[0]
walletType := strings.ToLower(args[1])
owner := args[2]
sold := 0
sold := 0.0
//authorized_by_association := args[4]
if err != nil {
@ -689,7 +692,7 @@ func (t *SimpleChaincode) transferWallet(stub shim.ChaincodeStubInterface, args
}
walletId := args[0]
newOwner := strings.ToLower(args[1])
newOwner := args[1]
fmt.Println("- start transferWallet ", walletId, newOwner)
// ==== Check if user already exists ====
@ -740,7 +743,7 @@ func (t *SimpleChaincode) setSoldOnWallet(stub shim.ChaincodeStubInterface, args
}
walletId := args[0]
newSold, err := strconv.Atoi(args[1])
newSold, err := strconv.ParseFloat(args[1], 64)
fmt.Println("- start setSoldOnWallet ", walletId, newSold)
// ==== Check if wallet already exists ====
@ -780,7 +783,7 @@ func (t *SimpleChaincode) transaction(stub shim.ChaincodeStubInterface, args []s
walletId := args[0]
walletTargetId := args[1]
transactionValue, err := strconv.Atoi(args[2])
transactionValue, err := strconv.ParseFloat(args[2], 64)
fmt.Println("- start transaction ", walletId, transactionValue)
@ -920,6 +923,14 @@ func (t *SimpleChaincode) getHistoryForWallet(stub shim.ChaincodeStubInterface,
}
defer resultsIterator.Close()
if resultsIterator.HasNext() {
modification, err := resultsIterator.Next()
if err != nil {
return shim.Error(err.Error())
}
fmt.Println("Returning information related to", string(modification.Value))
}
// buffer is a JSON array containing historic values for the marble
var buffer bytes.Buffer
buffer.WriteString("[")
@ -940,6 +951,7 @@ func (t *SimpleChaincode) getHistoryForWallet(stub shim.ChaincodeStubInterface,
buffer.WriteString("\"")
buffer.WriteString(", \"Value\":")
// if it was a delete operation on given key, then we need to set the
//corresponding value null. Else, we will write the response.Value
//as-is (as the Value itself a JSON marble)
@ -970,6 +982,32 @@ func (t *SimpleChaincode) getHistoryForWallet(stub shim.ChaincodeStubInterface,
}
func (t *SimpleChaincode) getAllWallets(stub shim.ChaincodeStubInterface, args []string) pb.Response {
if len(args) < 2 {
return shim.Error("Incorrect number of arguments. Expecting 2")
}
startKey := args[0]
endKey := args[1]
resultsIterator, err := stub.GetStateByRange(startKey, endKey)
if err != nil {
return shim.Error(err.Error())
}
defer resultsIterator.Close()
buffer, err := constructQueryResponseFromIterator(resultsIterator)
if err != nil {
return shim.Error(err.Error())
}
fmt.Printf("- getAllWallets queryResult:\n%s\n", buffer.String())
return shim.Success(buffer.Bytes())
}
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {