basic fetch working
This commit is contained in:
		
							parent
							
								
									74f68b0e00
								
							
						
					
					
						commit
						f0b0786ef8
					
				@ -37,7 +37,7 @@ type JSONRPCRequest struct {
 | 
				
			|||||||
	ID      string          `json:"id"`
 | 
						ID      string          `json:"id"`
 | 
				
			||||||
	JSONRPC string          `json:"jsonrpc"`
 | 
						JSONRPC string          `json:"jsonrpc"`
 | 
				
			||||||
	Method  string          `json:"method"`
 | 
						Method  string          `json:"method"`
 | 
				
			||||||
	Params  []json.RawMessage `json:"params"`
 | 
						Params  json.RawMessage `json:"params"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type JSONRPC struct {
 | 
					type JSONRPC struct {
 | 
				
			||||||
@ -62,7 +62,7 @@ func NewJSONRPC(url string, options ...func(rpc *JSONRPC)) *JSONRPC {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Call returns raw response of method call
 | 
					// 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{
 | 
						request := JSONRPCRequest{
 | 
				
			||||||
		ID:      "1",
 | 
							ID:      "1",
 | 
				
			||||||
		JSONRPC: "2.0",
 | 
							JSONRPC: "2.0",
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										9
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								main.go
									
									
									
									
									
								
							@ -6,11 +6,12 @@ import (
 | 
				
			|||||||
	"log"
 | 
						"log"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					const steemApiUrl = "https://api.steemit.com"
 | 
				
			||||||
	c := JSONRPCClient("https://api.steemit.com", func(x *JSONRPC) { x.Debug = true })
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	r, err := c.GetVirtualOpsInBlock(20000000)
 | 
					func main() {
 | 
				
			||||||
	//r, err := c.GetOpsInBlock(1)
 | 
						s := NewSteemAPI(steemApiUrl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r, err := s.GetOpsInBlock(20000000, true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatal(err)
 | 
							log.Fatal(err)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import log "github.com/sirupsen/logrus"
 | 
				
			||||||
import "encoding/json"
 | 
					import "encoding/json"
 | 
				
			||||||
import "github.com/joeshaw/iso8601"
 | 
					import "github.com/joeshaw/iso8601"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -13,22 +14,49 @@ type SteemVirtualTransaction struct {
 | 
				
			|||||||
	Op        []json.RawMessage `json:"op"`
 | 
						Op        []json.RawMessage `json:"op"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (rpc *JSONRPC) GetVirtualOpsInBlock(blockNum int) ([]*SteemVirtualTransaction, error) {
 | 
					type SteemAPI struct {
 | 
				
			||||||
	raw, err1 := rpc.Call("condenser_api.get_ops_in_block", blockNum, true)
 | 
						url   string
 | 
				
			||||||
	if err1 != nil {
 | 
						rpc   *JSONRPC
 | 
				
			||||||
		return nil, err1
 | 
						Debug bool
 | 
				
			||||||
 | 
						log   *log.Logger
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tmp := make([]SteemVirtualTransaction)
 | 
					func NewSteemAPI(url string, options ...func(s *SteemAPI)) *SteemAPI {
 | 
				
			||||||
	//var result []interface{}
 | 
					
 | 
				
			||||||
	err2 := json.Unmarshal(raw, &tmp)
 | 
						rpc := NewJSONRPC(url, func(x *JSONRPC) { x.Debug = true })
 | 
				
			||||||
	if err2 != nil {
 | 
					
 | 
				
			||||||
		return result, nil
 | 
						self := &SteemAPI{
 | 
				
			||||||
	}
 | 
							rpc: rpc,
 | 
				
			||||||
	return nil, err2
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (rpc *JSONRPC) GetOpsInBlock(blockNum int) (json.RawMessage, error) {
 | 
						self.log = log.New()
 | 
				
			||||||
	r, err := rpc.Call("condenser_api.get_ops_in_block", blockNum, false)
 | 
					
 | 
				
			||||||
	return r, err
 | 
						for _, option := range options {
 | 
				
			||||||
 | 
							option(self)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return self
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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…
	
		Reference in New Issue
	
	Block a user