Browse Source

Merge branch 'develop' of https://github.com/tendermint/tendermint into develop

pull/61/head
Ethan Buchman 10 years ago
parent
commit
8aaa918143
11 changed files with 55 additions and 855 deletions
  1. +1
    -0
      .gitignore
  2. +2
    -0
      binary/README.md
  3. +6
    -6
      cmd/barak/main.go
  4. +19
    -13
      cmd/debora/main.go
  5. +4
    -4
      consensus/reactor.go
  6. +1
    -0
      node/node.go
  7. +2
    -0
      process/process.go
  8. +11
    -2
      rpc/core/consensus.go
  9. +7
    -1
      rpc/core/pipe.go
  10. +2
    -1
      rpc/core/types/responses.go
  11. +0
    -828
      rpc/core_client/client_methods.go.bak

+ 1
- 0
.gitignore View File

@ -1,6 +1,7 @@
*.swp
*.swo
.bak
*.bak
.DS_Store
build/*
rpc/test/.tendermint


+ 2
- 0
binary/README.md View File

@ -3,6 +3,8 @@
This documentation is out of date.
* 0x00 is reserved as a nil byte for RegisterInterface
* moved TypeByte() into RegisterInterface/ConcreteType
* Pointers that don't have a declared TypeByte() are
encoded with a leading 0x00 (nil) or 0x01.
# `tendermint/binary`


+ 6
- 6
cmd/barak/main.go View File

@ -88,12 +88,6 @@ func main() {
}
barak.registries = options.Registries
// Write pid to file.
err = AtomicWriteFile(barak.rootDir+"/pidfile", []byte(Fmt("%v", barak.pid)))
if err != nil {
panic(Fmt("Error writing pidfile: %v", err))
}
// Debug.
fmt.Printf("Options: %v\n", options)
fmt.Printf("Barak: %v\n", barak)
@ -119,6 +113,12 @@ func main() {
}(registry)
}
// Write pid to file. This should be the last thing before TrapSignal.
err = AtomicWriteFile(barak.rootDir+"/pidfile", []byte(Fmt("%v", barak.pid)))
if err != nil {
panic(Fmt("Error writing pidfile: %v", err))
}
TrapSignal(func() {
fmt.Println("Barak shutting down")
})


+ 19
- 13
cmd/debora/main.go View File

@ -32,6 +32,11 @@ func main() {
Value: "default",
Usage: "uses ~/.debora/<group>.cfg",
}
labelFlag = cli.StringFlag{
Name: "label",
Value: "_",
Usage: "label of the process, or _ by default",
}
bgFlag = cli.BoolFlag{
Name: "bg",
Usage: "if set, runs as a background daemon",
@ -68,6 +73,7 @@ func main() {
Usage: "run process",
Action: cliRunProcess,
Flags: []cli.Flag{
labelFlag,
bgFlag,
inputFlag,
},
@ -125,15 +131,14 @@ func cliGetStatus(c *cli.Context) {
func cliRunProcess(c *cli.Context) {
args := c.Args()
if len(args) < 2 {
Exit("Must specify <label> <execPath> <args...>")
if len(args) < 1 {
Exit("Must specify <execPath> <args...>")
}
label := args[0]
execPath := args[1]
args = args[2:]
execPath := args[0]
args = args[1:]
command := btypes.CommandRunProcess{
Wait: !c.Bool("bg"),
Label: label,
Label: c.String("label"),
ExecPath: execPath,
Args: args,
Input: c.String("input"),
@ -207,14 +212,15 @@ func cliListProcesses(c *cli.Context) {
} else {
fmt.Printf("%v processes:\n", Blue(remote))
for _, proc := range response.Processes {
startTimeStr := Green(proc.StartTime.String())
endTimeStr := proc.EndTime.String()
if !proc.EndTime.IsZero() {
endTimeStr = Red(endTimeStr)
fmt.Printf(" \"%v\" => `%v %v` (%v)\n", Yellow(proc.Label), proc.ExecPath, proc.Args, proc.Pid)
fmt.Printf(" started at %v", proc.StartTime.String())
if proc.EndTime.IsZero() {
fmt.Printf(", running still\n")
} else {
endTimeStr := proc.EndTime.String()
fmt.Printf(", stopped at %v\n", Yellow(endTimeStr))
}
fmt.Printf(" %v start:%v end:%v output:%v\n",
RightPadString(Fmt("\"%v\" => `%v` (%v)", Yellow(proc.Label), proc.ExecPath, proc.Pid), 40),
startTimeStr, endTimeStr, proc.OutputPath)
fmt.Printf(" stdout/stderr goes to %v\n", proc.OutputPath)
}
}
}(remote)


+ 4
- 4
consensus/reactor.go View File

@ -24,7 +24,7 @@ const (
DataChannel = byte(0x21)
VoteChannel = byte(0x22)
peerStateKey = "ConsensusReactor.peerState"
PeerStateKey = "ConsensusReactor.peerState"
peerGossipSleepDuration = 100 * time.Millisecond // Time to sleep if there's nothing to send.
)
@ -106,7 +106,7 @@ func (conR *ConsensusReactor) AddPeer(peer *p2p.Peer) {
// Create peerState for peer
peerState := NewPeerState(peer)
peer.Data.Set(peerStateKey, peerState)
peer.Data.Set(PeerStateKey, peerState)
// Begin gossip routines for this peer.
go conR.gossipDataRoutine(peer, peerState)
@ -121,7 +121,7 @@ func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) {
if !conR.IsRunning() {
return
}
//peer.Data.Get(peerStateKey).(*PeerState).Disconnect()
//peer.Data.Get(PeerStateKey).(*PeerState).Disconnect()
}
// Implements Reactor
@ -132,7 +132,7 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte
// Get round state
rs := conR.conS.GetRoundState()
ps := peer.Data.Get(peerStateKey).(*PeerState)
ps := peer.Data.Get(PeerStateKey).(*PeerState)
_, msg_, err := DecodeMessage(msgBytes)
if err != nil {
log.Warn("Error decoding message", "channel", chId, "peer", peer, "msg", msg_, "error", err, "bytes", msgBytes)


+ 1
- 0
node/node.go View File

@ -178,6 +178,7 @@ func (n *Node) dialSeed(addr *p2p.NetAddress) {
func (n *Node) StartRPC() {
core.SetBlockStore(n.blockStore)
core.SetConsensusState(n.consensusState)
core.SetConsensusReactor(n.consensusReactor)
core.SetMempoolReactor(n.mempoolReactor)
core.SetSwitch(n.sw)


+ 2
- 0
process/process.go View File

@ -13,6 +13,7 @@ import (
type Process struct {
Label string
ExecPath string
Args []string
Pid int
StartTime time.Time
EndTime time.Time
@ -55,6 +56,7 @@ func Create(mode int, label string, execPath string, args []string, input string
proc := &Process{
Label: label,
ExecPath: execPath,
Args: args,
Pid: cmd.Process.Pid,
StartTime: time.Now(),
OutputPath: outPath,


+ 11
- 2
rpc/core/consensus.go View File

@ -2,6 +2,7 @@ package core
import (
"github.com/tendermint/tendermint/binary"
cm "github.com/tendermint/tendermint/consensus"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
sm "github.com/tendermint/tendermint/state"
)
@ -26,6 +27,14 @@ func ListValidators() (*ctypes.ResponseListValidators, error) {
}
func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
jsonBytes := binary.JSONBytes(consensusState.GetRoundState())
return &ctypes.ResponseDumpConsensusState{string(jsonBytes)}, nil
roundState := consensusState.GetRoundState()
peerRoundStates := []string{}
for _, peer := range p2pSwitch.Peers().List() {
// TODO: clean this up?
peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState)
peerRoundState := peerState.GetRoundState()
peerRoundStateStr := peer.Key + ":" + string(binary.JSONBytes(peerRoundState))
peerRoundStates = append(peerRoundStates, peerRoundStateStr)
}
return &ctypes.ResponseDumpConsensusState{roundState.String(), peerRoundStates}, nil
}

+ 7
- 1
rpc/core/pipe.go View File

@ -10,6 +10,7 @@ import (
var blockStore *bc.BlockStore
var consensusState *consensus.ConsensusState
var consensusReactor *consensus.ConsensusReactor
var mempoolReactor *mempl.MempoolReactor
var p2pSwitch *p2p.Switch
@ -21,6 +22,10 @@ func SetConsensusState(cs *consensus.ConsensusState) {
consensusState = cs
}
func SetConsensusReactor(cr *consensus.ConsensusReactor) {
consensusReactor = cr
}
func SetMempoolReactor(mr *mempl.MempoolReactor) {
mempoolReactor = mr
}
@ -29,6 +34,7 @@ func SetSwitch(sw *p2p.Switch) {
p2pSwitch = sw
}
// JAE Why is this here?
func SetPrivValidator(priv *state.PrivValidator) {
consensusState.SetPrivValidator(priv)
consensusReactor.SetPrivValidator(priv)
}

+ 2
- 1
rpc/core/types/responses.go View File

@ -93,5 +93,6 @@ type ResponseListValidators struct {
}
type ResponseDumpConsensusState struct {
ConsensusState string
RoundState string
PeerRoundStates []string
}

+ 0
- 828
rpc/core_client/client_methods.go.bak View File

@ -1,828 +0,0 @@
// File generated by github.com/ebuchman/rpc-gen
package rpc
import (
"fmt"
"github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
"github.com/tendermint/tendermint/rpc/core"
"github.com/tendermint/tendermint/types"
"io/ioutil"
"net/http"
)
type Client interface {
BlockchainInfo(minHeight uint, maxHeight uint) (*core.ResponseBlockchainInfo, error)
BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error)
Call(address []byte, data []byte) (*core.ResponseCall, error)
CallCode(code []byte, data []byte) (*core.ResponseCall, error)
DumpStorage(addr []byte) (*core.ResponseDumpStorage, error)
GenPrivAccount() (*core.ResponseGenPrivAccount, error)
GetAccount(address []byte) (*core.ResponseGetAccount, error)
GetBlock(height uint) (*core.ResponseGetBlock, error)
GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error)
ListAccounts() (*core.ResponseListAccounts, error)
ListValidators() (*core.ResponseListValidators, error)
NetInfo() (*core.ResponseNetInfo, error)
SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error)
Status() (*core.ResponseStatus, error)
}
func (c *ClientHTTP) BlockchainInfo(minHeight uint, maxHeight uint) (*core.ResponseBlockchainInfo, error) {
values, err := argsToURLValues([]string{"minHeight", "maxHeight"}, minHeight, maxHeight)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["BlockchainInfo"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseBlockchainInfo `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error) {
values, err := argsToURLValues([]string{"tx"}, tx)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["BroadcastTx"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseBroadcastTx `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) Call(address []byte, data []byte) (*core.ResponseCall, error) {
values, err := argsToURLValues([]string{"address", "data"}, address, data)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["Call"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseCall `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) CallCode(code []byte, data []byte) (*core.ResponseCall, error) {
values, err := argsToURLValues([]string{"code", "data"}, code, data)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["CallCode"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseCall `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) DumpStorage(addr []byte) (*core.ResponseDumpStorage, error) {
values, err := argsToURLValues([]string{"addr"}, addr)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["DumpStorage"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseDumpStorage `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) GenPrivAccount() (*core.ResponseGenPrivAccount, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["GenPrivAccount"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGenPrivAccount `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) GetAccount(address []byte) (*core.ResponseGetAccount, error) {
values, err := argsToURLValues([]string{"address"}, address)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["GetAccount"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGetAccount `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) GetBlock(height uint) (*core.ResponseGetBlock, error) {
values, err := argsToURLValues([]string{"height"}, height)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["GetBlock"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGetBlock `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error) {
values, err := argsToURLValues([]string{"address", "key"}, address, key)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["GetStorage"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGetStorage `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) ListAccounts() (*core.ResponseListAccounts, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["ListAccounts"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseListAccounts `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) ListValidators() (*core.ResponseListValidators, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["ListValidators"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseListValidators `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) NetInfo() (*core.ResponseNetInfo, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["NetInfo"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseNetInfo `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error) {
values, err := argsToURLValues([]string{"tx", "priv_accounts"}, tx, privAccounts)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["SignTx"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseSignTx `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) Status() (*core.ResponseStatus, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["Status"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseStatus `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) BlockchainInfo(minHeight uint, maxHeight uint) (*core.ResponseBlockchainInfo, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["BlockchainInfo"],
Params: []interface{}{minHeight, maxHeight},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseBlockchainInfo `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) BroadcastTx(tx types.Tx) (*core.ResponseBroadcastTx, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["BroadcastTx"],
Params: []interface{}{tx},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseBroadcastTx `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) Call(address []byte, data []byte) (*core.ResponseCall, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["Call"],
Params: []interface{}{address, data},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseCall `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) CallCode(code []byte, data []byte) (*core.ResponseCall, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["CallCode"],
Params: []interface{}{code, data},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseCall `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) DumpStorage(addr []byte) (*core.ResponseDumpStorage, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["DumpStorage"],
Params: []interface{}{addr},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseDumpStorage `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) GenPrivAccount() (*core.ResponseGenPrivAccount, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["GenPrivAccount"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGenPrivAccount `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) GetAccount(address []byte) (*core.ResponseGetAccount, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["GetAccount"],
Params: []interface{}{address},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGetAccount `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) GetBlock(height uint) (*core.ResponseGetBlock, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["GetBlock"],
Params: []interface{}{height},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGetBlock `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) GetStorage(address []byte, key []byte) (*core.ResponseGetStorage, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["GetStorage"],
Params: []interface{}{address, key},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseGetStorage `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) ListAccounts() (*core.ResponseListAccounts, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["ListAccounts"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseListAccounts `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) ListValidators() (*core.ResponseListValidators, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["ListValidators"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseListValidators `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) NetInfo() (*core.ResponseNetInfo, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["NetInfo"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseNetInfo `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*core.ResponseSignTx, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["SignTx"],
Params: []interface{}{tx, privAccounts},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseSignTx `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) Status() (*core.ResponseStatus, error) {
request := RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["Status"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *core.ResponseStatus `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}

Loading…
Cancel
Save