mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 07:25:10 +00:00
34 lines
725 B
Go
34 lines
725 B
Go
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
|
|
}
|