-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skeleton Endorser implemention with a CLI driver
This patch is for https://jira.hyperledger.org/browse/FAB-181, FAB-182. The patch is around endorser.go which implements the basic Endorser service. The "peer deploy ..." and "peer invoke .." CLI driver commands have been modified to redirected to use endorser.ProcessProposal instead of the original "devops" calls. The deploy, invoke (and query) CLI calls are unchanged in non-dev mode from user point of view - but for one difference. The response is a ProposalResponse. In dev mode (ie, when peer is started with --peer-chaincodedev) the deploy command would need to set "CORE_CHAINCODE_MODE=dev" in the "peer chaincode deploy ..." command. This is because, the command now computes the chaincode code just like the SDK as opposed to leaving it to be done by devops in the peer. Example CORE_CHAINCODE_MODE=dev CORE_LOGGING_LEVEL=debug ./peer chaincode deploy -n mycc -c '{"Args":["init","a","100","b","200"]}' Change-Id: Ie6e44cef880bfcbeb7619f135566a7dce9dcdbc2 Signed-off-by: Srinivasan Muralidharan <muralisr@us.ibm.com>
- Loading branch information
Srinivasan Muralidharan
committed
Sep 22, 2016
1 parent
9ec4873
commit ec50ad1
Showing
13 changed files
with
1,180 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package chaincode | ||
|
||
import ( | ||
"golang.org/x/net/context" | ||
|
||
"fmt" | ||
|
||
"github.com/hyperledger/fabric/core/ledger" | ||
"github.com/hyperledger/fabric/core/util" | ||
pb "github.com/hyperledger/fabric/protos" | ||
) | ||
|
||
//create a Transactions - this has to change to Proposal when we move chaincode to use Proposals | ||
func createTx(typ pb.Transaction_Type, ccname string, args [][]byte) (*pb.Transaction, error) { | ||
var tx *pb.Transaction | ||
var err error | ||
uuid := util.GenerateUUID() | ||
spec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: ccname}, CtorMsg: &pb.ChaincodeInput{Args: args}}} | ||
tx, err = pb.NewChaincodeExecute(spec, uuid, typ) | ||
if nil != err { | ||
return nil, err | ||
} | ||
return tx, nil | ||
} | ||
|
||
// ExecuteChaincode executes a given chaincode given chaincode name and arguments | ||
func ExecuteChaincode(typ pb.Transaction_Type, chainname string, ccname string, args [][]byte) ([]byte, error) { | ||
var tx *pb.Transaction | ||
var err error | ||
var b []byte | ||
var lgr *ledger.Ledger | ||
tx, err = createTx(typ, ccname, args) | ||
lgr, err = ledger.GetLedger() | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to get handle to ledger: %s ", err) | ||
} | ||
//TODO - new ledger access will change this call to take a context | ||
lgr.BeginTxBatch("1") | ||
b, _, err = Execute(context.Background(), GetChain(ChainName(chainname)), tx) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error deploying chaincode: %s", err) | ||
} | ||
//TODO - new ledger access will change this call to take a context | ||
lgr.CommitTxBatch("1", []*pb.Transaction{tx}, nil, nil) | ||
|
||
return b, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package endorser | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/op/go-logging" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// Config the config wrapper structure | ||
type Config struct { | ||
} | ||
|
||
func init() { | ||
|
||
} | ||
|
||
// SetupTestLogging setup the logging during test execution | ||
func SetupTestLogging() { | ||
level, err := logging.LogLevel(viper.GetString("logging.peer")) | ||
if err == nil { | ||
// No error, use the setting | ||
logging.SetLevel(level, "main") | ||
logging.SetLevel(level, "server") | ||
logging.SetLevel(level, "peer") | ||
} else { | ||
logging.SetLevel(logging.ERROR, "main") | ||
logging.SetLevel(logging.ERROR, "server") | ||
logging.SetLevel(logging.ERROR, "peer") | ||
} | ||
} | ||
|
||
// SetupTestConfig setup the config during test execution | ||
func SetupTestConfig() { | ||
flag.Parse() | ||
|
||
// Now set the configuration file | ||
viper.SetEnvPrefix("CORE") | ||
viper.AutomaticEnv() | ||
replacer := strings.NewReplacer(".", "_") | ||
viper.SetEnvKeyReplacer(replacer) | ||
viper.SetConfigName("endorser") // name of config file (without extension) | ||
viper.AddConfigPath("./") // path to look for the config file in | ||
err := viper.ReadInConfig() // Find and read the config file | ||
if err != nil { // Handle errors reading the config file | ||
panic(fmt.Errorf("Fatal error config file: %s \n", err)) | ||
} | ||
|
||
SetupTestLogging() | ||
|
||
// Set the number of maxprocs | ||
viper.GetInt("peer.gomaxprocs") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.