mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-18 07:55:10 +00:00
The Javascript asset-transfer-basic chaincode stores AppraisedValue and Size as string types instead of number types. This leads to an issue when used with a Go client application where assets are unmarshaled into an Asset type where AppraisedValue and Size are of uint64 type. This change makes sure that AppraisedValue and Size are stringified as numbers. To prevent the pipeline from failing when the expected error occurs a sentinel error was created and checked against in the entry point. Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type command func(grpc.ClientConnInterface) error
|
|
|
|
var allCommands = map[string]command{
|
|
"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.Println("command:", name)
|
|
}
|
|
|
|
client := newGrpcConnection()
|
|
defer client.Close()
|
|
|
|
for _, name := range commands {
|
|
command := allCommands[name]
|
|
|
|
if err := command(client); err != nil {
|
|
if errors.Is(err, errExpected) {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func printUsage() {
|
|
fmt.Println("Arguments: <command1> [<command2> ...]")
|
|
fmt.Println("Available commands:", availableCommands())
|
|
}
|
|
|
|
func availableCommands() string {
|
|
result := make([]string, len(allCommands))
|
|
i := 0
|
|
for command := range allCommands {
|
|
result[i] = command
|
|
i++
|
|
}
|
|
|
|
return strings.Join(result, ", ")
|
|
}
|