fabric-samples/off_chain_data/application-go/app.go
Stanislav Jakuschevskij 7244639e7c
Add off-chain-data go client application
Created project structure, fixed typos. Implemented connect.go and
getAllAssets.go. The latter uses an assetTransferBasic struct which
provides a simple API for basic asset operations like create, transfer,
etc.

Added transact.go with some util functions. Using google uuid package to
generate random UUIDs for the transactions.

Implemented pretty printing of JSON results.

Implemented app.go entry point with error handling. The existing
commands are getAllAssets, transact and listen. They can be called from
the command line via: "go run . <command> <command> ...". They will be
executed in order and if a command is not known an the application
panics and aborts before executing any of the commands.

Implementing listen.go. Added checkpointer, context setups, call to
BlockEvents and all the interfaces needed for parsing. Started
implementing the interfaces needed to represent a block bottom up in
structs. Finished NamespaceReadWriteSet, ReadWriteSet and
EndorserTransaction.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:46 +01:00

62 lines
1.1 KiB
Go

/*
* Copyright 2024 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"errors"
"fmt"
"os"
"strings"
"google.golang.org/grpc"
)
var allCommands = map[string]func(clientConnection *grpc.ClientConn){
"getAllAssets": getAllAssets,
"transact": transact,
"listen": listen,
}
func main() {
commands := os.Args[1:]
if len(commands) == 0 {
printUsage()
panic(errors.New("missing command"))
}
for _, name := range commands {
if _, exists := allCommands[name]; !exists {
printUsage()
panic(fmt.Errorf("unknown command: %s", name))
}
fmt.Printf("command: %s\n", name)
}
client := newGrpcConnection()
defer client.Close()
for _, name := range commands {
command := allCommands[name]
command(client)
}
}
func printUsage() {
fmt.Println("Arguments: <command1> [<command2> ...]")
fmt.Printf("Available commands: %v\n", availableCommands())
}
func availableCommands() string {
result := make([]string, len(allCommands))
i := 0
for command := range allCommands {
result[i] = command
i++
}
return strings.Join(result, ", ")
}