forked from Hyperledger-TWGC/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_envelope_gen.go
75 lines (64 loc) · 1.79 KB
/
tx_envelope_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package chainmgmt
import (
"fmt"
"github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/core/ledger/kvledger/benchmark/mocks"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protoutil"
)
const (
dummyChainID = "myChain"
dummyCCName = "myChaincode"
useDummyProposal = true
)
var (
dummyCCID = &pb.ChaincodeID{Name: dummyCCName, Version: "v1"}
dummyProposal *pb.Proposal
mspLcl msp.MSP
signer msp.SigningIdentity
serializedSigner []byte
)
func init() {
mspLcl = mocks.NewNoopMsp()
signer, _ = mspLcl.GetDefaultSigningIdentity()
serializedSigner, _ = signer.Serialize()
dummyProposal, _, _ = protoutil.CreateChaincodeProposal(
common.HeaderType_ENDORSER_TRANSACTION, dummyChainID,
&pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: dummyCCID}},
serializedSigner)
}
func createTxEnv(simulationResults []byte) (*common.Envelope, error) {
var prop *pb.Proposal
var err error
if useDummyProposal {
prop = dummyProposal
} else {
prop, _, err = protoutil.CreateChaincodeProposal(
common.HeaderType_ENDORSER_TRANSACTION,
dummyChainID,
&pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: dummyCCID}},
serializedSigner)
if err != nil {
return nil, err
}
}
presp, err := protoutil.CreateProposalResponse(prop.Header, prop.Payload, nil, simulationResults, nil, dummyCCID, signer)
if err != nil {
return nil, err
}
env, err := protoutil.CreateSignedTx(prop, signer, presp)
if err != nil {
return nil, err
}
return env, nil
}
func panicOnError(err error) {
if err != nil {
panic(fmt.Errorf("Error:%s", err))
}
}