github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/btcjson/chainsvrresults.go (about) 1 // Copyright (c) 2014 The btcsuite developers 2 // Copyright (c) 2016 The Dash developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package btcjson 7 8 import "encoding/json" 9 10 // GetBlockHeaderVerboseResult models the data from the getblockheader command when 11 // the verbose flag is set. When the verbose flag is not set, getblockheader 12 // returns a hex-encoded string. 13 type GetBlockHeaderVerboseResult struct { 14 Hash string `json:"hash"` 15 Confirmations uint64 `json:"confirmations"` 16 Height int32 `json:"height"` 17 Version int32 `json:"version"` 18 MerkleRoot string `json:"merkleroot"` 19 Time int64 `json:"time"` 20 Nonce uint64 `json:"nonce"` 21 Bits string `json:"bits"` 22 Difficulty float64 `json:"difficulty"` 23 PreviousHash string `json:"previousblockhash,omitempty"` 24 NextHash string `json:"nextblockhash,omitempty"` 25 } 26 27 // GetBlockVerboseResult models the data from the getblock command when the 28 // verbose flag is set. When the verbose flag is not set, getblock returns a 29 // hex-encoded string. 30 type GetBlockVerboseResult struct { 31 Hash string `json:"hash"` 32 Confirmations uint64 `json:"confirmations"` 33 Size int32 `json:"size"` 34 Height int64 `json:"height"` 35 Version int32 `json:"version"` 36 MerkleRoot string `json:"merkleroot"` 37 Tx []string `json:"tx,omitempty"` 38 RawTx []TxRawResult `json:"rawtx,omitempty"` 39 Time int64 `json:"time"` 40 Nonce uint32 `json:"nonce"` 41 Bits string `json:"bits"` 42 Difficulty float64 `json:"difficulty"` 43 PreviousHash string `json:"previousblockhash"` 44 NextHash string `json:"nextblockhash,omitempty"` 45 } 46 47 // CreateMultiSigResult models the data returned from the createmultisig 48 // command. 49 type CreateMultiSigResult struct { 50 Address string `json:"address"` 51 RedeemScript string `json:"redeemScript"` 52 } 53 54 // DecodeScriptResult models the data returned from the decodescript command. 55 type DecodeScriptResult struct { 56 Asm string `json:"asm"` 57 ReqSigs int32 `json:"reqSigs,omitempty"` 58 Type string `json:"type"` 59 Addresses []string `json:"addresses,omitempty"` 60 P2sh string `json:"p2sh"` 61 } 62 63 // GetAddedNodeInfoResultAddr models the data of the addresses portion of the 64 // getaddednodeinfo command. 65 type GetAddedNodeInfoResultAddr struct { 66 Address string `json:"address"` 67 Connected string `json:"connected"` 68 } 69 70 // GetAddedNodeInfoResult models the data from the getaddednodeinfo command. 71 type GetAddedNodeInfoResult struct { 72 AddedNode string `json:"addednode"` 73 Connected *bool `json:"connected,omitempty"` 74 Addresses *[]GetAddedNodeInfoResultAddr `json:"addresses,omitempty"` 75 } 76 77 // GetBlockChainInfoResult models the data returned from the getblockchaininfo 78 // command. 79 type GetBlockChainInfoResult struct { 80 Chain string `json:"chain"` 81 Blocks int32 `json:"blocks"` 82 Headers int32 `json:"headers"` 83 BestBlockHash string `json:"bestblockhash"` 84 Difficulty float64 `json:"difficulty"` 85 VerificationProgress float64 `json:"verificationprogress"` 86 ChainWork string `json:"chainwork"` 87 } 88 89 // GetBlockTemplateResultTx models the transactions field of the 90 // getblocktemplate command. 91 type GetBlockTemplateResultTx struct { 92 Data string `json:"data"` 93 Hash string `json:"hash"` 94 Depends []int64 `json:"depends"` 95 Fee int64 `json:"fee"` 96 SigOps int64 `json:"sigops"` 97 } 98 99 // GetBlockTemplateResultAux models the coinbaseaux field of the 100 // getblocktemplate command. 101 type GetBlockTemplateResultAux struct { 102 Flags string `json:"flags"` 103 } 104 105 // GetBlockTemplateResult models the data returned from the getblocktemplate 106 // command. 107 type GetBlockTemplateResult struct { 108 // Base fields from BIP 0022. CoinbaseAux is optional. One of 109 // CoinbaseTxn or CoinbaseValue must be specified, but not both. 110 Bits string `json:"bits"` 111 CurTime int64 `json:"curtime"` 112 Height int64 `json:"height"` 113 PreviousHash string `json:"previousblockhash"` 114 SigOpLimit int64 `json:"sigoplimit,omitempty"` 115 SizeLimit int64 `json:"sizelimit,omitempty"` 116 Transactions []GetBlockTemplateResultTx `json:"transactions"` 117 Version int32 `json:"version"` 118 CoinbaseAux *GetBlockTemplateResultAux `json:"coinbaseaux,omitempty"` 119 CoinbaseTxn *GetBlockTemplateResultTx `json:"coinbasetxn,omitempty"` 120 CoinbaseValue *int64 `json:"coinbasevalue,omitempty"` 121 WorkID string `json:"workid,omitempty"` 122 123 // Optional long polling from BIP 0022. 124 LongPollID string `json:"longpollid,omitempty"` 125 LongPollURI string `json:"longpolluri,omitempty"` 126 SubmitOld *bool `json:"submitold,omitempty"` 127 128 // Basic pool extension from BIP 0023. 129 Target string `json:"target,omitempty"` 130 Expires int64 `json:"expires,omitempty"` 131 132 // Mutations from BIP 0023. 133 MaxTime int64 `json:"maxtime,omitempty"` 134 MinTime int64 `json:"mintime,omitempty"` 135 Mutable []string `json:"mutable,omitempty"` 136 NonceRange string `json:"noncerange,omitempty"` 137 138 // Block proposal from BIP 0023. 139 Capabilities []string `json:"capabilities,omitempty"` 140 RejectReasion string `json:"reject-reason,omitempty"` 141 } 142 143 // GetMempoolInfoResult models the data returned from the getmempoolinfo 144 // command. 145 type GetMempoolInfoResult struct { 146 Size int64 `json:"size"` 147 Bytes int64 `json:"bytes"` 148 } 149 150 // GetNetworkInfoResult models the data returned from the getnetworkinfo 151 // command. 152 type GetNetworkInfoResult struct { 153 Version int32 `json:"version"` 154 ProtocolVersion int32 `json:"protocolversion"` 155 TimeOffset int64 `json:"timeoffset"` 156 Connections int32 `json:"connections"` 157 Networks []NetworksResult `json:"networks"` 158 RelayFee float64 `json:"relayfee"` 159 LocalAddresses []LocalAddressesResult `json:"localaddresses"` 160 } 161 162 // GetPeerInfoResult models the data returned from the getpeerinfo command. 163 type GetPeerInfoResult struct { 164 ID int32 `json:"id"` 165 Addr string `json:"addr"` 166 AddrLocal string `json:"addrlocal,omitempty"` 167 Services string `json:"services"` 168 LastSend int64 `json:"lastsend"` 169 LastRecv int64 `json:"lastrecv"` 170 BytesSent uint64 `json:"bytessent"` 171 BytesRecv uint64 `json:"bytesrecv"` 172 ConnTime int64 `json:"conntime"` 173 TimeOffset int64 `json:"timeoffset"` 174 PingTime float64 `json:"pingtime"` 175 PingWait float64 `json:"pingwait,omitempty"` 176 Version uint32 `json:"version"` 177 SubVer string `json:"subver"` 178 Inbound bool `json:"inbound"` 179 StartingHeight int32 `json:"startingheight"` 180 CurrentHeight int32 `json:"currentheight,omitempty"` 181 BanScore int32 `json:"banscore"` 182 SyncNode bool `json:"syncnode"` 183 } 184 185 // GetRawMempoolVerboseResult models the data returned from the getrawmempool 186 // command when the verbose flag is set. When the verbose flag is not set, 187 // getrawmempool returns an array of transaction hashes. 188 type GetRawMempoolVerboseResult struct { 189 Size int32 `json:"size"` 190 Fee float64 `json:"fee"` 191 Time int64 `json:"time"` 192 Height int64 `json:"height"` 193 StartingPriority float64 `json:"startingpriority"` 194 CurrentPriority float64 `json:"currentpriority"` 195 Depends []string `json:"depends"` 196 } 197 198 // ScriptPubKeyResult models the scriptPubKey data of a tx script. It is 199 // defined separately since it is used by multiple commands. 200 type ScriptPubKeyResult struct { 201 Asm string `json:"asm"` 202 Hex string `json:"hex,omitempty"` 203 ReqSigs int32 `json:"reqSigs,omitempty"` 204 Type string `json:"type"` 205 Addresses []string `json:"addresses,omitempty"` 206 } 207 208 // GetTxOutResult models the data from the gettxout command. 209 type GetTxOutResult struct { 210 BestBlock string `json:"bestblock"` 211 Confirmations int64 `json:"confirmations"` 212 Value float64 `json:"value"` 213 ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"` 214 Version int32 `json:"version"` 215 Coinbase bool `json:"coinbase"` 216 } 217 218 // GetNetTotalsResult models the data returned from the getnettotals command. 219 type GetNetTotalsResult struct { 220 TotalBytesRecv uint64 `json:"totalbytesrecv"` 221 TotalBytesSent uint64 `json:"totalbytessent"` 222 TimeMillis int64 `json:"timemillis"` 223 } 224 225 // ScriptSig models a signature script. It is defined separately since it only 226 // applies to non-coinbase. Therefore the field in the Vin structure needs 227 // to be a pointer. 228 type ScriptSig struct { 229 Asm string `json:"asm"` 230 Hex string `json:"hex"` 231 } 232 233 // Vin models parts of the tx data. It is defined separately since 234 // getrawtransaction, decoderawtransaction, and searchrawtransaction use the 235 // same structure. 236 type Vin struct { 237 Coinbase string `json:"coinbase"` 238 Txid string `json:"txid"` 239 Vout uint32 `json:"vout"` 240 ScriptSig *ScriptSig `json:"scriptSig"` 241 Sequence uint32 `json:"sequence"` 242 } 243 244 // IsCoinBase returns a bool to show if a Vin is a Coinbase one or not. 245 func (v *Vin) IsCoinBase() bool { 246 return len(v.Coinbase) > 0 247 } 248 249 // MarshalJSON provides a custom Marshal method for Vin. 250 func (v *Vin) MarshalJSON() ([]byte, error) { 251 if v.IsCoinBase() { 252 coinbaseStruct := struct { 253 Coinbase string `json:"coinbase"` 254 Sequence uint32 `json:"sequence"` 255 }{ 256 Coinbase: v.Coinbase, 257 Sequence: v.Sequence, 258 } 259 return json.Marshal(coinbaseStruct) 260 } 261 262 txStruct := struct { 263 Txid string `json:"txid"` 264 Vout uint32 `json:"vout"` 265 ScriptSig *ScriptSig `json:"scriptSig"` 266 Sequence uint32 `json:"sequence"` 267 }{ 268 Txid: v.Txid, 269 Vout: v.Vout, 270 ScriptSig: v.ScriptSig, 271 Sequence: v.Sequence, 272 } 273 return json.Marshal(txStruct) 274 } 275 276 // PrevOut represents previous output for an input Vin. 277 type PrevOut struct { 278 Addresses []string `json:"addresses,omitempty"` 279 Value float64 `json:"value"` 280 } 281 282 // VinPrevOut is like Vin except it includes PrevOut. It is used by searchrawtransaction 283 type VinPrevOut struct { 284 Coinbase string `json:"coinbase"` 285 Txid string `json:"txid"` 286 Vout uint32 `json:"vout"` 287 ScriptSig *ScriptSig `json:"scriptSig"` 288 PrevOut *PrevOut `json:"prevOut"` 289 Sequence uint32 `json:"sequence"` 290 } 291 292 // IsCoinBase returns a bool to show if a Vin is a Coinbase one or not. 293 func (v *VinPrevOut) IsCoinBase() bool { 294 return len(v.Coinbase) > 0 295 } 296 297 // MarshalJSON provides a custom Marshal method for VinPrevOut. 298 func (v *VinPrevOut) MarshalJSON() ([]byte, error) { 299 if v.IsCoinBase() { 300 coinbaseStruct := struct { 301 Coinbase string `json:"coinbase"` 302 Sequence uint32 `json:"sequence"` 303 }{ 304 Coinbase: v.Coinbase, 305 Sequence: v.Sequence, 306 } 307 return json.Marshal(coinbaseStruct) 308 } 309 310 txStruct := struct { 311 Txid string `json:"txid"` 312 Vout uint32 `json:"vout"` 313 ScriptSig *ScriptSig `json:"scriptSig"` 314 PrevOut *PrevOut `json:"prevOut,omitempty"` 315 Sequence uint32 `json:"sequence"` 316 }{ 317 Txid: v.Txid, 318 Vout: v.Vout, 319 ScriptSig: v.ScriptSig, 320 PrevOut: v.PrevOut, 321 Sequence: v.Sequence, 322 } 323 return json.Marshal(txStruct) 324 } 325 326 // Vout models parts of the tx data. It is defined separately since both 327 // getrawtransaction and decoderawtransaction use the same structure. 328 type Vout struct { 329 Value float64 `json:"value"` 330 N uint32 `json:"n"` 331 ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"` 332 } 333 334 // GetMiningInfoResult models the data from the getmininginfo command. 335 type GetMiningInfoResult struct { 336 Blocks int64 `json:"blocks"` 337 CurrentBlockSize uint64 `json:"currentblocksize"` 338 CurrentBlockTx uint64 `json:"currentblocktx"` 339 Difficulty float64 `json:"difficulty"` 340 Errors string `json:"errors"` 341 Generate bool `json:"generate"` 342 GenProcLimit int32 `json:"genproclimit"` 343 HashesPerSec int64 `json:"hashespersec"` 344 NetworkHashPS int64 `json:"networkhashps"` 345 PooledTx uint64 `json:"pooledtx"` 346 TestNet bool `json:"testnet"` 347 } 348 349 // GetWorkResult models the data from the getwork command. 350 type GetWorkResult struct { 351 Data string `json:"data"` 352 Hash1 string `json:"hash1"` 353 Midstate string `json:"midstate"` 354 Target string `json:"target"` 355 } 356 357 // InfoChainResult models the data returned by the chain server getinfo command. 358 type InfoChainResult struct { 359 Version int32 `json:"version"` 360 ProtocolVersion int32 `json:"protocolversion"` 361 Blocks int32 `json:"blocks"` 362 TimeOffset int64 `json:"timeoffset"` 363 Connections int32 `json:"connections"` 364 Proxy string `json:"proxy"` 365 Difficulty float64 `json:"difficulty"` 366 TestNet bool `json:"testnet"` 367 RelayFee float64 `json:"relayfee"` 368 Errors string `json:"errors"` 369 } 370 371 // LocalAddressesResult models the localaddresses data from the getnetworkinfo 372 // command. 373 type LocalAddressesResult struct { 374 Address string `json:"address"` 375 Port uint16 `json:"port"` 376 Score int32 `json:"score"` 377 } 378 379 // NetworksResult models the networks data from the getnetworkinfo command. 380 type NetworksResult struct { 381 Name string `json:"name"` 382 Limited bool `json:"limited"` 383 Reachable bool `json:"reachable"` 384 Proxy string `json:"proxy"` 385 } 386 387 // TxRawResult models the data from the getrawtransaction command. 388 type TxRawResult struct { 389 Hex string `json:"hex"` 390 Txid string `json:"txid"` 391 Version int32 `json:"version"` 392 LockTime uint32 `json:"locktime"` 393 Vin []Vin `json:"vin"` 394 Vout []Vout `json:"vout"` 395 BlockHash string `json:"blockhash,omitempty"` 396 Confirmations uint64 `json:"confirmations,omitempty"` 397 Time int64 `json:"time,omitempty"` 398 Blocktime int64 `json:"blocktime,omitempty"` 399 } 400 401 // SearchRawTransactionsResult models the data from the searchrawtransaction 402 // command. 403 type SearchRawTransactionsResult struct { 404 Hex string `json:"hex,omitempty"` 405 Txid string `json:"txid"` 406 Version int32 `json:"version"` 407 LockTime uint32 `json:"locktime"` 408 Vin []VinPrevOut `json:"vin"` 409 Vout []Vout `json:"vout"` 410 BlockHash string `json:"blockhash,omitempty"` 411 Confirmations uint64 `json:"confirmations,omitempty"` 412 Time int64 `json:"time,omitempty"` 413 Blocktime int64 `json:"blocktime,omitempty"` 414 } 415 416 // TxRawDecodeResult models the data from the decoderawtransaction command. 417 type TxRawDecodeResult struct { 418 Txid string `json:"txid"` 419 Version int32 `json:"version"` 420 Locktime uint32 `json:"locktime"` 421 Vin []Vin `json:"vin"` 422 Vout []Vout `json:"vout"` 423 } 424 425 // ValidateAddressChainResult models the data returned by the chain server 426 // validateaddress command. 427 type ValidateAddressChainResult struct { 428 IsValid bool `json:"isvalid"` 429 Address string `json:"address,omitempty"` 430 }