Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,7 @@ if err := config.Parse("config.yaml", &cfg); err != nil {

### `node`

Simple Tezos RPC API wrapper.

```go
import "github.com/dipdup-net/go-lib/node"

rpc := node.NewNodeRPC(url, node.WithTimeout(timeout))

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// example with context
constants, err := rpc.Constants(node.WithContext(ctx))
if err != nil {
panic(err)
}

// example without context
constants, err := rpc.Constants()
if err != nil {
panic(err)
}

```
Simple Tezos RPC API wrapper. Docs you can find [here](node/README.md)

### `database`

Expand Down
55 changes: 55 additions & 0 deletions node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Tezos RPC client

The library realize almost all RPC methods of Tezos node.

## Usage

### Simple example

```go
rpc := node.NewRPC("https://rpc.tzkt.io/mainnet", "main")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

block, err := rpc.Block(ctx, "head")
if err != nil {
panic(err)
}
log.Printf("%##v", block)
```

You can use main RPC constructor where chain id set by default to `main`

```go
rpc := node.NewMainRPC("https://rpc.tzkt.io/mainnet")
```

### Usage certain API part

RPC struct contains some internal parts: `Chain`, `Block`, `Context`, `Config`, `General`, `Protocols`, `Inject` and `Network`. You can use it without creation of full RPC client.

```go
rpc := node.NewMainBlockRPC("https://rpc.tzkt.io/mainnet")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

block, err := rpc.Block(ctx, "head")
if err != nil {
panic(err)
}
log.Printf("%##v", block)
```

### Interfaces

For testing purpose RPC was wrapped by interfaces. Also each part of RPC has interface. You can mock it with code generation tools.

Interfaces list:
* `BlockAPI`
* `ChainAPI`
* `ContextAPI`
* `ConfigAPI`
* `GeneralAPI`
* `ProtocolsAPI`
* `NetworkAPI`
* `InjectAPI`
57 changes: 57 additions & 0 deletions node/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package node

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary

// API -
type API interface {
BlockAPI
ChainAPI
ContextAPI
ConfigAPI
GeneralAPI
ProtocolsAPI
NetworkAPI
InjectAPI
}

// RPC -
type RPC struct {
*BlockRPC
*Chain
*Context
*Config
*General
*Protocols
*Network
*Inject
}

// NewRPC -
func NewRPC(baseURL, chainID string) *RPC {
return &RPC{
BlockRPC: NewBlockRPC(baseURL, chainID),
Chain: NewChain(baseURL, chainID),
Context: NewContext(baseURL, chainID),
Config: NewConfig(baseURL),
General: NewGeneral(baseURL),
Protocols: NewProtocols(baseURL),
Network: NewNetwork(baseURL),
Inject: NewInject(baseURL),
}
}

// NewMainRPC -
func NewMainRPC(baseURL string) *RPC {
return &RPC{
BlockRPC: NewMainBlockRPC(baseURL),
Chain: NewMainChain(baseURL),
Context: NewMainContext(baseURL),
Config: NewConfig(baseURL),
General: NewGeneral(baseURL),
Protocols: NewProtocols(baseURL),
Network: NewNetwork(baseURL),
Inject: NewInject(baseURL),
}
}
Loading