github.com/datachainlab/burrow@v0.25.0/rpc/result.go (about) 1 // Copyright 2017 Monax Industries Limited 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package rpc 16 17 import ( 18 "github.com/hyperledger/burrow/acm" 19 "github.com/hyperledger/burrow/acm/validator" 20 "github.com/hyperledger/burrow/binary" 21 "github.com/hyperledger/burrow/consensus/tendermint" 22 "github.com/hyperledger/burrow/crypto" 23 "github.com/hyperledger/burrow/execution/names" 24 "github.com/hyperledger/burrow/genesis" 25 "github.com/hyperledger/burrow/txs" 26 amino "github.com/tendermint/go-amino" 27 "github.com/tendermint/tendermint/consensus" 28 ctypes "github.com/tendermint/tendermint/consensus/types" 29 core_types "github.com/tendermint/tendermint/rpc/core/types" 30 tmTypes "github.com/tendermint/tendermint/types" 31 ) 32 33 // When using Tendermint types like Block and Vote we are forced to wrap the outer object and use amino marshalling 34 var aminoCodec = NewAminoCodec() 35 36 func NewAminoCodec() *amino.Codec { 37 aminoCodec := amino.NewCodec() 38 consensus.RegisterConsensusMessages(aminoCodec) 39 core_types.RegisterAmino(aminoCodec) 40 return aminoCodec 41 } 42 43 type ResultStorage struct { 44 Key binary.HexBytes 45 Value binary.HexBytes 46 } 47 48 type ResultAccounts struct { 49 BlockHeight uint64 50 Accounts []*acm.Account 51 } 52 53 type ResultDumpStorage struct { 54 StorageItems []StorageItem 55 } 56 57 type StorageItem struct { 58 Key binary.HexBytes 59 Value binary.HexBytes 60 } 61 62 type ResultBlocks struct { 63 LastHeight uint64 64 BlockMetas []*tmTypes.BlockMeta 65 } 66 67 type ResultBlock struct { 68 BlockMeta *BlockMeta 69 Block *Block 70 } 71 72 type BlockMeta struct { 73 *tmTypes.BlockMeta 74 } 75 76 func (bm BlockMeta) MarshalJSON() ([]byte, error) { 77 return aminoCodec.MarshalJSON(bm.BlockMeta) 78 } 79 80 func (bm *BlockMeta) UnmarshalJSON(data []byte) (err error) { 81 return aminoCodec.UnmarshalJSON(data, &bm.BlockMeta) 82 } 83 84 // Needed for go-amino handling of interface types 85 type Block struct { 86 *tmTypes.Block 87 } 88 89 func (b Block) MarshalJSON() ([]byte, error) { 90 return aminoCodec.MarshalJSON(b.Block) 91 } 92 93 func (b *Block) UnmarshalJSON(data []byte) (err error) { 94 return aminoCodec.UnmarshalJSON(data, &b.Block) 95 } 96 97 type ResultChainId struct { 98 ChainName string 99 ChainId string 100 GenesisHash binary.HexBytes 101 } 102 103 type ResultSubscribe struct { 104 EventID string 105 SubscriptionID string 106 } 107 108 type ResultUnsubscribe struct { 109 SubscriptionID string 110 } 111 112 type ResultNetwork struct { 113 ThisNode *tendermint.NodeInfo 114 *core_types.ResultNetInfo 115 } 116 117 type ResultValidators struct { 118 BlockHeight uint64 119 BondedValidators []*validator.Validator 120 UnbondingValidators []*validator.Validator 121 } 122 123 type ResultConsensusState struct { 124 *core_types.ResultDumpConsensusState 125 } 126 127 // TODO use round state in ResultConsensusState - currently there are some part of RoundState have no Unmarshal 128 type RoundState struct { 129 *ctypes.RoundState 130 } 131 132 func (rs RoundState) MarshalJSON() ([]byte, error) { 133 return aminoCodec.MarshalJSON(rs.RoundState) 134 } 135 136 func (rs *RoundState) UnmarshalJSON(data []byte) (err error) { 137 return aminoCodec.UnmarshalJSON(data, &rs.RoundState) 138 } 139 140 type ResultPeers struct { 141 Peers []core_types.Peer 142 } 143 144 type ResultNames struct { 145 BlockHeight uint64 146 Names []*names.Entry 147 } 148 149 type ResultGeneratePrivateAccount struct { 150 PrivateAccount *acm.ConcretePrivateAccount 151 } 152 153 type ResultAccount struct { 154 Account *acm.Account 155 } 156 157 type AccountHumanReadable struct { 158 Address crypto.Address 159 PublicKey crypto.PublicKey 160 Sequence uint64 161 Balance uint64 162 Code []string 163 Permissions []string 164 Roles []string 165 } 166 167 type ResultAccountHumanReadable struct { 168 Account *AccountHumanReadable 169 } 170 171 type ResultAccountStats struct { 172 AccountsWithCode uint64 173 AccountsWithoutCode uint64 174 } 175 176 type ResultUnconfirmedTxs struct { 177 NumTxs int 178 Txs []*txs.Envelope 179 } 180 181 type ResultName struct { 182 Entry *names.Entry 183 } 184 185 type ResultGenesis struct { 186 Genesis genesis.GenesisDoc 187 } 188 189 type ResultSignTx struct { 190 Tx *txs.Envelope 191 }