forked from hyperledger/fabric-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAllAssets.go
More file actions
34 lines (28 loc) · 725 Bytes
/
Copy pathgetAllAssets.go
File metadata and controls
34 lines (28 loc) · 725 Bytes
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
package main
import (
"encoding/json"
"fmt"
atb "offchaindata/contract"
"github.com/hyperledger/fabric-gateway/pkg/client"
"google.golang.org/grpc"
)
func getAllAssets(clientConnection grpc.ClientConnInterface) error {
id, options := newConnectOptions(clientConnection)
gateway, err := client.Connect(id, options...)
if err != nil {
return err
}
defer gateway.Close()
contract := gateway.GetNetwork(channelName).GetContract(chaincodeName)
smartContract := atb.NewAssetTransferBasic(contract)
assets, err := smartContract.GetAllAssets()
if err != nil {
return err
}
formatted, err := json.MarshalIndent(assets, "", " ")
if err != nil {
return err
}
fmt.Println(string(formatted))
return nil
}