63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package main
|
|
|
|
import log "github.com/sirupsen/logrus"
|
|
import "encoding/json"
|
|
import "github.com/joeshaw/iso8601"
|
|
|
|
type SteemVirtualTransaction struct {
|
|
TxID string `json:"trx_id"`
|
|
BlockNum uint64 `json:"block"`
|
|
TxInBlock uint64 `json:"trx_in_block"`
|
|
OpInTx int `json:"op_in_trx"`
|
|
IsVirtual int `json:"virtual_op"`
|
|
Timestamp iso8601.Time `json:"timestamp"`
|
|
Op []json.RawMessage `json:"op"`
|
|
}
|
|
|
|
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,
|
|
}
|
|
|
|
self.log = log.New()
|
|
|
|
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
|
|
}
|