-
Notifications
You must be signed in to change notification settings - Fork 12
/
proposal.go
39 lines (32 loc) · 1.05 KB
/
proposal.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
package golang
import (
"crypto/rand"
"github.com/davidkhala/protoutil"
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
)
func GetRandomNonce() []byte {
key := make([]byte, 24)
_, err := rand.Read(key)
if err != nil {
panic(err)
}
return key
}
func CreateProposal(creator []byte, channel, ccname, version string, transientMap map[string][]byte, args ...string) (proposal *peer.Proposal, txid string, err error) {
var argsInByte [][]byte
for _, arg := range args {
argsInByte = append(argsInByte, []byte(arg))
}
spec := &peer.ChaincodeSpec{
Type: peer.ChaincodeSpec_GOLANG,
ChaincodeId: &peer.ChaincodeID{Name: ccname, Version: version},
Input: &peer.ChaincodeInput{Args: argsInByte},
}
invocation := &peer.ChaincodeInvocationSpec{ChaincodeSpec: spec}
prop, txid, err := protoutil.CreateChaincodeProposalWithTransient(common.HeaderType_ENDORSER_TRANSACTION, channel, invocation, creator, transientMap)
if err != nil {
return nil, "", err
}
return prop, txid, nil
}