Skip to content

Pantani/jsonrpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference codecov

JSON-RPC request abstraction

Simple abstraction for JSON-RPC requests.

Initialize the client:

import "github.com/Pantani/jsonrpc"

client := jsonrpc.InitRpcClient("http://127.0.0.1:8080")

Methods

Rpc Call

var txs []Transaction
err := client.RpcCall(&txs, "getTransactionsByAddress", []string{"d48182276127b149a9710e78c436fb4bc1c4dc0b", "25"})

Rpc Batch Call

var requests jsonrpc.RpcRequests
for _, hash := range hashes {
    requests = append(requests, &jsonrpc.RpcRequest{
        Method: "GetTransaction",
        Params: []string{hash},
    })
}
responses, err := client.RpcBatchCall(requests)
if err != nil {
    panic(err)
}
for _, result := range responses {
    var tx Transaction
    if mapstructure.Decode(result.Result, &tx) != nil {
        continue
    }
    txs = append(txs, tx)
}