-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
executable file
·69 lines (53 loc) · 1.59 KB
/
app.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
/*
Copyright 2022 IBM All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"context"
"time"
"github.com/hyperledger/fabric-gateway/pkg/client"
"gateway/simulate"
)
const (
channelName = "mychannel"
ccname = "abac"
)
// var now = time.Now()
// var assetID = fmt.Sprintf("asset%d", now.Unix()*1e3+int64(now.Nanosecond())/1e6)
var assetID = "asset1691484020387"
func main() {
clientConnection := newGrpcConnection()
defer clientConnection.Close()
id := newIdentity()
sign := newSign()
gateway, err := client.Connect(
id,
client.WithSign(sign),
client.WithClientConnection(clientConnection),
client.WithEvaluateTimeout(5*time.Second),
client.WithEndorseTimeout(15*time.Second),
client.WithSubmitTimeout(5*time.Second),
client.WithCommitStatusTimeout(1*time.Minute),
)
if err != nil {
panic(err)
}
defer gateway.Close()
network := gateway.GetNetwork(channelName)
contract := network.GetContract(ccname)
// Context used for event listening
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Listen for events emitted by subsequent transactions
simulate.StartChaincodeEventListening(ctx, network, ccname)
/** SIMULATIONS */
// simulate.CreateAsset(contract, assetID)
// startBlock := simulate.CreateAsset(contract, assetID)
simulate.UpdateAsset(contract, assetID)
// simulate.TransferAsset(contract, assetID)
// simulate.DeleteAsset(contract, assetID)
simulate.GetAllAssets(contract)
// Replay events from the block containing the first transaction
// simulate.ReplayChaincodeEvents(ctx, network, startBlock, ccname)
}