mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Added caching util function with tests and applied in: - parser.Block.Transactions(), - parser.Payload.ChannelHeader(), - parser.Payload.SignatureHeader(), - parser.NamespaceReadWriteSet.ReadWriteSet(), - parser.EndorserTransaction.ReadWriteSets(), methods, as it was in the typescript sample. Corrected Println usage and added comments to util functions. Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
40 lines
884 B
Go
40 lines
884 B
Go
/*
|
|
* Copyright 2024 IBM All Rights Reserved.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
atb "offChainData/contract"
|
|
|
|
"github.com/hyperledger/fabric-gateway/pkg/client"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func getAllAssets(clientConnection *grpc.ClientConn) {
|
|
id, options := newConnectOptions(clientConnection)
|
|
gateway, err := client.Connect(id, options...)
|
|
if err != nil {
|
|
panic((err))
|
|
}
|
|
defer gateway.Close()
|
|
|
|
contract := gateway.GetNetwork(channelName).GetContract(chaincodeName)
|
|
smartContract := atb.NewAssetTransferBasic(contract)
|
|
assets := smartContract.GetAllAssets()
|
|
|
|
fmt.Println(formatJSON(assets))
|
|
}
|
|
|
|
func formatJSON(data []byte) string {
|
|
var result bytes.Buffer
|
|
if err := json.Indent(&result, data, "", " "); err != nil {
|
|
panic(fmt.Errorf("failed to parse JSON: %w", err))
|
|
}
|
|
return result.String()
|
|
}
|