github.com/evdatsion/aphelion-dpos-bft@v0.32.1/test/app/grpc_client.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/hex"
     5  	"fmt"
     6  	"os"
     7  
     8  	"context"
     9  
    10  	amino "github.com/evdatsion/go-amino"
    11  	core_grpc "github.com/evdatsion/aphelion-dpos-bft/rpc/grpc"
    12  )
    13  
    14  var grpcAddr = "tcp://localhost:36656"
    15  
    16  func main() {
    17  	args := os.Args
    18  	if len(args) == 1 {
    19  		fmt.Println("Must enter a transaction to send (hex)")
    20  		os.Exit(1)
    21  	}
    22  	tx := args[1]
    23  	txBytes, err := hex.DecodeString(tx)
    24  	if err != nil {
    25  		fmt.Println("Invalid hex", err)
    26  		os.Exit(1)
    27  	}
    28  
    29  	clientGRPC := core_grpc.StartGRPCClient(grpcAddr)
    30  	res, err := clientGRPC.BroadcastTx(context.Background(), &core_grpc.RequestBroadcastTx{Tx: txBytes})
    31  	if err != nil {
    32  		fmt.Println(err)
    33  		os.Exit(1)
    34  	}
    35  
    36  	bz, err := amino.NewCodec().MarshalJSON(res)
    37  	if err != nil {
    38  		fmt.Println(err)
    39  		os.Exit(1)
    40  	}
    41  	fmt.Println(string(bz))
    42  }