Skip to content

Commit d6ad358

Browse files
committed
Add first batch of pull request rework
- update Application section in README - remove param name in app.go - add error checks in processor/block.go - move vars from model to transact logic - move newAsset to transact - use ID for well-known initialisms - move randomelement, randomnint and differentelement to transact - remove AssertDefined - blockTxIdsJoinedByComma: use standard library to join elements - return nil, instead of []byte{} - remove go routine in listen.go - move cache to parser - inline processor in listen.go - move store to main package - move util to main package - fixed failing cache issue - fixed staticcheck issues - removed cache function, implemented caching in the structs and methods Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
1 parent 69c521f commit d6ad358

File tree

22 files changed

+455
-695
lines changed

22 files changed

+455
-695
lines changed

off_chain_data/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ The client application provides several "commands" that can be invoked using the
1919
- **getAllAssets**: Retrieve the current details of all assets recorded on the ledger. See:
2020
- TypeScript: [application-typescript/src/getAllAssets.ts](application-typescript/src/getAllAssets.ts)
2121
- Java: [application-java/app/src/main/java/GetAllAssets.java](application-java/app/src/main/java/GetAllAssets.java)
22+
- Go: [application-go/getAllAssets.go](application-go/getAllAssets.go)
2223
- **listen**: Listen for block events, and use them to replicate ledger updates in an off-chain data store. See:
2324
- TypeScript: [application-typescript/src/listen.ts](application-typescript/src/listen.ts)
2425
- Java: [application-java/app/src/main/java/Listen.java](application-java/app/src/main/java/Listen.java)
26+
- Go: [application-go/listen.go](application-go/listen.go)
2527
- **transact**: Submit a set of transactions to create, modify and delete assets. See:
2628
- TypeScript: [application-typescript/src/transact.ts](application-typescript/src/transact.ts)
2729
- Java: [application-java/app/src/main/java/Transact.java](application-java/app/src/main/java/Transact.java)
30+
- Go: [application-go/transact.go](application-go/transact.go)
2831

2932
To keep the sample code concise, the **listen** command writes ledger updates to an output file named `store.log` in the current working directory (which for the Java sample is the `application-java/app` directory). A real implementation could write ledger updates directly to an off-chain data store of choice. You can inspect the information captured in this file as you run the sample.
3033

off_chain_data/application-go/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"google.golang.org/grpc"
1616
)
1717

18-
var allCommands = map[string]func(clientConnection *grpc.ClientConn){
18+
var allCommands = map[string]func(*grpc.ClientConn){
1919
"getAllAssets": getAllAssets,
2020
"transact": transact,
2121
"listen": listen,

off_chain_data/application-go/connect.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package main
99
import (
1010
"crypto/x509"
1111
"fmt"
12-
"offChainData/utils"
1312
"os"
1413
"path"
1514
"time"
@@ -24,27 +23,27 @@ import (
2423
const peerName = "peer0.org1.example.com"
2524

2625
var (
27-
channelName = utils.EnvOrDefault("CHANNEL_NAME", "mychannel")
28-
chaincodeName = utils.EnvOrDefault("CHAINCODE_NAME", "basic")
29-
mspID = utils.EnvOrDefault("MSP_ID", "Org1MSP")
26+
channelName = envOrDefault("CHANNEL_NAME", "mychannel")
27+
chaincodeName = envOrDefault("CHAINCODE_NAME", "basic")
28+
mspID = envOrDefault("MSP_ID", "Org1MSP")
3029

3130
// Path to crypto materials.
32-
cryptoPath = utils.EnvOrDefault("CRYPTO_PATH", "../../test-network/organizations/peerOrganizations/org1.example.com")
31+
cryptoPath = envOrDefault("CRYPTO_PATH", "../../test-network/organizations/peerOrganizations/org1.example.com")
3332

3433
// Path to user private key directory.
35-
keyDirectoryPath = utils.EnvOrDefault("KEY_DIRECTORY_PATH", cryptoPath+"/users/User1@org1.example.com/msp/keystore")
34+
keyDirectoryPath = envOrDefault("KEY_DIRECTORY_PATH", cryptoPath+"/users/User1@org1.example.com/msp/keystore")
3635

3736
// Path to user certificate.
38-
certPath = utils.EnvOrDefault("CERT_PATH", cryptoPath+"/users/User1@org1.example.com/msp/signcerts/cert.pem")
37+
certPath = envOrDefault("CERT_PATH", cryptoPath+"/users/User1@org1.example.com/msp/signcerts/cert.pem")
3938

4039
// Path to peer tls certificate.
41-
tlsCertPath = utils.EnvOrDefault("TLS_CERT_PATH", cryptoPath+"/peers/peer0.org1.example.com/tls/ca.crt")
40+
tlsCertPath = envOrDefault("TLS_CERT_PATH", cryptoPath+"/peers/peer0.org1.example.com/tls/ca.crt")
4241

4342
// Gateway peer endpoint.
44-
peerEndpoint = utils.EnvOrDefault("PEER_ENDPOINT", "dns:///localhost:7051")
43+
peerEndpoint = envOrDefault("PEER_ENDPOINT", "dns:///localhost:7051")
4544

4645
// Gateway peer SSL host name override.
47-
peerHostAlias = utils.EnvOrDefault("PEER_HOST_ALIAS", peerName)
46+
peerHostAlias = envOrDefault("PEER_HOST_ALIAS", peerName)
4847
)
4948

5049
func newGrpcConnection() *grpc.ClientConn {

off_chain_data/application-go/contract/contract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (atb *AssetTransferBasic) DeleteAsset(id string) error {
6565
func (atb *AssetTransferBasic) GetAllAssets() ([]byte, error) {
6666
result, err := atb.contract.Evaluate("GetAllAssets")
6767
if err != nil {
68-
return []byte{}, fmt.Errorf("in GetAllAssets: %w", err)
68+
return nil, fmt.Errorf("in GetAllAssets: %w", err)
6969
}
7070
return result, nil
7171
}

off_chain_data/application-go/contract/model.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,10 @@
55
*/
66
package contract
77

8-
import (
9-
"offChainData/utils"
10-
11-
"github.com/google/uuid"
12-
)
13-
14-
var (
15-
colors = []string{"red", "green", "blue"}
16-
Owners = []string{"alice", "bob", "charlie"}
17-
)
18-
19-
const (
20-
maxInitialValue = 1000
21-
maxInitialSize = 10
22-
)
23-
248
type Asset struct {
259
ID string `json:"ID"`
2610
Color string `json:"Color"`
2711
Size uint64 `json:"Size"`
2812
Owner string `json:"Owner"`
2913
AppraisedValue uint64 `json:"AppraisedValue"`
3014
}
31-
32-
func NewAsset() Asset {
33-
id, err := uuid.NewRandom()
34-
if err != nil {
35-
panic(err)
36-
}
37-
38-
return Asset{
39-
ID: id.String(),
40-
Color: utils.RandomElement(colors),
41-
Size: uint64(utils.RandomInt(maxInitialSize) + 1),
42-
Owner: utils.RandomElement(Owners),
43-
AppraisedValue: uint64(utils.RandomInt(maxInitialValue) + 1),
44-
}
45-
}

off_chain_data/application-go/getAllAssets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"bytes"
1111
"encoding/json"
1212
"fmt"
13-
atb "offChainData/contract"
13+
atb "offchaindata/contract"
1414

1515
"github.com/hyperledger/fabric-gateway/pkg/client"
1616
"google.golang.org/grpc"

off_chain_data/application-go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module offChainData
1+
module offchaindata
22

33
go 1.22.0
44

0 commit comments

Comments
 (0)