Commit 722ac307 authored by Gabor Hosszu's avatar Gabor Hosszu
Browse files

Use stub to get arguments in chaincodes



Change-Id: I397f11320be2dc1225b9be6ef089a080e94986f1
Signed-off-by: default avatarGabor Hosszu <gabor@digitalasset.com>
parent eae02813
......@@ -30,7 +30,7 @@ type SimpleChaincode struct {
}
// Init create tables for tests
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
// Create table one
err := createTableOne(stub)
if err != nil {
......@@ -60,8 +60,8 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string
// Invoke callback representing the invocation of a chaincode
// This chaincode will manage two accounts A and B and will transfer X units from A to B upon invoke
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
switch function {
case "insertRowTableOne":
......@@ -286,7 +286,8 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function stri
}
// Query callback representing the query of a chaincode
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
switch function {
case "getRowTableOne":
......
......@@ -51,14 +51,15 @@ func (t *SystemChaincode) getLedger() ledgerHandler {
}
// Init initailizes the system chaincode
func (t *SystemChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SystemChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
logger.SetLevel(shim.LogDebug)
logger.Debugf("NOOP INIT")
return nil, nil
}
// Invoke runs an invocation on the system chaincode
func (t *SystemChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SystemChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
args := stub.GetStringArgs()
if len(args) != 1 {
return nil, errors.New("Noop execute operation must have one single argument.")
}
......@@ -67,7 +68,8 @@ func (t *SystemChaincode) Invoke(stub shim.ChaincodeStubInterface, function stri
}
// Query callback representing the query of a chaincode
func (t *SystemChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SystemChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
switch function {
case "getTran":
if len(args) < 1 {
......
......@@ -21,6 +21,7 @@ import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/protos"
)
......@@ -39,7 +40,8 @@ func TestMocking(t *testing.T) {
func TestInvokeUnsupported(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Invoke(nil, "unsupported_operation", []string{"arg1", "arg2"})
stub := shim.InitTestStub("unsupported_operation", "arg1", "arg2")
var res, err = noop.Invoke(stub)
if res != nil || err == nil {
t.Errorf("Invoke has to return nil and error when called with unsupported operation!")
}
......@@ -47,7 +49,8 @@ func TestInvokeUnsupported(t *testing.T) {
func TestInvokeExecuteNotEnoughArgs(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Invoke(nil, "execute", []string{})
stub := shim.InitTestStub()
var res, err = noop.Invoke(stub)
if res != nil || err == nil {
t.Errorf("Invoke.execute has to indicate error if called with less than one arguments!")
}
......@@ -55,7 +58,8 @@ func TestInvokeExecuteNotEnoughArgs(t *testing.T) {
func TestInvokeExecuteOneArgReturnsNothing(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Invoke(nil, "execute", []string{"arg1"})
stub := shim.InitTestStub("arg1")
var res, err = noop.Invoke(stub)
if res != nil || err != nil {
t.Errorf("Invoke.execute has to return nil with no error.")
}
......@@ -63,7 +67,8 @@ func TestInvokeExecuteOneArgReturnsNothing(t *testing.T) {
func TestInvokeExecuteMoreArgsReturnsError(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Invoke(nil, "execute", []string{"arg1", "arg2"})
stub := shim.InitTestStub("arg1", "arg2")
var res, err = noop.Invoke(stub)
if res != nil || err == nil {
t.Errorf("Invoke.execute has to return error when called with more than one arguments.")
}
......@@ -71,7 +76,8 @@ func TestInvokeExecuteMoreArgsReturnsError(t *testing.T) {
func TestQueryUnsupported(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Query(nil, "unsupported_operation", []string{"arg1", "arg2"})
stub := shim.InitTestStub("unsupported_operation", "arg1", "arg2")
var res, err = noop.Query(stub)
if res != nil || err == nil {
t.Errorf("Invoke has to return nil and error when called with unsupported operation!")
}
......@@ -79,7 +85,8 @@ func TestQueryUnsupported(t *testing.T) {
func TestQueryGetTranNotEnoughArgs(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Query(nil, "getTran", []string{})
stub := shim.InitTestStub("getTran")
var res, err = noop.Query(stub)
if res != nil || err == nil {
t.Errorf("Invoke has to return nil and error when called with unsupported operation!")
}
......@@ -87,7 +94,8 @@ func TestQueryGetTranNotEnoughArgs(t *testing.T) {
func TestQueryGetTranNonExisting(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Query(nil, "getTran", []string{"noSuchTX"})
stub := shim.InitTestStub("getTran", "noSuchTX")
res, err := noop.Query(stub)
if res != nil || err == nil {
t.Errorf("Invoke has to return nil when called with a non-existent transaction.")
}
......@@ -95,7 +103,8 @@ func TestQueryGetTranNonExisting(t *testing.T) {
func TestQueryGetTranNonExistingWithManyArgs(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Query(nil, "getTran", []string{"noSuchTX", "arg2"})
stub := shim.InitTestStub("getTran", "noSuchTX", "arg2")
res, err := noop.Query(stub)
if res != nil || err == nil {
t.Errorf("Invoke has to return nil when called with a non-existent transaction.")
}
......@@ -103,7 +112,8 @@ func TestQueryGetTranNonExistingWithManyArgs(t *testing.T) {
func TestQueryGetTranExisting(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Query(nil, "getTran", []string{"someTx"})
stub := shim.InitTestStub("getTran", "someTx")
var res, err = noop.Query(stub)
if res == nil || err != nil {
t.Errorf("Invoke has to return a transaction when called with an existing one.")
}
......
......@@ -372,13 +372,14 @@ func TestGopathExecuteDeployTransaction(t *testing.T) {
// Test deploy of a transaction with a chaincode over HTTP.
func TestHTTPExecuteDeployTransaction(t *testing.T) {
t.Skip("Skipping test temporarily.")
// The chaincode used here cannot be from the fabric repo
// itself or it won't be downloaded because it will be found
// in GOPATH, which would defeat the test
testDBWrapper.CleanDB(t)
//executeDeployTransaction(t, "http://github.com/hyperledger/fabric-test-resources/examples/chaincode/go/chaincode_example01")
// forked the above until the ChaincodeStubInterface change is accepted into the fabric-test-resources project
executeDeployTransaction(t, "http://github.com/brad-gorman/fabric-test-resources/examples/chaincode/go/chaincode_example01")
executeDeployTransaction(t, "http://github.com/gabre/fabric-test-resources/examples/chaincode/go/chaincode_example01")
}
// Check the correctness of the final state after transaction execution.
......
......@@ -34,6 +34,7 @@ import (
"github.com/hyperledger/fabric/core/chaincode/shim/crypto/attr"
"github.com/hyperledger/fabric/core/chaincode/shim/crypto/ecdsa"
"github.com/hyperledger/fabric/core/comm"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos"
"github.com/op/go-logging"
"github.com/spf13/viper"
......@@ -244,6 +245,15 @@ func (stub *ChaincodeStub) init(uuid string, secContext *pb.ChaincodeSecurityCon
}
}
func InitTestStub(funargs ...string) *ChaincodeStub {
stub := ChaincodeStub{}
allargs := util.ToChaincodeArgs(funargs...)
newCI := pb.ChaincodeInput{Args: allargs}
pl, _ := proto.Marshal(&newCI)
stub.init("TEST-uuid", &pb.ChaincodeSecurityContext{Payload: pl})
return &stub
}
// --------- Security functions ----------
//CHAINCODE SEC INTERFACE FUNCS TOBE IMPLEMENTED BY ANGELO
......@@ -388,6 +398,17 @@ func (stub *ChaincodeStub) GetStringArgs() []string {
return strargs
}
func (stub *ChaincodeStub) GetFunctionAndParameters() (function string, params []string) {
allargs := stub.GetStringArgs()
function = ""
params = []string{}
if len(allargs) >= 1 {
function = allargs[0]
params = allargs[1:]
}
return
}
// TABLE FUNCTIONALITY
// TODO More comments here with documentation
......
......@@ -223,8 +223,7 @@ func (handler *Handler) handleInit(msg *pb.ChaincodeMessage) {
// Create the ChaincodeStub which the chaincode can use to callback
stub := new(ChaincodeStub)
stub.init(msg.Txid, msg.SecurityContext)
function, params := getFunctionAndParams(stub)
res, err := handler.cc.Init(stub, function, params)
res, err := handler.cc.Init(stub)
// delete isTransaction entry
handler.deleteIsTransaction(msg.Txid)
......@@ -291,8 +290,7 @@ func (handler *Handler) handleTransaction(msg *pb.ChaincodeMessage) {
// Create the ChaincodeStub which the chaincode can use to callback
stub := new(ChaincodeStub)
stub.init(msg.Txid, msg.SecurityContext)
function, params := getFunctionAndParams(stub)
res, err := handler.cc.Invoke(stub, function, params)
res, err := handler.cc.Invoke(stub)
// delete isTransaction entry
handler.deleteIsTransaction(msg.Txid)
......@@ -339,8 +337,7 @@ func (handler *Handler) handleQuery(msg *pb.ChaincodeMessage) {
// Create the ChaincodeStub which the chaincode can use to callback
stub := new(ChaincodeStub)
stub.init(msg.Txid, msg.SecurityContext)
function, params := getFunctionAndParams(stub)
res, err := handler.cc.Query(stub, function, params)
res, err := handler.cc.Query(stub)
// delete isTransaction entry
handler.deleteIsTransaction(msg.Txid)
......@@ -907,14 +904,3 @@ func filterError(errFromFSMEvent error) error {
}
return nil
}
func getFunctionAndParams(stub ChaincodeStubInterface) (function string, params []string) {
allargs := stub.GetStringArgs()
function = ""
params = []string{}
if len(allargs) >= 1 {
function = allargs[0]
params = allargs[1:]
}
return
}
......@@ -28,15 +28,15 @@ import (
type Chaincode interface {
// Init is called during Deploy transaction after the container has been
// established, allowing the chaincode to initialize its internal data
Init(stub ChaincodeStubInterface, function string, args []string) ([]byte, error)
Init(stub ChaincodeStubInterface) ([]byte, error)
// Invoke is called for every Invoke transactions. The chaincode may change
// its state variables
Invoke(stub ChaincodeStubInterface, function string, args []string) ([]byte, error)
Invoke(stub ChaincodeStubInterface) ([]byte, error)
// Query is called for Query transactions. The chaincode may only read
// (but not modify) its state variables and return the result
Query(stub ChaincodeStubInterface, function string, args []string) ([]byte, error)
Query(stub ChaincodeStubInterface) ([]byte, error)
}
// ChaincodeStubInterface is used by deployable chaincode apps to access and modify their ledgers
......@@ -47,6 +47,10 @@ type ChaincodeStubInterface interface {
// Get the arguments to the stub call as a string array
GetStringArgs() []string
// Get the function which is the first argument and the rest of the arguments
// as parameters
GetFunctionAndParameters() (string, []string)
// InvokeChaincode locally calls the specified chaincode `Invoke` using the
// same transaction context; that is, chaincode calling chaincode doesn't
// create a new transaction message.
......
......@@ -72,6 +72,17 @@ func (stub *MockStub) GetStringArgs() []string {
return strargs
}
func (stub *MockStub) GetFunctionAndParameters() (function string, params []string) {
allargs := stub.GetStringArgs()
function = ""
params = []string{}
if len(allargs) >= 1 {
function = allargs[0]
params = allargs[1:]
}
return
}
// Used to indicate to a chaincode that it is part of a transaction.
// This is important when chaincodes invoke each other.
// MockStub doesn't support concurrent transactions at present.
......@@ -95,7 +106,7 @@ func (stub *MockStub) MockPeerChaincode(invokableChaincodeName string, otherStub
func (stub *MockStub) MockInit(uuid string, function string, args []string) ([]byte, error) {
stub.args = getBytes(function, args)
stub.MockTransactionStart(uuid)
bytes, err := stub.cc.Init(stub, function, args)
bytes, err := stub.cc.Init(stub)
stub.MockTransactionEnd(uuid)
return bytes, err
}
......@@ -104,7 +115,7 @@ func (stub *MockStub) MockInit(uuid string, function string, args []string) ([]b
func (stub *MockStub) MockInvoke(uuid string, function string, args []string) ([]byte, error) {
stub.args = getBytes(function, args)
stub.MockTransactionStart(uuid)
bytes, err := stub.cc.Invoke(stub, function, args)
bytes, err := stub.cc.Invoke(stub)
stub.MockTransactionEnd(uuid)
return bytes, err
}
......@@ -113,7 +124,7 @@ func (stub *MockStub) MockInvoke(uuid string, function string, args []string) ([
func (stub *MockStub) MockQuery(function string, args []string) ([]byte, error) {
stub.args = getBytes(function, args)
// no transaction needed for queries
bytes, err := stub.cc.Query(stub, function, args)
bytes, err := stub.cc.Query(stub)
return bytes, err
}
......
......@@ -28,7 +28,7 @@ type SampleSysCC struct {
// Init initializes the sample system chaincode by storing the key and value
// arguments passed in as parameters
func (t *SampleSysCC) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SampleSysCC) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
//as system chaincodes do not take part in consensus and are part of the system,
//best practice to do nothing (or very little) in Init.
......@@ -37,7 +37,8 @@ func (t *SampleSysCC) Init(stub shim.ChaincodeStubInterface, function string, ar
// Invoke gets the supplied key and if it exists, updates the key with the newly
// supplied value.
func (t *SampleSysCC) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SampleSysCC) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
_, args := stub.GetFunctionAndParameters()
var key, val string // Entities
if len(args) != 2 {
......@@ -64,7 +65,8 @@ func (t *SampleSysCC) Invoke(stub shim.ChaincodeStubInterface, function string,
}
// Query callback representing the query of a chaincode
func (t *SampleSysCC) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SampleSysCC) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
if function != "getval" {
return nil, errors.New("Invalid query function name. Expecting \"getval\"")
}
......
......@@ -38,7 +38,8 @@ type AssetManagementChaincode struct {
// Init method will be called during deployment.
// The deploy transaction metadata is supposed to contain the administrator cert
func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
myLogger.Debug("Init Chaincode...")
if len(args) != 0 {
return nil, errors.New("Incorrect number of arguments. Expecting 0")
......@@ -242,8 +243,8 @@ func (t *AssetManagementChaincode) isCaller(stub shim.ChaincodeStubInterface, ce
// "transfer(asset, newOwner)": to transfer the ownership of an asset. Only the owner of the specific
// asset can call this function.
// An asset is any string to identify it. An owner is representated by one of his ECert/TCert.
func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
// Handle different functions
if function == "assign" {
// Assign ownership
......@@ -260,7 +261,8 @@ func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface, func
// Supported functions are the following:
// "query(asset)": returns the owner of the asset.
// Anyone can invoke this function.
func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
myLogger.Debugf("Query [%s]", function)
if function != "query" {
......
......@@ -190,7 +190,8 @@ func (t *AssetManagementChaincode) getBalance(stub shim.ChaincodeStubInterface,
}
// Init initialization, this method will create asset despository in the chaincode state
func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
myLogger.Debugf("********************************Init****************************************")
myLogger.Info("[AssetManagementChaincode] Init")
......@@ -203,7 +204,8 @@ func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface, functi
// Invoke method is the interceptor of all invocation transactions, its job is to direct
// invocation transactions to intended APIs
func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
myLogger.Debugf("********************************Invoke****************************************")
// Handle different functions
......@@ -220,7 +222,8 @@ func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface, func
// Query method is the interceptor of all invocation transactions, its job is to direct
// query transactions to intended APIs, and return the result back to callers
func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
myLogger.Debugf("********************************Query****************************************")
// Handle different functions
......
......@@ -57,7 +57,8 @@ type AssetManagementChaincode struct {
}
// Init initialization
func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
myLogger.Info("[AssetManagementChaincode] Init")
if len(args) != 0 {
return nil, errors.New("Incorrect number of arguments. Expecting 0")
......@@ -218,8 +219,8 @@ func (t *AssetManagementChaincode) transfer(stub shim.ChaincodeStubInterface, ar
}
// Invoke runs callback representing the invocation of a chaincode
func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
// Handle different functions
if function == "assign" {
// Assign ownership
......@@ -233,7 +234,8 @@ func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface, func
}
// Query callback representing the query of a chaincode
func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
if function != "query" {
return nil, errors.New("Invalid query function name. Expecting \"query\"")
}
......
......@@ -49,7 +49,8 @@ func (t *Attributes2State) setStateToAttributes(stub shim.ChaincodeStubInterface
// Init intializes the chaincode by reading the transaction attributes and storing
// the attrbute values in the state
func (t *Attributes2State) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *Attributes2State) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
err := t.setStateToAttributes(stub, args)
if err != nil {
return nil, err
......@@ -58,7 +59,8 @@ func (t *Attributes2State) Init(stub shim.ChaincodeStubInterface, function strin
}
// Invoke takes two arguements, a key and value, and stores these in the state
func (t *Attributes2State) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *Attributes2State) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
if function == "delete" {
return nil, t.delete(stub, args)
}
......@@ -105,7 +107,8 @@ func (t *Attributes2State) delete(stub shim.ChaincodeStubInterface, args []strin
}
// Query callback representing the query of a chaincode
func (t *Attributes2State) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *Attributes2State) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
if function != "read" {
return nil, errors.New("Invalid query function name. Expecting \"read\"")
}
......
......@@ -30,13 +30,14 @@ type AuthorizableCounterChaincode struct {
}
//Init the chaincode asigned the value "0" to the counter in the state.
func (t *AuthorizableCounterChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AuthorizableCounterChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
err := stub.PutState("counter", []byte("0"))
return nil, err
}
//Invoke Transaction makes increment counter
func (t *AuthorizableCounterChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AuthorizableCounterChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, _ := stub.GetFunctionAndParameters()
if function != "increment" {
return nil, errors.New("Invalid invoke function name. Expecting \"increment\"")
}
......@@ -62,7 +63,8 @@ func (t *AuthorizableCounterChaincode) Invoke(stub shim.ChaincodeStubInterface,
}
// Query callback representing the query of a chaincode
func (t *AuthorizableCounterChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *AuthorizableCounterChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, _ := stub.GetFunctionAndParameters()
if function != "read" {
return nil, errors.New("Invalid query function name. Expecting \"read\"")
}
......
......@@ -33,9 +33,9 @@ var Aval, Bval, X int
// Init callback representing the invocation of a chaincode
// This chaincode will manage two accounts A and B and will transfer X units from A to B upon invoke
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
var err error
_, args := stub.GetFunctionAndParameters()
if len(args) != 4 {
return nil, errors.New("Incorrect number of arguments. Expecting 4")
}
......@@ -69,7 +69,8 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string
return nil, nil
}
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
_, args := stub.GetFunctionAndParameters()
// Transaction makes payment of X units from A to B
var err error
X, err = strconv.Atoi(args[0])
......@@ -84,7 +85,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function stri
}
// Query callback representing the query of a chaincode
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
return nil, nil
}
......
......@@ -34,7 +34,8 @@ import (
type SimpleChaincode struct {
}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
_, args := stub.GetFunctionAndParameters()
var A, B string // Entities
var Aval, Bval int // Asset holdings
var err error
......@@ -71,7 +72,8 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string
}
// Transaction makes payment of X units from A to B
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
if function == "delete" {
// Deletes an entity from its state
return t.delete(stub, args)
......@@ -147,7 +149,8 @@ func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string
}
// Query callback representing the query of a chaincode
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) {
function, args := stub.GetFunctionAndParameters()
if function != "query" {
return nil, errors.New("Invalid query function name. Expecting \"query\"")
}
......
......@@ -30,11 +30,11 @@ type SimpleChaincode struct {
}
// Init takes a string and int. These are stored as a key/value pair in the state
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) {
var A string // Entity
var Aval int // Asset holding
var err error
_, args := stub.GetFunctionAndParameters()