@ -3,10 +3,12 @@ package coretypes
import (
import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"time"
"time"
abci "github.com/tendermint/tendermint/abci/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/internal/jsontypes"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/bytes"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/types"
@ -26,7 +28,7 @@ var (
// List of blocks
// List of blocks
type ResultBlockchainInfo struct {
type ResultBlockchainInfo struct {
LastHeight int64 ` json:"last_height" `
LastHeight int64 ` json:"last_height,string " `
BlockMetas [ ] * types . BlockMeta ` json:"block_metas" `
BlockMetas [ ] * types . BlockMeta ` json:"block_metas" `
}
}
@ -40,8 +42,8 @@ type ResultGenesis struct {
// document to JSON and then splitting the resulting payload into
// document to JSON and then splitting the resulting payload into
// 16 megabyte blocks and then base64 encoding each block.
// 16 megabyte blocks and then base64 encoding each block.
type ResultGenesisChunk struct {
type ResultGenesisChunk struct {
ChunkNumber int ` json:"chunk" `
TotalChunks int ` json:"total" `
ChunkNumber int ` json:"chunk,string " `
TotalChunks int ` json:"total,string " `
Data string ` json:"data" `
Data string ` json:"data" `
}
}
@ -64,9 +66,9 @@ type ResultCommit struct {
// ABCI results from a block
// ABCI results from a block
type ResultBlockResults struct {
type ResultBlockResults struct {
Height int64 ` json:"height" `
Height int64 ` json:"height,string " `
TxsResults [ ] * abci . ResponseDeliverTx ` json:"txs_results" `
TxsResults [ ] * abci . ResponseDeliverTx ` json:"txs_results" `
TotalGasUsed int64 ` json:"total_gas_used" `
TotalGasUsed int64 ` json:"total_gas_used,string " `
BeginBlockEvents [ ] abci . Event ` json:"begin_block_events" `
BeginBlockEvents [ ] abci . Event ` json:"begin_block_events" `
EndBlockEvents [ ] abci . Event ` json:"end_block_events" `
EndBlockEvents [ ] abci . Event ` json:"end_block_events" `
ValidatorUpdates [ ] abci . ValidatorUpdate ` json:"validator_updates" `
ValidatorUpdates [ ] abci . ValidatorUpdate ` json:"validator_updates" `
@ -91,35 +93,64 @@ func NewResultCommit(header *types.Header, commit *types.Commit,
type SyncInfo struct {
type SyncInfo struct {
LatestBlockHash bytes . HexBytes ` json:"latest_block_hash" `
LatestBlockHash bytes . HexBytes ` json:"latest_block_hash" `
LatestAppHash bytes . HexBytes ` json:"latest_app_hash" `
LatestAppHash bytes . HexBytes ` json:"latest_app_hash" `
LatestBlockHeight int64 ` json:"latest_block_height" `
LatestBlockHeight int64 ` json:"latest_block_height,string " `
LatestBlockTime time . Time ` json:"latest_block_time" `
LatestBlockTime time . Time ` json:"latest_block_time" `
EarliestBlockHash bytes . HexBytes ` json:"earliest_block_hash" `
EarliestBlockHash bytes . HexBytes ` json:"earliest_block_hash" `
EarliestAppHash bytes . HexBytes ` json:"earliest_app_hash" `
EarliestAppHash bytes . HexBytes ` json:"earliest_app_hash" `
EarliestBlockHeight int64 ` json:"earliest_block_height" `
EarliestBlockHeight int64 ` json:"earliest_block_height,string " `
EarliestBlockTime time . Time ` json:"earliest_block_time" `
EarliestBlockTime time . Time ` json:"earliest_block_time" `
MaxPeerBlockHeight int64 ` json:"max_peer_block_height" `
MaxPeerBlockHeight int64 ` json:"max_peer_block_height,string " `
CatchingUp bool ` json:"catching_up" `
CatchingUp bool ` json:"catching_up" `
TotalSyncedTime time . Duration ` json:"total_synced_time" `
RemainingTime time . Duration ` json:"remaining_time" `
TotalSyncedTime time . Duration ` json:"total_synced_time,string " `
RemainingTime time . Duration ` json:"remaining_time,string " `
TotalSnapshots int64 ` json:"total_snapshots" `
ChunkProcessAvgTime time . Duration ` json:"chunk_process_avg_time" `
SnapshotHeight int64 ` json:"snapshot_height" `
SnapshotChunksCount int64 ` json:"snapshot_chunks_count" `
SnapshotChunksTotal int64 ` json:"snapshot_chunks_total" `
BackFilledBlocks int64 ` json:"backfilled_blocks" `
BackFillBlocksTotal int64 ` json:"backfill_blocks_total" `
TotalSnapshots int64 ` json:"total_snapshots,string " `
ChunkProcessAvgTime time . Duration ` json:"chunk_process_avg_time,string " `
SnapshotHeight int64 ` json:"snapshot_height,string " `
SnapshotChunksCount int64 ` json:"snapshot_chunks_count,string " `
SnapshotChunksTotal int64 ` json:"snapshot_chunks_total,string " `
BackFilledBlocks int64 ` json:"backfilled_blocks,string " `
BackFillBlocksTotal int64 ` json:"backfill_blocks_total,string " `
}
}
// Info about the node's validator
// Info about the node's validator
type ValidatorInfo struct {
type ValidatorInfo struct {
Address bytes . HexBytes ` json:"address" `
PubKey crypto . PubKey ` json:"pub_key" `
VotingPower int64 ` json:"voting_power" `
Address bytes . HexBytes
PubKey crypto . PubKey
VotingPower int64
}
type validatorInfoJSON struct {
Address bytes . HexBytes ` json:"address" `
PubKey json . RawMessage ` json:"pub_key" `
VotingPower int64 ` json:"voting_power,string" `
}
func ( v ValidatorInfo ) MarshalJSON ( ) ( [ ] byte , error ) {
pk , err := jsontypes . Marshal ( v . PubKey )
if err != nil {
return nil , err
}
return json . Marshal ( validatorInfoJSON {
Address : v . Address , PubKey : pk , VotingPower : v . VotingPower ,
} )
}
func ( v * ValidatorInfo ) UnmarshalJSON ( data [ ] byte ) error {
var val validatorInfoJSON
if err := json . Unmarshal ( data , & val ) ; err != nil {
return err
}
if err := jsontypes . Unmarshal ( val . PubKey , & v . PubKey ) ; err != nil {
return err
}
v . Address = val . Address
v . VotingPower = val . VotingPower
return nil
}
}
// Node Status
// Node Status
@ -142,7 +173,7 @@ func (s *ResultStatus) TxIndexEnabled() bool {
type ResultNetInfo struct {
type ResultNetInfo struct {
Listening bool ` json:"listening" `
Listening bool ` json:"listening" `
Listeners [ ] string ` json:"listeners" `
Listeners [ ] string ` json:"listeners" `
NPeers int ` json:"n_peers" `
NPeers int ` json:"n_peers,string " `
Peers [ ] Peer ` json:"peers" `
Peers [ ] Peer ` json:"peers" `
}
}
@ -164,12 +195,11 @@ type Peer struct {
// Validators for a height.
// Validators for a height.
type ResultValidators struct {
type ResultValidators struct {
BlockHeight int64 ` json:"block_height" `
BlockHeight int64 ` json:"block_height,string " `
Validators [ ] * types . Validator ` json:"validators" `
Validators [ ] * types . Validator ` json:"validators" `
// Count of actual validators in this result
Count int ` json:"count" `
// Total number of validators
Total int ` json:"total" `
Count int ` json:"count,string" ` // Count of actual validators in this result
Total int ` json:"total,string" ` // Total number of validators
}
}
// ConsensusParams for given height
// ConsensusParams for given height
@ -203,8 +233,7 @@ type ResultBroadcastTx struct {
Log string ` json:"log" `
Log string ` json:"log" `
Codespace string ` json:"codespace" `
Codespace string ` json:"codespace" `
MempoolError string ` json:"mempool_error" `
MempoolError string ` json:"mempool_error" `
Hash bytes . HexBytes ` json:"hash" `
Hash bytes . HexBytes ` json:"hash" `
}
}
// CheckTx and DeliverTx results
// CheckTx and DeliverTx results
@ -212,7 +241,7 @@ type ResultBroadcastTxCommit struct {
CheckTx abci . ResponseCheckTx ` json:"check_tx" `
CheckTx abci . ResponseCheckTx ` json:"check_tx" `
DeliverTx abci . ResponseDeliverTx ` json:"deliver_tx" `
DeliverTx abci . ResponseDeliverTx ` json:"deliver_tx" `
Hash bytes . HexBytes ` json:"hash" `
Hash bytes . HexBytes ` json:"hash" `
Height int64 ` json:"height" `
Height int64 ` json:"height,string " `
}
}
// ResultCheckTx wraps abci.ResponseCheckTx.
// ResultCheckTx wraps abci.ResponseCheckTx.
@ -223,7 +252,7 @@ type ResultCheckTx struct {
// Result of querying for a tx
// Result of querying for a tx
type ResultTx struct {
type ResultTx struct {
Hash bytes . HexBytes ` json:"hash" `
Hash bytes . HexBytes ` json:"hash" `
Height int64 ` json:"height" `
Height int64 ` json:"height,string " `
Index uint32 ` json:"index" `
Index uint32 ` json:"index" `
TxResult abci . ResponseDeliverTx ` json:"tx_result" `
TxResult abci . ResponseDeliverTx ` json:"tx_result" `
Tx types . Tx ` json:"tx" `
Tx types . Tx ` json:"tx" `
@ -233,20 +262,20 @@ type ResultTx struct {
// Result of searching for txs
// Result of searching for txs
type ResultTxSearch struct {
type ResultTxSearch struct {
Txs [ ] * ResultTx ` json:"txs" `
Txs [ ] * ResultTx ` json:"txs" `
TotalCount int ` json:"total_count" `
TotalCount int ` json:"total_count,string " `
}
}
// ResultBlockSearch defines the RPC response type for a block search by events.
// ResultBlockSearch defines the RPC response type for a block search by events.
type ResultBlockSearch struct {
type ResultBlockSearch struct {
Blocks [ ] * ResultBlock ` json:"blocks" `
Blocks [ ] * ResultBlock ` json:"blocks" `
TotalCount int ` json:"total_count" `
TotalCount int ` json:"total_count,string " `
}
}
// List of mempool txs
// List of mempool txs
type ResultUnconfirmedTxs struct {
type ResultUnconfirmedTxs struct {
Count int ` json:"n_txs" `
Total int ` json:"total" `
TotalBytes int64 ` json:"total_bytes" `
Count int ` json:"n_txs,string " `
Total int ` json:"total,string " `
TotalBytes int64 ` json:"total_bytes,string " `
Txs [ ] types . Tx ` json:"txs" `
Txs [ ] types . Tx ` json:"txs" `
}
}
@ -276,8 +305,55 @@ type (
// Event data from a subscription
// Event data from a subscription
type ResultEvent struct {
type ResultEvent struct {
SubscriptionID string ` json:"subscription_id" `
Query string ` json:"query" `
Data types . TMEventData ` json:"data" `
Events [ ] abci . Event ` json:"events" `
SubscriptionID string
Query string
Data types . TMEventData
Events [ ] abci . Event
}
}
type resultEventJSON struct {
SubscriptionID string ` json:"subscription_id" `
Query string ` json:"query" `
Data json . RawMessage ` json:"data" `
Events [ ] abci . Event ` json:"events" `
}
func ( r ResultEvent ) MarshalJSON ( ) ( [ ] byte , error ) {
data , ok := r . Data . ( jsontypes . Tagged )
if ! ok {
return nil , fmt . Errorf ( "type %T is not tagged" , r . Data )
}
evt , err := jsontypes . Marshal ( data )
if err != nil {
return nil , err
}
return json . Marshal ( resultEventJSON {
SubscriptionID : r . SubscriptionID ,
Query : r . Query ,
Data : evt ,
Events : r . Events ,
} )
}
func ( r * ResultEvent ) UnmarshalJSON ( data [ ] byte ) error {
var res resultEventJSON
if err := json . Unmarshal ( data , & res ) ; err != nil {
return err
}
if err := jsontypes . Unmarshal ( res . Data , & r . Data ) ; err != nil {
return err
}
r . SubscriptionID = res . SubscriptionID
r . Query = res . Query
r . Events = res . Events
return nil
}
// Evidence is an argument wrapper for a types.Evidence value, that handles
// encoding and decoding through JSON.
type Evidence struct {
Value types . Evidence
}
func ( e Evidence ) MarshalJSON ( ) ( [ ] byte , error ) { return jsontypes . Marshal ( e . Value ) }
func ( e * Evidence ) UnmarshalJSON ( data [ ] byte ) error { return jsontypes . Unmarshal ( data , & e . Value ) }