This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
forked from s7techlab/hlf-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
proposal.go
54 lines (45 loc) · 1.53 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package proto
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/msp"
)
func NewPeerSignedProposal(proposal []byte, identity msp.SigningIdentity) (*peer.SignedProposal, error) {
signedProposal, err := identity.Sign(proposal)
if err != nil {
return nil, fmt.Errorf(`sign proposal: %w`, err)
}
return &peer.SignedProposal{
ProposalBytes: proposal,
Signature: signedProposal}, nil
}
func NewMarshaledPeerProposal(header []byte, chaincode string, args [][]byte, transientMap map[string][]byte) ([]byte, error) {
payload, err := NewMarshalledChaincodeProposalPayload(chaincode, args, transientMap)
if err != nil {
return nil, fmt.Errorf(`chaincode proposal payload: %w`, err)
}
return proto.Marshal(&peer.Proposal{
Header: header,
Payload: payload,
})
}
func NewMarshalledChaincodeProposalPayload(chaincode string, args [][]byte, transientMap map[string][]byte) ([]byte, error) {
invSpec, err := NewMarshalledPeerChaincodeInvocationSpec(chaincode, args)
if err != nil {
return nil, fmt.Errorf(`invocation spec: %w`, err)
}
return proto.Marshal(&peer.ChaincodeProposalPayload{
Input: invSpec,
TransientMap: transientMap,
})
}
func NewMarshalledPeerChaincodeInvocationSpec(chaincode string, args [][]byte) ([]byte, error) {
spec := &peer.ChaincodeInvocationSpec{
ChaincodeSpec: &peer.ChaincodeSpec{
ChaincodeId: &peer.ChaincodeID{Name: chaincode},
Input: &peer.ChaincodeInput{Args: args},
},
}
return proto.Marshal(spec)
}