chainsvrresults.go
1 // Copyright (c) 2014-2017 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package btcjson 6 7 import "encoding/json" 8 9 // GetBlockHeaderVerboseResult models the data from the getblockheader command when 10 // the verbose flag is set. When the verbose flag is not set, getblockheader 11 // returns a hex-encoded string. 12 type GetBlockHeaderVerboseResult struct { 13 Hash string `json:"hash"` 14 Confirmations uint64 `json:"confirmations"` 15 Height int32 `json:"height"` 16 Version int32 `json:"version"` 17 VersionHex string `json:"versionHex"` 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 StrippedSize int32 `json:"strippedsize"` 34 Size int32 `json:"size"` 35 Weight int32 `json:"weight"` 36 Height int64 `json:"height"` 37 Version int32 `json:"version"` 38 VersionHex string `json:"versionHex"` 39 MerkleRoot string `json:"merkleroot"` 40 Tx []string `json:"tx,omitempty"` 41 RawTx []TxRawResult `json:"rawtx,omitempty"` 42 Time int64 `json:"time"` 43 Nonce uint32 `json:"nonce"` 44 Bits string `json:"bits"` 45 Difficulty float64 `json:"difficulty"` 46 PreviousHash string `json:"previousblockhash"` 47 NextHash string `json:"nextblockhash,omitempty"` 48 } 49 50 // CreateMultiSigResult models the data returned from the createmultisig 51 // command. 52 type CreateMultiSigResult struct { 53 Address string `json:"address"` 54 RedeemScript string `json:"redeemScript"` 55 } 56 57 // DecodeScriptResult models the data returned from the decodescript command. 58 type DecodeScriptResult struct { 59 Asm string `json:"asm"` 60 ReqSigs int32 `json:"reqSigs,omitempty"` 61 Type string `json:"type"` 62 Addresses []string `json:"addresses,omitempty"` 63 P2sh string `json:"p2sh,omitempty"` 64 } 65 66 // GetAddedNodeInfoResultAddr models the data of the addresses portion of the 67 // getaddednodeinfo command. 68 type GetAddedNodeInfoResultAddr struct { 69 Address string `json:"address"` 70 Connected string `json:"connected"` 71 } 72 73 // GetAddedNodeInfoResult models the data from the getaddednodeinfo command. 74 type GetAddedNodeInfoResult struct { 75 AddedNode string `json:"addednode"` 76 Connected *bool `json:"connected,omitempty"` 77 Addresses *[]GetAddedNodeInfoResultAddr `json:"addresses,omitempty"` 78 } 79 80 // SoftForkDescription describes the current state of a soft-fork which was 81 // deployed using a super-majority block signalling. 82 type SoftForkDescription struct { 83 ID string `json:"id"` 84 Version uint32 `json:"version"` 85 Reject struct { 86 Status bool `json:"status"` 87 } `json:"reject"` 88 } 89 90 // Bip9SoftForkDescription describes the current state of a defined BIP0009 91 // version bits soft-fork. 92 type Bip9SoftForkDescription struct { 93 Status string `json:"status"` 94 Bit uint8 `json:"bit"` 95 StartTime int64 `json:"startTime"` 96 Timeout int64 `json:"timeout"` 97 Since int32 `json:"since"` 98 } 99 100 // GetBlockChainInfoResult models the data returned from the getblockchaininfo 101 // command. 102 type GetBlockChainInfoResult struct { 103 Chain string `json:"chain"` 104 Blocks int32 `json:"blocks"` 105 Headers int32 `json:"headers"` 106 BestBlockHash string `json:"bestblockhash"` 107 Difficulty float64 `json:"difficulty"` 108 MedianTime int64 `json:"mediantime"` 109 VerificationProgress float64 `json:"verificationprogress,omitempty"` 110 Pruned bool `json:"pruned"` 111 PruneHeight int32 `json:"pruneheight,omitempty"` 112 ChainWork string `json:"chainwork,omitempty"` 113 SoftForks []*SoftForkDescription `json:"softforks"` 114 Bip9SoftForks map[string]*Bip9SoftForkDescription `json:"bip9_softforks"` 115 } 116 117 // GetBlockTemplateResultTx models the transactions field of the 118 // getblocktemplate command. 119 type GetBlockTemplateResultTx struct { 120 Data string `json:"data"` 121 Hash string `json:"hash"` 122 Depends []int64 `json:"depends"` 123 Fee int64 `json:"fee"` 124 SigOps int64 `json:"sigops"` 125 Weight int64 `json:"weight"` 126 } 127 128 // GetBlockTemplateResultAux models the coinbaseaux field of the 129 // getblocktemplate command. 130 type GetBlockTemplateResultAux struct { 131 Flags string `json:"flags"` 132 } 133 134 // GetBlockTemplateResult models the data returned from the getblocktemplate 135 // command. 136 type GetBlockTemplateResult struct { 137 // Base fields from BIP 0022. CoinbaseAux is optional. One of 138 // CoinbaseTxn or CoinbaseValue must be specified, but not both. 139 Bits string `json:"bits"` 140 CurTime int64 `json:"curtime"` 141 Height int64 `json:"height"` 142 PreviousHash string `json:"previousblockhash"` 143 SigOpLimit int64 `json:"sigoplimit,omitempty"` 144 SizeLimit int64 `json:"sizelimit,omitempty"` 145 WeightLimit int64 `json:"weightlimit,omitempty"` 146 Transactions []GetBlockTemplateResultTx `json:"transactions"` 147 Version int32 `json:"version"` 148 CoinbaseAux *GetBlockTemplateResultAux `json:"coinbaseaux,omitempty"` 149 CoinbaseTxn *GetBlockTemplateResultTx `json:"coinbasetxn,omitempty"` 150 CoinbaseValue *int64 `json:"coinbasevalue,omitempty"` 151 WorkID string `json:"workid,omitempty"` 152 153 // Witness commitment defined in BIP 0141. 154 DefaultWitnessCommitment string `json:"default_witness_commitment,omitempty"` 155 156 // Optional long polling from BIP 0022. 157 LongPollID string `json:"longpollid,omitempty"` 158 LongPollURI string `json:"longpolluri,omitempty"` 159 SubmitOld *bool `json:"submitold,omitempty"` 160 161 // Basic pool extension from BIP 0023. 162 Target string `json:"target,omitempty"` 163 Expires int64 `json:"expires,omitempty"` 164 165 // Mutations from BIP 0023. 166 MaxTime int64 `json:"maxtime,omitempty"` 167 MinTime int64 `json:"mintime,omitempty"` 168 Mutable []string `json:"mutable,omitempty"` 169 NonceRange string `json:"noncerange,omitempty"` 170 171 // Block proposal from BIP 0023. 172 Capabilities []string `json:"capabilities,omitempty"` 173 RejectReasion string `json:"reject-reason,omitempty"` 174 } 175 176 // GetMempoolEntryResult models the data returned from the getmempoolentry 177 // command. 178 type GetMempoolEntryResult struct { 179 Size int32 `json:"size"` 180 Fee float64 `json:"fee"` 181 ModifiedFee float64 `json:"modifiedfee"` 182 Time int64 `json:"time"` 183 Height int64 `json:"height"` 184 StartingPriority float64 `json:"startingpriority"` 185 CurrentPriority float64 `json:"currentpriority"` 186 DescendantCount int64 `json:"descendantcount"` 187 DescendantSize int64 `json:"descendantsize"` 188 DescendantFees float64 `json:"descendantfees"` 189 AncestorCount int64 `json:"ancestorcount"` 190 AncestorSize int64 `json:"ancestorsize"` 191 AncestorFees float64 `json:"ancestorfees"` 192 Depends []string `json:"depends"` 193 } 194 195 // GetMempoolInfoResult models the data returned from the getmempoolinfo 196 // command. 197 type GetMempoolInfoResult struct { 198 Size int64 `json:"size"` 199 Bytes int64 `json:"bytes"` 200 } 201 202 // NetworksResult models the networks data from the getnetworkinfo command. 203 type NetworksResult struct { 204 Name string `json:"name"` 205 Limited bool `json:"limited"` 206 Reachable bool `json:"reachable"` 207 Proxy string `json:"proxy"` 208 ProxyRandomizeCredentials bool `json:"proxy_randomize_credentials"` 209 } 210 211 // LocalAddressesResult models the localaddresses data from the getnetworkinfo 212 // command. 213 type LocalAddressesResult struct { 214 Address string `json:"address"` 215 Port uint16 `json:"port"` 216 Score int32 `json:"score"` 217 } 218 219 // GetNetworkInfoResult models the data returned from the getnetworkinfo 220 // command. 221 type GetNetworkInfoResult struct { 222 Version int32 `json:"version"` 223 SubVersion string `json:"subversion"` 224 ProtocolVersion int32 `json:"protocolversion"` 225 LocalServices string `json:"localservices"` 226 LocalRelay bool `json:"localrelay"` 227 TimeOffset int64 `json:"timeoffset"` 228 Connections int32 `json:"connections"` 229 NetworkActive bool `json:"networkactive"` 230 Networks []NetworksResult `json:"networks"` 231 RelayFee float64 `json:"relayfee"` 232 IncrementalFee float64 `json:"incrementalfee"` 233 LocalAddresses []LocalAddressesResult `json:"localaddresses"` 234 Warnings string `json:"warnings"` 235 } 236 237 // GetPeerInfoResult models the data returned from the getpeerinfo command. 238 type GetPeerInfoResult struct { 239 ID int32 `json:"id"` 240 Addr string `json:"addr"` 241 AddrLocal string `json:"addrlocal,omitempty"` 242 Services string `json:"services"` 243 RelayTxes bool `json:"relaytxes"` 244 LastSend int64 `json:"lastsend"` 245 LastRecv int64 `json:"lastrecv"` 246 BytesSent uint64 `json:"bytessent"` 247 BytesRecv uint64 `json:"bytesrecv"` 248 ConnTime int64 `json:"conntime"` 249 TimeOffset int64 `json:"timeoffset"` 250 PingTime float64 `json:"pingtime"` 251 PingWait float64 `json:"pingwait,omitempty"` 252 Version uint32 `json:"version"` 253 SubVer string `json:"subver"` 254 Inbound bool `json:"inbound"` 255 StartingHeight int32 `json:"startingheight"` 256 CurrentHeight int32 `json:"currentheight,omitempty"` 257 BanScore int32 `json:"banscore"` 258 FeeFilter int64 `json:"feefilter"` 259 SyncNode bool `json:"syncnode"` 260 } 261 262 // GetRawMempoolVerboseResult models the data returned from the getrawmempool 263 // command when the verbose flag is set. When the verbose flag is not set, 264 // getrawmempool returns an array of transaction hashes. 265 type GetRawMempoolVerboseResult struct { 266 Size int32 `json:"size"` 267 Vsize int32 `json:"vsize"` 268 Fee float64 `json:"fee"` 269 Time int64 `json:"time"` 270 Height int64 `json:"height"` 271 StartingPriority float64 `json:"startingpriority"` 272 CurrentPriority float64 `json:"currentpriority"` 273 Depends []string `json:"depends"` 274 } 275 276 // ScriptPubKeyResult models the scriptPubKey data of a tx script. It is 277 // defined separately since it is used by multiple commands. 278 type ScriptPubKeyResult struct { 279 Asm string `json:"asm"` 280 Hex string `json:"hex,omitempty"` 281 ReqSigs int32 `json:"reqSigs,omitempty"` 282 Type string `json:"type"` 283 Addresses []string `json:"addresses,omitempty"` 284 } 285 286 // GetTxOutResult models the data from the gettxout command. 287 type GetTxOutResult struct { 288 BestBlock string `json:"bestblock"` 289 Confirmations int64 `json:"confirmations"` 290 Value float64 `json:"value"` 291 ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"` 292 Version int32 `json:"version"` 293 Coinbase bool `json:"coinbase"` 294 } 295 296 // GetNetTotalsResult models the data returned from the getnettotals command. 297 type GetNetTotalsResult struct { 298 TotalBytesRecv uint64 `json:"totalbytesrecv"` 299 TotalBytesSent uint64 `json:"totalbytessent"` 300 TimeMillis int64 `json:"timemillis"` 301 } 302 303 // ScriptSig models a signature script. It is defined separately since it only 304 // applies to non-coinbase. Therefore the field in the Vin structure needs 305 // to be a pointer. 306 type ScriptSig struct { 307 Asm string `json:"asm"` 308 Hex string `json:"hex"` 309 } 310 311 // Vin models parts of the tx data. It is defined separately since 312 // getrawtransaction, decoderawtransaction, and searchrawtransaction use the 313 // same structure. 314 type Vin struct { 315 Coinbase string `json:"coinbase"` 316 Txid string `json:"txid"` 317 Vout uint32 `json:"vout"` 318 ScriptSig *ScriptSig `json:"scriptSig"` 319 Sequence uint32 `json:"sequence"` 320 Witness []string `json:"txinwitness"` 321 } 322 323 // IsCoinBase returns a bool to show if a Vin is a Coinbase one or not. 324 func (v *Vin) IsCoinBase() bool { 325 return len(v.Coinbase) > 0 326 } 327 328 // HasWitness returns a bool to show if a Vin has any witness data associated 329 // with it or not. 330 func (v *Vin) HasWitness() bool { 331 return len(v.Witness) > 0 332 } 333 334 // MarshalJSON provides a custom Marshal method for Vin. 335 func (v *Vin) MarshalJSON() ([]byte, error) { 336 if v.IsCoinBase() { 337 coinbaseStruct := struct { 338 Coinbase string `json:"coinbase"` 339 Sequence uint32 `json:"sequence"` 340 Witness []string `json:"witness,omitempty"` 341 }{ 342 Coinbase: v.Coinbase, 343 Sequence: v.Sequence, 344 Witness: v.Witness, 345 } 346 return json.Marshal(coinbaseStruct) 347 } 348 349 if v.HasWitness() { 350 txStruct := struct { 351 Txid string `json:"txid"` 352 Vout uint32 `json:"vout"` 353 ScriptSig *ScriptSig `json:"scriptSig"` 354 Witness []string `json:"txinwitness"` 355 Sequence uint32 `json:"sequence"` 356 }{ 357 Txid: v.Txid, 358 Vout: v.Vout, 359 ScriptSig: v.ScriptSig, 360 Witness: v.Witness, 361 Sequence: v.Sequence, 362 } 363 return json.Marshal(txStruct) 364 } 365 366 txStruct := struct { 367 Txid string `json:"txid"` 368 Vout uint32 `json:"vout"` 369 ScriptSig *ScriptSig `json:"scriptSig"` 370 Sequence uint32 `json:"sequence"` 371 }{ 372 Txid: v.Txid, 373 Vout: v.Vout, 374 ScriptSig: v.ScriptSig, 375 Sequence: v.Sequence, 376 } 377 return json.Marshal(txStruct) 378 } 379 380 // PrevOut represents previous output for an input Vin. 381 type PrevOut struct { 382 Addresses []string `json:"addresses,omitempty"` 383 Value float64 `json:"value"` 384 } 385 386 // VinPrevOut is like Vin except it includes PrevOut. It is used by searchrawtransaction 387 type VinPrevOut struct { 388 Coinbase string `json:"coinbase"` 389 Txid string `json:"txid"` 390 Vout uint32 `json:"vout"` 391 ScriptSig *ScriptSig `json:"scriptSig"` 392 Witness []string `json:"txinwitness"` 393 PrevOut *PrevOut `json:"prevOut"` 394 Sequence uint32 `json:"sequence"` 395 } 396 397 // IsCoinBase returns a bool to show if a Vin is a Coinbase one or not. 398 func (v *VinPrevOut) IsCoinBase() bool { 399 return len(v.Coinbase) > 0 400 } 401 402 // HasWitness returns a bool to show if a Vin has any witness data associated 403 // with it or not. 404 func (v *VinPrevOut) HasWitness() bool { 405 return len(v.Witness) > 0 406 } 407 408 // MarshalJSON provides a custom Marshal method for VinPrevOut. 409 func (v *VinPrevOut) MarshalJSON() ([]byte, error) { 410 if v.IsCoinBase() { 411 coinbaseStruct := struct { 412 Coinbase string `json:"coinbase"` 413 Sequence uint32 `json:"sequence"` 414 }{ 415 Coinbase: v.Coinbase, 416 Sequence: v.Sequence, 417 } 418 return json.Marshal(coinbaseStruct) 419 } 420 421 if v.HasWitness() { 422 txStruct := struct { 423 Txid string `json:"txid"` 424 Vout uint32 `json:"vout"` 425 ScriptSig *ScriptSig `json:"scriptSig"` 426 Witness []string `json:"txinwitness"` 427 PrevOut *PrevOut `json:"prevOut,omitempty"` 428 Sequence uint32 `json:"sequence"` 429 }{ 430 Txid: v.Txid, 431 Vout: v.Vout, 432 ScriptSig: v.ScriptSig, 433 Witness: v.Witness, 434 PrevOut: v.PrevOut, 435 Sequence: v.Sequence, 436 } 437 return json.Marshal(txStruct) 438 } 439 440 txStruct := struct { 441 Txid string `json:"txid"` 442 Vout uint32 `json:"vout"` 443 ScriptSig *ScriptSig `json:"scriptSig"` 444 PrevOut *PrevOut `json:"prevOut,omitempty"` 445 Sequence uint32 `json:"sequence"` 446 }{ 447 Txid: v.Txid, 448 Vout: v.Vout, 449 ScriptSig: v.ScriptSig, 450 PrevOut: v.PrevOut, 451 Sequence: v.Sequence, 452 } 453 return json.Marshal(txStruct) 454 } 455 456 // Vout models parts of the tx data. It is defined separately since both 457 // getrawtransaction and decoderawtransaction use the same structure. 458 type Vout struct { 459 Value float64 `json:"value"` 460 N uint32 `json:"n"` 461 ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"` 462 } 463 464 // GetMiningInfoResult models the data from the getmininginfo command. 465 type GetMiningInfoResult struct { 466 Blocks int64 `json:"blocks"` 467 CurrentBlockSize uint64 `json:"currentblocksize"` 468 CurrentBlockWeight uint64 `json:"currentblockweight"` 469 CurrentBlockTx uint64 `json:"currentblocktx"` 470 Difficulty float64 `json:"difficulty"` 471 Errors string `json:"errors"` 472 Generate bool `json:"generate"` 473 GenProcLimit int32 `json:"genproclimit"` 474 HashesPerSec int64 `json:"hashespersec"` 475 NetworkHashPS int64 `json:"networkhashps"` 476 PooledTx uint64 `json:"pooledtx"` 477 TestNet bool `json:"testnet"` 478 } 479 480 // GetWorkResult models the data from the getwork command. 481 type GetWorkResult struct { 482 Data string `json:"data"` 483 Hash1 string `json:"hash1"` 484 Midstate string `json:"midstate"` 485 Target string `json:"target"` 486 } 487 488 // InfoChainResult models the data returned by the chain server getinfo command. 489 type InfoChainResult struct { 490 Version int32 `json:"version"` 491 ProtocolVersion int32 `json:"protocolversion"` 492 Blocks int32 `json:"blocks"` 493 TimeOffset int64 `json:"timeoffset"` 494 Connections int32 `json:"connections"` 495 Proxy string `json:"proxy"` 496 Difficulty float64 `json:"difficulty"` 497 TestNet bool `json:"testnet"` 498 RelayFee float64 `json:"relayfee"` 499 Errors string `json:"errors"` 500 } 501 502 // TxRawResult models the data from the getrawtransaction command. 503 type TxRawResult struct { 504 Hex string `json:"hex"` 505 Txid string `json:"txid"` 506 Hash string `json:"hash,omitempty"` 507 Size int32 `json:"size,omitempty"` 508 Vsize int32 `json:"vsize,omitempty"` 509 Version int32 `json:"version"` 510 LockTime uint32 `json:"locktime"` 511 Vin []Vin `json:"vin"` 512 Vout []Vout `json:"vout"` 513 BlockHash string `json:"blockhash,omitempty"` 514 Confirmations uint64 `json:"confirmations,omitempty"` 515 Time int64 `json:"time,omitempty"` 516 Blocktime int64 `json:"blocktime,omitempty"` 517 } 518 519 // SearchRawTransactionsResult models the data from the searchrawtransaction 520 // command. 521 type SearchRawTransactionsResult struct { 522 Hex string `json:"hex,omitempty"` 523 Txid string `json:"txid"` 524 Hash string `json:"hash"` 525 Size string `json:"size"` 526 Vsize string `json:"vsize"` 527 Version int32 `json:"version"` 528 LockTime uint32 `json:"locktime"` 529 Vin []VinPrevOut `json:"vin"` 530 Vout []Vout `json:"vout"` 531 BlockHash string `json:"blockhash,omitempty"` 532 Confirmations uint64 `json:"confirmations,omitempty"` 533 Time int64 `json:"time,omitempty"` 534 Blocktime int64 `json:"blocktime,omitempty"` 535 } 536 537 // TxRawDecodeResult models the data from the decoderawtransaction command. 538 type TxRawDecodeResult struct { 539 Txid string `json:"txid"` 540 Version int32 `json:"version"` 541 Locktime uint32 `json:"locktime"` 542 Vin []Vin `json:"vin"` 543 Vout []Vout `json:"vout"` 544 } 545 546 // ValidateAddressChainResult models the data returned by the chain server 547 // validateaddress command. 548 type ValidateAddressChainResult struct { 549 IsValid bool `json:"isvalid"` 550 Address string `json:"address,omitempty"` 551 }