From c9dcdcdb877bc29556a987b1f0cc2bed867ab0db Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:59:20 +0200 Subject: [PATCH] feat: add gno.land/pkg/gnoclient (Gno.land Go client) Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> --- gno.land/pkg/gnoclient/README.md | 14 ++++++++++ gno.land/pkg/gnoclient/client.go | 36 ++++++++++++++++++++++++++ gno.land/pkg/gnoclient/client_test.go | 15 +++++++++++ gno.land/pkg/gnoclient/example_test.go | 15 +++++++++++ 4 files changed, 80 insertions(+) create mode 100644 gno.land/pkg/gnoclient/README.md create mode 100644 gno.land/pkg/gnoclient/client.go create mode 100644 gno.land/pkg/gnoclient/client_test.go create mode 100644 gno.land/pkg/gnoclient/example_test.go diff --git a/gno.land/pkg/gnoclient/README.md b/gno.land/pkg/gnoclient/README.md new file mode 100644 index 00000000000..322df2a2742 --- /dev/null +++ b/gno.land/pkg/gnoclient/README.md @@ -0,0 +1,14 @@ +# Gno.land Go Client + +This is a Go client library for interacting with the Gno.land RPC API. +The library provides a convenient way to make requests to the Gno.land API endpoints and process the responses. + +## Installation + +To use this library, you can add it to your Go project using `go get`: + + go get github.com/gnolang/gno/gno.land/pkg/gnoclient + +## Usage + +TODO diff --git a/gno.land/pkg/gnoclient/client.go b/gno.land/pkg/gnoclient/client.go new file mode 100644 index 00000000000..4b3b9e7a4fb --- /dev/null +++ b/gno.land/pkg/gnoclient/client.go @@ -0,0 +1,36 @@ +package gnoclient + +// Client represents the Gno.land RPC API client. +type Client struct { + Remote string + ChainID string +} + +// TODO: port existing code, i.e. faucet? +// TODO: create right now a tm2 generic go client and a gnovm generic go client? +// TODO: Command: Call +// TODO: Command: Send +// TODO: Command: AddPkg +// TODO: Command: Query +// TODO: Command: Eval +// TODO: Command: Exec +// TODO: Command: Package +// TODO: Command: QFile +// TODO: examples and unit tests +// TODO: Mock +// TODO: alternative configuration (pass existing websocket?) +// TODO: minimal go.mod to make it light to import + +func (c *Client) ApplyDefaults() { + if c.Remote == "" { + c.Remote = "127.0.0.1:26657" + } + if c.ChainID == "" { + c.ChainID = "devnet" + } +} + +// Request performs an API request and returns the response body. +func (c *Client) Request(method, endpoint string, params map[string]interface{}) ([]byte, error) { + panic("not implemented") +} diff --git a/gno.land/pkg/gnoclient/client_test.go b/gno.land/pkg/gnoclient/client_test.go new file mode 100644 index 00000000000..3aa2f41c111 --- /dev/null +++ b/gno.land/pkg/gnoclient/client_test.go @@ -0,0 +1,15 @@ +package gnoclient + +import ( + "testing" +) + +func TestClient_Request(t *testing.T) { + client := Client{ + Remote: "localhost:12345", + ChainID: "test", + } + _ = client + + // TODO: xxx +} diff --git a/gno.land/pkg/gnoclient/example_test.go b/gno.land/pkg/gnoclient/example_test.go new file mode 100644 index 00000000000..4de537fa4f3 --- /dev/null +++ b/gno.land/pkg/gnoclient/example_test.go @@ -0,0 +1,15 @@ +package gnoclient_test + +import ( + "fmt" + + "github.com/gnolang/gno/gno.land/pkg/gnoclient" +) + +func Example() { + client := gnoclient.Client{} + _ = client + fmt.Println("Hello") + // Output: + // Hello +}