basic fetch working

master
Jeffrey Paul 6 years ago
parent 74f68b0e00
commit f0b0786ef8
Signed by: sneak
GPG Key ID: 052443F4DF2A55C2
  1. 10
      jsonrpc.go
  2. 7
      main.go
  3. 54
      steemitapi.go

@ -34,10 +34,10 @@ type JSONRPCResponse struct {
}
type JSONRPCRequest struct {
ID string `json:"id"`
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params []json.RawMessage `json:"params"`
ID string `json:"id"`
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params"`
}
type JSONRPC struct {
@ -62,7 +62,7 @@ func NewJSONRPC(url string, options ...func(rpc *JSONRPC)) *JSONRPC {
}
// Call returns raw response of method call
func (rpc *JSONRPC) Call(method string, params ...json.RawMessage) (json.RawMessage, error) {
func (rpc *JSONRPC) Call(method string, params json.RawMessage) (json.RawMessage, error) {
request := JSONRPCRequest{
ID: "1",
JSONRPC: "2.0",

@ -6,11 +6,12 @@ import (
"log"
)
const steemApiUrl = "https://api.steemit.com"
func main() {
c := JSONRPCClient("https://api.steemit.com", func(x *JSONRPC) { x.Debug = true })
s := NewSteemAPI(steemApiUrl)
r, err := c.GetVirtualOpsInBlock(20000000)
//r, err := c.GetOpsInBlock(1)
r, err := s.GetOpsInBlock(20000000, true)
if err != nil {
log.Fatal(err)

@ -1,5 +1,6 @@
package main
import log "github.com/sirupsen/logrus"
import "encoding/json"
import "github.com/joeshaw/iso8601"
@ -13,22 +14,49 @@ type SteemVirtualTransaction struct {
Op []json.RawMessage `json:"op"`
}
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
type SteemAPI struct {
url string
rpc *JSONRPC
Debug bool
log *log.Logger
}
func NewSteemAPI(url string, options ...func(s *SteemAPI)) *SteemAPI {
rpc := NewJSONRPC(url, func(x *JSONRPC) { x.Debug = true })
self := &SteemAPI{
rpc: rpc,
}
tmp := make([]SteemVirtualTransaction)
//var result []interface{}
err2 := json.Unmarshal(raw, &tmp)
if err2 != nil {
return result, nil
self.log = log.New()
for _, option := range options {
option(self)
}
return nil, err2
return self
}
func (rpc *JSONRPC) GetOpsInBlock(blockNum int) (json.RawMessage, error) {
r, err := rpc.Call("condenser_api.get_ops_in_block", blockNum, false)
return r, err
type GetOpsInBlockRequestParams struct {
BlockNum int
VirtualOps bool
}
func (r *GetOpsInBlockRequestParams) MarshalJSON() ([]byte, error) {
arr := []interface{}{r.BlockNum, r.VirtualOps}
return json.Marshal(arr)
}
func (self *SteemAPI) GetOpsInBlock(blockNum int, virtualOps bool) (json.RawMessage, error) {
p := &GetOpsInBlockRequestParams{BlockNum: blockNum, VirtualOps: virtualOps}
j, err := p.MarshalJSON()
if err != nil {
return nil, err
}
r, err := self.rpc.Call("condenser_api.get_ops_in_block", j)
if err != nil {
return nil, err
}
return r, nil
}

Loading…
Cancel
Save