-
Notifications
You must be signed in to change notification settings - Fork 70
/
fackEnvelopGenerator.go
61 lines (54 loc) · 1.55 KB
/
fackEnvelopGenerator.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
package trafficGenerator
import (
"github.com/hyperledger-twgc/tape/internal/fabric/protoutil"
"github.com/hyperledger-twgc/tape/pkg/infra"
"github.com/hyperledger-twgc/tape/pkg/infra/basic"
"github.com/opentracing/opentracing-go"
"github.com/hyperledger/fabric-protos-go-apiv2/common"
)
type FackEnvelopGenerator struct {
Num int
Burst int
R float64
Config basic.Config
Crypto infra.Crypto
Envs chan *basic.TracingEnvelope
ErrorCh chan error
}
var nonce = []byte("nonce-abc-12345")
var data = []byte("data")
func (initiator *FackEnvelopGenerator) Start() {
i := 0
for {
if initiator.Num > 0 {
if i == initiator.Num {
return
}
i++
}
creator, _ := initiator.Crypto.Serialize()
txid := protoutil.ComputeTxID(nonce, creator)
payloadBytes, _ := protoutil.GetBytesPayload(&common.Payload{
Header: &common.Header{
ChannelHeader: protoutil.MarshalOrPanic(&common.ChannelHeader{
Type: int32(common.HeaderType_ENDORSER_TRANSACTION),
ChannelId: initiator.Config.Channel,
TxId: txid,
Epoch: uint64(0),
}),
SignatureHeader: protoutil.MarshalOrPanic(&common.SignatureHeader{
Creator: creator,
Nonce: nonce,
}),
},
Data: data,
})
signature, _ := initiator.Crypto.Sign(payloadBytes)
env := &common.Envelope{
Payload: payloadBytes,
Signature: signature,
}
span := opentracing.GlobalTracer().StartSpan("integrator for endorsements ", opentracing.Tag{Key: "txid", Value: txid})
initiator.Envs <- &basic.TracingEnvelope{Env: env, TxId: txid, Span: span}
}
}