本文整理汇总了Golang中github.com/hyperledger/fabric/core/util.ToChaincodeArgs函数的典型用法代码示例。如果您正苦于以下问题:Golang ToChaincodeArgs函数的具体用法?Golang ToChaincodeArgs怎么用?Golang ToChaincodeArgs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ToChaincodeArgs函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Query
// Query callback representing the query of a chaincode
func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
if function != "query" {
return nil, errors.New("Invalid query function name. Expecting \"query\"")
}
var sum string // Sum entity
var Aval, Bval, sumVal int // value of sum entity - to be computed
var err error
// Can query another chaincode within query, but cannot put state or invoke another chaincode (in transaction context)
if len(args) != 2 {
return nil, errors.New("Incorrect number of arguments. Expecting 2")
}
chaincodeURL := args[0]
sum = args[1]
// Query chaincode_example02
f := "query"
queryArgs := util.ToChaincodeArgs(f, "a")
response, err := stub.QueryChaincode(chaincodeURL, queryArgs)
if err != nil {
errStr := fmt.Sprintf("Failed to query chaincode. Got error: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
Aval, err = strconv.Atoi(string(response))
if err != nil {
errStr := fmt.Sprintf("Error retrieving state from ledger for queried chaincode: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
queryArgs = util.ToChaincodeArgs(f, "b")
response, err = stub.QueryChaincode(chaincodeURL, queryArgs)
if err != nil {
errStr := fmt.Sprintf("Failed to query chaincode. Got error: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
Bval, err = strconv.Atoi(string(response))
if err != nil {
errStr := fmt.Sprintf("Error retrieving state from ledger for queried chaincode: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
// Compute sum
sumVal = Aval + Bval
fmt.Printf("Query chaincode successful. Got sum %d\n", sumVal)
jsonResp := "{\"Name\":\"" + sum + "\",\"Value\":\"" + strconv.Itoa(sumVal) + "\"}"
fmt.Printf("Query Response:%s\n", jsonResp)
return []byte(strconv.Itoa(sumVal)), nil
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:55,代码来源:chaincode_example05.go
示例2: invoke
// Invoke queries another chaincode and updates its own state
func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) {
var sum string // Sum entity
var Aval, Bval, sumVal int // value of sum entity - to be computed
var err error
if len(args) != 2 {
return nil, errors.New("Incorrect number of arguments. Expecting 2")
}
chaincodeURL := args[0] // Expecting "github.com/hyperledger/fabric/core/example/chaincode/chaincode_example02"
sum = args[1]
// Query chaincode_example02
f := "query"
queryArgs := util.ToChaincodeArgs(f, "a")
response, err := stub.InvokeChaincode(chaincodeURL, queryArgs)
if err != nil {
errStr := fmt.Sprintf("Failed to query chaincode. Got error: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
Aval, err = strconv.Atoi(string(response))
if err != nil {
errStr := fmt.Sprintf("Error retrieving state from ledger for queried chaincode: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
queryArgs = util.ToChaincodeArgs(f, "b")
response, err = stub.InvokeChaincode(chaincodeURL, queryArgs)
if err != nil {
errStr := fmt.Sprintf("Failed to query chaincode. Got error: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
Bval, err = strconv.Atoi(string(response))
if err != nil {
errStr := fmt.Sprintf("Error retrieving state from ledger for queried chaincode: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
// Compute sum
sumVal = Aval + Bval
// Write sumVal back to the ledger
err = stub.PutState(sum, []byte(strconv.Itoa(sumVal)))
if err != nil {
return nil, err
}
fmt.Printf("Invoke chaincode successful. Got sum %d\n", sumVal)
return []byte(strconv.Itoa(sumVal)), nil
}
开发者ID:hyperledger,项目名称:fabric,代码行数:55,代码来源:chaincode_example05.go
示例3: iq
//helper
func (p *PassthruChaincode) iq(invoke bool, stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
if function == "" {
return nil, errors.New("Chaincode ID not provided")
}
chaincodeID := function
if invoke {
return stub.InvokeChaincode(chaincodeID, util.ToChaincodeArgs(args...))
}
return stub.QueryChaincode(chaincodeID, util.ToChaincodeArgs(args...))
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:12,代码来源:passthru.go
示例4: TestDeployAndUpgrade
// TestUpgradeAndInvoke deploys chaincode_example01, upgrade it with chaincode_example02, then invoke it
func TestDeployAndUpgrade(t *testing.T) {
chainID := util.GetTestChainID()
var ctxt = context.Background()
url1 := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"
url2 := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
chaincodeID1 := &pb.ChaincodeID{Path: url1, Name: "upgradeex01"}
chaincodeID2 := &pb.ChaincodeID{Path: url2, Name: "upgradeex01"}
f := "init"
argsDeploy := util.ToChaincodeArgs(f, "a", "100", "b", "200")
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID1, CtorMsg: &pb.ChaincodeInput{Args: argsDeploy}}
cccid1 := chaincode.NewCCContext(chainID, "upgradeex01", "", "", false, nil)
cccid2 := chaincode.NewCCContext(chainID, "upgradeex02", "", "", false, nil)
resp, prop, err := deploy(endorserServer, chainID, spec, nil)
chaincodeName := spec.ChaincodeID.Name
if err != nil {
t.Fail()
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
t.Logf("Error deploying <%s>: %s", chaincodeName, err)
return
}
err = endorserServer.(*Endorser).commitTxSimulation(prop, chainID, signer, resp)
if err != nil {
t.Fail()
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
t.Logf("Error committing <%s>: %s", chaincodeName, err)
return
}
argsUpgrade := util.ToChaincodeArgs(f, "a", "150", "b", "300")
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID2, CtorMsg: &pb.ChaincodeInput{Args: argsUpgrade}}
resp, prop, err = upgrade(endorserServer, chainID, spec, nil)
if err != nil {
t.Fail()
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
t.Logf("Error upgrading <%s>: %s", chaincodeName, err)
return
}
fmt.Printf("Upgrade test passed\n")
t.Logf("Upgrade test passed")
chaincode.GetChain().Stop(ctxt, cccid1, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID1}})
chaincode.GetChain().Stop(ctxt, cccid2, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID2}})
}
开发者ID:hyperledger,项目名称:fabric,代码行数:54,代码来源:endorser_test.go
示例5: TestRangeQuery
// Test the invocation of a transaction.
func TestRangeQuery(t *testing.T) {
//TODO enable after ledger enables RangeQuery
t.Skip()
chainID := util.GetTestChainID()
lis, err := initPeer(chainID)
if err != nil {
t.Fail()
t.Logf("Error creating peer: %s", err)
}
defer finitPeer(lis, chainID)
var ctxt = context.Background()
url := "github.com/hyperledger/fabric/examples/chaincode/go/map"
cID := &pb.ChaincodeID{Name: "tmap", Path: url}
f := "init"
args := util.ToChaincodeArgs(f)
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: args}}
cccid := NewCCContext(chainID, "tmap", "", "", false, nil)
_, err = deploy(ctxt, cccid, spec)
chaincodeID := spec.ChaincodeID.Name
if err != nil {
t.Fail()
t.Logf("Error initializing chaincode %s(%s)", chaincodeID, err)
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
// Invoke second chaincode, which will inturn invoke the first chaincode
f = "keys"
args = util.ToChaincodeArgs(f)
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: args}}
_, _, _, err = invoke(ctxt, chainID, spec)
if err != nil {
t.Fail()
t.Logf("Error invoking <%s>: %s", chaincodeID, err)
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}
开发者ID:hyperledger,项目名称:fabric,代码行数:51,代码来源:exectransaction_test.go
示例6: invokeExample02Transaction
// Invoke chaincode_example02
func invokeExample02Transaction(ctxt context.Context, cccid *CCContext, cID *pb.ChaincodeID, args []string, destroyImage bool) error {
f := "init"
argsDeploy := util.ToChaincodeArgs(f, "a", "100", "b", "200")
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: argsDeploy}}
_, err := deploy(ctxt, cccid, spec)
chaincodeID := spec.ChaincodeID.Name
if err != nil {
return fmt.Errorf("Error deploying <%s>: %s", chaincodeID, err)
}
time.Sleep(time.Second)
if destroyImage {
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
dir := container.DestroyImageReq{CCID: ccintf.CCID{ChaincodeSpec: spec, NetworkID: theChaincodeSupport.peerNetworkID, PeerID: theChaincodeSupport.peerID, ChainID: cccid.ChainID}, Force: true, NoPrune: true}
_, err = container.VMCProcess(ctxt, container.DOCKER, dir)
if err != nil {
err = fmt.Errorf("Error destroying image: %s", err)
return err
}
}
f = "invoke"
invokeArgs := append([]string{f}, args...)
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs(invokeArgs...)}}
_, uuid, _, err := invoke(ctxt, cccid.ChainID, spec)
if err != nil {
return fmt.Errorf("Error invoking <%s>: %s", cccid.Name, err)
}
cccid.TxID = uuid
err = checkFinalState(cccid)
if err != nil {
return fmt.Errorf("Incorrect final state after transaction for <%s>: %s", chaincodeID, err)
}
// Test for delete state
f = "delete"
delArgs := util.ToChaincodeArgs(f, "a")
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: delArgs}}
_, uuid, _, err = invoke(ctxt, cccid.ChainID, spec)
if err != nil {
return fmt.Errorf("Error deleting state in <%s>: %s", cccid.Name, err)
}
return nil
}
开发者ID:hyperledger,项目名称:fabric,代码行数:50,代码来源:exectransaction_test.go
示例7: deploy
func deploy(admCert crypto.CertificateHandler) error {
// Prepare the spec. The metadata includes the identity of the administrator
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("init")},
Metadata: admCert.GetCertificate(),
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
// First build and get the deployment spec
var ctx = context.Background()
chaincodeDeploymentSpec, err := getDeploymentSpec(ctx, spec)
if err != nil {
return err
}
tid := chaincodeDeploymentSpec.ChaincodeSpec.ChaincodeID.Name
// Now create the Transactions message and send to Peer.
transaction, err := administrator.NewChaincodeDeployTransaction(chaincodeDeploymentSpec, tid)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s ", err)
}
ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
_, _, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s", err)
}
ledger.CommitTxBatch("1", []*pb.Transaction{transaction}, nil, nil)
return err
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:35,代码来源:rbac_test.go
示例8: exec
// Execute multiple transactions and queries.
func exec(ctxt context.Context, chainID string, chaincodeID string, numTrans int, numQueries int) []error {
var wg sync.WaitGroup
errs := make([]error, numTrans+numQueries)
e := func(qnum int) {
defer wg.Done()
var spec *pb.ChaincodeSpec
args := util.ToChaincodeArgs("invoke", "a", "b", "10")
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: chaincodeID}, CtorMsg: &pb.ChaincodeInput{Args: args}}
_, _, _, err := invoke(ctxt, chainID, spec)
if err != nil {
errs[qnum] = fmt.Errorf("Error executing <%s>: %s", chaincodeID, err)
return
}
}
wg.Add(numTrans + numQueries)
//execute transactions sequentially..
go func() {
for i := 0; i < numTrans; i++ {
e(i)
}
}()
wg.Wait()
return errs
}
开发者ID:hyperledger,项目名称:fabric,代码行数:31,代码来源:exectransaction_test.go
示例9: Invoke
// Invoke invokes another chaincode - chaincode_example02, upon receipt of an event and changes event state
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
var event string // Event entity
var eventVal string // State of event
var err error
var amount int
event = args[0]
eventVal = args[1]
chainCodeToCall := args[2] // Get the chaincode to call from the ledger
if eventVal == "middleSchool" {
amount = 2000
} else {
amount = 5000
}
// 转账操作
invokeArgs := util.ToChaincodeArgs("transferAcc", args[3], args[4], strconv.Itoa(amount))
response, err := stub.InvokeChaincode(chainCodeToCall, invokeArgs)
if err != nil {
errStr := fmt.Sprintf("Failed to invoke chaincode. Got error: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
fmt.Printf("Invoke chaincode successful. Got response %s", string(response))
// Write the event state back to the ledger
err = stub.PutState(event, []byte(args[1]))
if err != nil {
return nil, err
}
return nil, nil
}
开发者ID:blzhang,项目名称:zhangbllib,代码行数:36,代码来源:donation.go
示例10: deployInternal
func deployInternal(deployer crypto.Client, adminCert crypto.CertificateHandler) (resp *pb.Response, err error) {
// Prepare the spec. The metadata includes the identity of the administrator
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Path: "github.com/hyperledger/fabric/examples/chaincode/go/asset_management"},
//ChaincodeID: &pb.ChaincodeID{Name: chaincodeName},
CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("init")},
Metadata: adminCert.GetCertificate(),
ConfidentialityLevel: confidentialityLevel,
}
// First build the deployment spec
cds, err := getChaincodeBytes(spec)
if err != nil {
return nil, fmt.Errorf("Error getting deployment spec: %s ", err)
}
// Now create the Transactions message and send to Peer.
transaction, err := deployer.NewChaincodeDeployTransaction(cds, cds.ChaincodeSpec.ChaincodeID.Name)
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s ", err)
}
resp, err = processTransaction(transaction)
appLogger.Debugf("resp [%s]", resp.String())
chaincodeName = cds.ChaincodeSpec.ChaincodeID.Name
appLogger.Debugf("ChaincodeName [%s]", chaincodeName)
return
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:32,代码来源:app_internal.go
示例11: whoIsTheOwner
func whoIsTheOwner(asset string) ([]byte, error) {
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("query", asset)}
// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: chaincodeInput,
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
var ctx = context.Background()
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
tid := chaincodeInvocationSpec.ChaincodeSpec.ChaincodeID.Name
// Now create the Transactions message and send to Peer.
transaction, err := administrator.NewChaincodeQuery(chaincodeInvocationSpec, tid)
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s ", err)
}
ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
result, _, err := chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s", err)
}
ledger.CommitTxBatch("1", []*pb.Transaction{transaction}, nil, nil)
return result, err
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:32,代码来源:asset_management_with_roles_test.go
示例12: executeDeployTransaction
func executeDeployTransaction(t *testing.T, chainID string, name string, url string) {
lis, err := initPeer(chainID)
if err != nil {
t.Fail()
t.Logf("Error creating peer: %s", err)
}
defer finitPeer(lis, chainID)
var ctxt = context.Background()
f := "init"
args := util.ToChaincodeArgs(f, "a", "100", "b", "200")
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: name, Path: url}, CtorMsg: &pb.ChaincodeInput{Args: args}}
cccid := NewCCContext(chainID, name, "", "", false, nil)
_, err = deploy(ctxt, cccid, spec)
chaincodeID := spec.ChaincodeID.Name
if err != nil {
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
t.Fail()
t.Logf("Error deploying <%s>: %s", chaincodeID, err)
return
}
theChaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}
开发者ID:hyperledger,项目名称:fabric,代码行数:29,代码来源:exectransaction_test.go
示例13: InitTestStub
func InitTestStub(funargs ...string) *ChaincodeStub {
stub := ChaincodeStub{}
allargs := util.ToChaincodeArgs(funargs...)
newCI := &pb.ChaincodeInput{Args: allargs}
stub.init(&Handler{}, "TEST-txid", newCI)
return &stub
}
开发者ID:hyperledger,项目名称:fabric,代码行数:7,代码来源:chaincode.go
示例14: exec
// Execute multiple transactions and queries.
func exec(ctxt context.Context, chaincodeID string, numTrans int, numQueries int) []error {
var wg sync.WaitGroup
errs := make([]error, numTrans+numQueries)
e := func(qnum int, typ pb.Transaction_Type) {
defer wg.Done()
var spec *pb.ChaincodeSpec
if typ == pb.Transaction_CHAINCODE_INVOKE {
f := "invoke"
args := util.ToChaincodeArgs(f, "a", "b", "10")
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: chaincodeID}, CtorMsg: &pb.ChaincodeInput{Args: args}}
} else {
f := "query"
args := util.ToChaincodeArgs(f, "a")
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: chaincodeID}, CtorMsg: &pb.ChaincodeInput{Args: args}}
}
_, _, _, err := invoke(ctxt, spec, typ)
if err != nil {
errs[qnum] = fmt.Errorf("Error executing <%s>: %s", chaincodeID, err)
return
}
}
wg.Add(numTrans + numQueries)
//execute transactions sequentially..
go func() {
for i := 0; i < numTrans; i++ {
e(i, pb.Transaction_CHAINCODE_INVOKE)
}
}()
//...but queries in parallel
for i := numTrans; i < numTrans+numQueries; i++ {
go e(i, pb.Transaction_CHAINCODE_QUERY)
}
wg.Wait()
return errs
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:44,代码来源:exectransaction_test.go
示例15: transferOwnership
func transferOwnership(owner crypto.Client, ownerCert crypto.CertificateHandler, fromAttributes string,
newOwnerCert crypto.CertificateHandler, toAttributes string, amount string) error {
// Get a transaction handler to be used to submit the execute transaction
// and bind the chaincode access control logic using the binding
submittingCertHandler, err := owner.GetTCertificateHandlerNext("role")
if err != nil {
return err
}
txHandler, err := submittingCertHandler.GetTransactionHandler()
if err != nil {
return err
}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs(
"transferOwnership",
base64.StdEncoding.EncodeToString(ownerCert.GetCertificate()),
fromAttributes,
base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate()),
toAttributes,
amount)}
// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: chaincodeInput,
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
var ctx = context.Background()
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
tid := chaincodeInvocationSpec.ChaincodeSpec.ChaincodeID.Name
// Now create the Transactions message and send to Peer.
transaction, err := txHandler.NewChaincodeExecute(chaincodeInvocationSpec, tid)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s ", err)
}
ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
_, _, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s", err)
}
ledger.CommitTxBatch("1", []*pb.Transaction{transaction}, nil, nil)
return err
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:52,代码来源:asset_management02_test.go
示例16: UnmarshalJSON
// UnmarshalJSON converts the string-based REST/JSON input to
// the []byte-based current ChaincodeInput structure.
func (c *ChaincodeInput) UnmarshalJSON(b []byte) error {
sa := &strArgs{}
err := json.Unmarshal(b, sa)
if err != nil {
return err
}
allArgs := sa.Args
if sa.Function != "" {
allArgs = append([]string{sa.Function}, sa.Args...)
}
c.Args = util.ToChaincodeArgs(allArgs...)
return nil
}
开发者ID:hyperledger,项目名称:fabric,代码行数:15,代码来源:chaincodeunmarshall.go
示例17: executeDeployTransaction
func executeDeployTransaction(t *testing.T, url string) {
var opts []grpc.ServerOption
if viper.GetBool("peer.tls.enabled") {
creds, err := credentials.NewServerTLSFromFile(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file"))
if err != nil {
grpclog.Fatalf("Failed to generate credentials %v", err)
}
opts = []grpc.ServerOption{grpc.Creds(creds)}
}
grpcServer := grpc.NewServer(opts...)
viper.Set("peer.fileSystemPath", "/var/hyperledger/test/tmpdb")
//lis, err := net.Listen("tcp", viper.GetString("peer.address"))
//use a different address than what we usually use for "peer"
//we override the peerAddress set in chaincode_support.go
peerAddress := "0.0.0.0:21212"
lis, err := net.Listen("tcp", peerAddress)
if err != nil {
t.Fail()
t.Logf("Error starting peer listener %s", err)
return
}
getPeerEndpoint := func() (*pb.PeerEndpoint, error) {
return &pb.PeerEndpoint{ID: &pb.PeerID{Name: "testpeer"}, Address: peerAddress}, nil
}
ccStartupTimeout := time.Duration(chaincodeStartupTimeoutDefault) * time.Millisecond
pb.RegisterChaincodeSupportServer(grpcServer, NewChaincodeSupport(DefaultChain, getPeerEndpoint, false, ccStartupTimeout, nil))
go grpcServer.Serve(lis)
var ctxt = context.Background()
f := "init"
args := util.ToChaincodeArgs(f, "a", "100", "b", "200")
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Path: url}, CtorMsg: &pb.ChaincodeInput{Args: args}}
_, err = deploy(ctxt, spec)
chaincodeID := spec.ChaincodeID.Name
if err != nil {
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
closeListenerAndSleep(lis)
t.Fail()
t.Logf("Error deploying <%s>: %s", chaincodeID, err)
return
}
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
closeListenerAndSleep(lis)
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:51,代码来源:exectransaction_test.go
示例18: transferOwnershipInternal
func transferOwnershipInternal(owner crypto.Client, ownerCert crypto.CertificateHandler, asset string, newOwnerCert crypto.CertificateHandler) (resp *pb.Response, err error) {
// Get a transaction handler to be used to submit the execute transaction
// and bind the chaincode access control logic using the binding
submittingCertHandler, err := owner.GetTCertificateHandlerNext()
if err != nil {
return nil, err
}
txHandler, err := submittingCertHandler.GetTransactionHandler()
if err != nil {
return nil, err
}
binding, err := txHandler.GetBinding()
if err != nil {
return nil, err
}
chaincodeInput := &pb.ChaincodeInput{
Args: util.ToChaincodeArgs("transfer", asset, base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())),
}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return nil, err
}
// Access control. Owner signs chaincodeInputRaw || binding to confirm his identity
sigma, err := ownerCert.Sign(append(chaincodeInputRaw, binding...))
if err != nil {
return nil, err
}
// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: chaincodeName},
CtorMsg: chaincodeInput,
Metadata: sigma, // Proof of identity
ConfidentialityLevel: confidentialityLevel,
}
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
// Now create the Transactions message and send to Peer.
transaction, err := txHandler.NewChaincodeExecute(chaincodeInvocationSpec, util.GenerateUUID())
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s ", err)
}
return processTransaction(transaction)
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:51,代码来源:app_internal.go
示例19: userCreatesAChaincodeSpecOfTypeForChaincodeWithArgs
func (b *BDDContext) userCreatesAChaincodeSpecOfTypeForChaincodeWithArgs(enrollID, ccSpecAlias, ccType, chaincodePath string, argsTable *gherkin.DataTable) error {
userRegistration, err := b.GetUserRegistration(enrollID)
if err != nil {
return err
}
args, err := b.GetArgsForUser(argsTable.Rows[1].Cells, userRegistration)
//fmt.Printf("Args for user: %v, with err = %s", args, err)
ccSpec := createChaincodeSpec(ccType, chaincodePath, util.ToChaincodeArgs(args...))
userRegistration.lastResult = ccSpec
userRegistration.tags[ccSpecAlias] = userRegistration.lastResult
return nil
}
开发者ID:hyperledger,项目名称:fabric,代码行数:14,代码来源:context_endorser.go
示例20: TestDeployAndInvoke
// TestDeployAndInvoke deploys and invokes chaincode_example01
func TestDeployAndInvoke(t *testing.T) {
chainID := util.GetTestChainID()
var ctxt = context.Background()
url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"
chaincodeID := &pb.ChaincodeID{Path: url, Name: "ex01"}
args := []string{"10"}
f := "init"
argsDeploy := util.ToChaincodeArgs(f, "a", "100", "b", "200")
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID, CtorMsg: &pb.ChaincodeInput{Args: argsDeploy}}
cccid := chaincode.NewCCContext(chainID, "ex01", "", "", false, nil)
resp, prop, err := deploy(endorserServer, chainID, spec, nil)
chaincodeID1 := spec.ChaincodeID.Name
if err != nil {
t.Fail()
t.Logf("Error deploying <%s>: %s", chaincodeID1, err)
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
return
}
err = endorserServer.(*Endorser).commitTxSimulation(prop, chainID, signer, resp)
if err != nil {
t.Fail()
t.Logf("Error committing <%s>: %s", chaincodeID1, err)
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
return
}
f = "invoke"
invokeArgs := append([]string{f}, args...)
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID, CtorMsg: &pb.ChaincodeInput{Args: util.ToChaincodeArgs(invokeArgs...)}}
resp, err = invoke(chainID, spec)
if err != nil {
t.Fail()
t.Logf("Error invoking transaction: %s", err)
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
return
}
fmt.Printf("Invoke test passed\n")
t.Logf("Invoke test passed")
chaincode.GetChain().Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: chaincodeID}})
}
开发者ID:hyperledger,项目名称:fabric,代码行数:49,代码来源:endorser_test.go
注:本文中的github.com/hyperledger/fabric/core/util.ToChaincodeArgs函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论