checkpoint, does not work
This commit is contained in:
parent
053e178942
commit
0289c414fd
|
@ -0,0 +1 @@
|
|||
0.0.0: Qmc8avR3R61qdrX8inmkKqnWtUQHQaN2XR6idG4wpYgYLf
|
|
@ -1,6 +1,5 @@
|
|||
package main
|
||||
|
||||
|
||||
import "log"
|
||||
import "io/ioutil"
|
||||
import "github.com/dgraph-io/badger"
|
||||
|
|
40
jsonrpc.go
40
jsonrpc.go
|
@ -7,59 +7,53 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type logger interface {
|
||||
Println(v ...interface{})
|
||||
}
|
||||
|
||||
type httpClient interface {
|
||||
type httpRPCClient interface {
|
||||
Post(url string, contentType string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
|
||||
type JsonRpcError struct {
|
||||
type JSONRPCError struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (err JsonRpcError) Error() string {
|
||||
func (err JSONRPCError) Error() string {
|
||||
return fmt.Sprintf("Error %d (%s)", err.Code, err.Message)
|
||||
}
|
||||
|
||||
type JsonRpcResponse struct {
|
||||
type JSONRPCResponse struct {
|
||||
ID string `json:"id"`
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
Result json.RawMessage `json:"result"`
|
||||
Error *JsonRpcError `json:"error"`
|
||||
Error *JSONRPCError `json:"error"`
|
||||
}
|
||||
|
||||
type JsonRpcRequest struct {
|
||||
type JSONRPCRequest struct {
|
||||
ID string `json:"id"`
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
Method string `json:"method"`
|
||||
Params []interface{} `json:"params"`
|
||||
Params []json.RawMessage `json:"params"`
|
||||
}
|
||||
|
||||
// JsonRpc Client Object
|
||||
type JsonRpc struct {
|
||||
type JSONRPC struct {
|
||||
url string
|
||||
client httpClient
|
||||
log logger
|
||||
client httpRPCClient
|
||||
Debug bool
|
||||
log *log.Logger
|
||||
}
|
||||
|
||||
// New create new rpc client with given url
|
||||
func JsonRpcClient(url string, options ...func(rpc *JsonRpc)) *JsonRpc {
|
||||
rpc := &JsonRpc{
|
||||
func NewJSONRPC(url string, options ...func(rpc *JSONRPC)) *JSONRPC {
|
||||
rpc := &JSONRPC{
|
||||
url: url,
|
||||
client: http.DefaultClient,
|
||||
log: log.New(os.Stderr, "", log.LstdFlags),
|
||||
}
|
||||
rpc.log = log.New()
|
||||
for _, option := range options {
|
||||
option(rpc)
|
||||
}
|
||||
|
@ -68,8 +62,8 @@ func JsonRpcClient(url string, options ...func(rpc *JsonRpc)) *JsonRpc {
|
|||
}
|
||||
|
||||
// Call returns raw response of method call
|
||||
func (rpc *JsonRpc) Call(method string, params ...interface{}) (json.RawMessage, error) {
|
||||
request := JsonRpcRequest{
|
||||
func (rpc *JSONRPC) Call(method string, params ...json.RawMessage) (json.RawMessage, error) {
|
||||
request := JSONRPCRequest{
|
||||
ID: "1",
|
||||
JSONRPC: "2.0",
|
||||
Method: method,
|
||||
|
@ -98,7 +92,7 @@ func (rpc *JsonRpc) Call(method string, params ...interface{}) (json.RawMessage,
|
|||
rpc.log.Println(fmt.Sprintf("%s\nRequest: %s\nResponse: %s\n", method, body, data))
|
||||
}
|
||||
|
||||
resp := new(JsonRpcResponse)
|
||||
resp := new(JSONRPCResponse)
|
||||
if err := json.Unmarshal(data, resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
import log "github.com/sirupsen/logrus"
|
||||
|
||||
// wtf go stdlib doesn't have a Logger interface?!
|
||||
type Logger interface {
|
||||
log.FieldLogger
|
||||
}
|
2
main.go
2
main.go
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
c := JsonRpcClient("https://api.steemit.com", func(x *JsonRpc) { x.Debug = true })
|
||||
c := JSONRPCClient("https://api.steemit.com", func(x *JSONRPC) { x.Debug = true })
|
||||
|
||||
r, err := c.GetVirtualOpsInBlock(20000000)
|
||||
//r, err := c.GetOpsInBlock(1)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"author": "sneak",
|
||||
"bugs": {},
|
||||
"gx": {},
|
||||
"gxVersion": "0.12.1",
|
||||
"language": "go",
|
||||
"license": "",
|
||||
"name": "steem-block-db",
|
||||
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
|
||||
"version": "0.0.0"
|
||||
}
|
||||
|
|
@ -4,9 +4,6 @@ import "encoding/json"
|
|||
import "github.com/joeshaw/iso8601"
|
||||
|
||||
|
||||
type UnparsedSteemVirtualOp struct {
|
||||
}
|
||||
|
||||
type SteemVirtualTransaction struct {
|
||||
TxID string `json:"trx_id"`
|
||||
BlockNum uint64 `json:"block"`
|
||||
|
@ -14,21 +11,25 @@ type SteemVirtualTransaction struct {
|
|||
OpInTx int `json:"op_in_trx"`
|
||||
IsVirtual int `json:"virtual_op"`
|
||||
Timestamp iso8601.Time `json:"timestamp"`
|
||||
Op *[]json.RawMessage `json:"op"`
|
||||
Op []json.RawMessage `json:"op"`
|
||||
}
|
||||
|
||||
func (rpc *JsonRpc) GetVirtualOpsInBlock(blockNum int) ([]*SteemVirtualTransaction, error) {
|
||||
func (rpc *JSONRPC) GetVirtualOpsInBlock(blockNum int) ([]*SteemVirtualTransaction, error) {
|
||||
raw, err1 := rpc.Call("condenser_api.get_ops_in_block", blockNum, true)
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
var result []*SteemVirtualTransaction
|
||||
|
||||
tmp := make([]SteemVirtualTransaction)
|
||||
//var result []interface{}
|
||||
err2 := json.Unmarshal(raw, &result)
|
||||
return result, err2
|
||||
err2 := json.Unmarshal(raw, &tmp)
|
||||
if err2 != nil {
|
||||
return result, nil
|
||||
}
|
||||
return nil, err2
|
||||
}
|
||||
|
||||
func (rpc *JsonRpc) GetOpsInBlock(blockNum int) (json.RawMessage, error) {
|
||||
func (rpc *JSONRPC) GetOpsInBlock(blockNum int) (json.RawMessage, error) {
|
||||
r, err := rpc.Call("condenser_api.get_ops_in_block", blockNum, false)
|
||||
return r, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue