mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-21 14:26:45 +00:00

* Optionally show serialized transactions on send * Explain more about serialized transactions * Increase grpc server send message size
32 lines
960 B
Go
32 lines
960 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/server"
|
|
"time"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// Connect connects to the kaspawalletd server, and returns the client instance
|
|
func Connect(address string) (pb.KaspawalletdClient, func(), error) {
|
|
// Connection is local, so 1 second timeout is sufficient
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
|
defer cancel()
|
|
|
|
conn, err := grpc.DialContext(ctx, address, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(server.MaxDaemonSendMsgSize)))
|
|
if err != nil {
|
|
if errors.Is(err, context.DeadlineExceeded) {
|
|
return nil, nil, errors.New("kaspawallet daemon is not running, start it with `kaspawallet start-daemon`")
|
|
}
|
|
return nil, nil, err
|
|
}
|
|
|
|
return pb.NewKaspawalletdClient(conn), func() {
|
|
conn.Close()
|
|
}, nil
|
|
}
|