github.com/decred/politeia@v1.4.0/politeiad/plugins/dcrdata/dcrdata.go (about) 1 // Copyright (c) 2020-2021 The Decred 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 dcrdata provides a plugin for querying the dcrdata block explorer. 6 package dcrdata 7 8 const ( 9 // PluginID is the unique identifier for this plugin. 10 PluginID = "dcrdata" 11 12 // Plugin commands 13 CmdBestBlock = "bestblock" // Get best block 14 CmdBlockDetails = "blockdetails" // Get details of a block 15 CmdTicketPool = "ticketpool" // Get ticket pool 16 CmdTxsTrimmed = "txstrimmed" // Get trimmed transactions 17 ) 18 19 // Plugin setting keys can be used to specify custom plugin settings. Default 20 // plugin setting values can be overridden by providing a plugin setting key 21 // and value to the plugin on startup. 22 const ( 23 // SettingKeyHostHTTP is the plugin setting key for the plugin 24 // setting SettingHostHTTP. 25 SettingKeyHostHTTP = "hosthttp" 26 27 // SettingKeyHostWS is the plugin setting key for the plugin 28 // setting SettingHostWS. 29 SettingKeyHostWS = "hostws" 30 ) 31 32 // Plugin setting default values. These can be overridden by providing a plugin 33 // setting key and value to the plugin on startup. 34 const ( 35 // SettingHostHTTPMainNet is the default dcrdata mainnet http host. 36 SettingHostHTTPMainNet = "https://dcrdata.decred.org" 37 38 // SettingHostHTTPTestNet is the default dcrdata testnet http host. 39 SettingHostHTTPTestNet = "https://testnet.decred.org" 40 41 // SettingHostWSMainNet is the default dcrdata mainnet websocket 42 // host. 43 SettingHostWSMainNet = "wss://dcrdata.decred.org/ps" 44 45 // SettingHostWSTestNet is the default dcrdata testnet websocket 46 // host. 47 SettingHostWSTestNet = "wss://testnet.decred.org/ps" 48 ) 49 50 // StatusT represents a dcrdata connection status. Some commands will returned 51 // cached results and the connection status to let the caller know that the 52 // cached data may be stale. It is the callers responsibility to determine the 53 // correct course of action when dcrdata cannot be reached. 54 type StatusT uint32 55 56 const ( 57 // StatusInvalid is an invalid connection status. 58 StatusInvalid StatusT = 0 59 60 // StatusConnected is returned when the dcrdata connection is ok. 61 StatusConnected StatusT = 1 62 63 // StatusDisconnected is returned when dcrdata cannot be reached. 64 StatusDisconnected StatusT = 2 65 ) 66 67 // BestBlock requests best block data. If dcrdata cannot be reached then the 68 // data from the most recent cached best block will be returned along with a 69 // status of StatusDisconnected. It is the callers responsibility to determine 70 // if the stale best block height should be used. 71 type BestBlock struct{} 72 73 // BestBlockReply is the reply to the BestBlock command. 74 type BestBlockReply struct { 75 Status StatusT `json:"status"` 76 Height uint32 `json:"height"` 77 } 78 79 // TicketPoolInfo models data about ticket pool. 80 type TicketPoolInfo struct { 81 Height uint32 `json:"height"` 82 Size uint32 `json:"size"` 83 Value float64 `json:"value"` 84 ValAvg float64 `json:"valavg"` 85 Winners []string `json:"winners"` 86 } 87 88 // BlockDataBasic models primary information about a block. 89 type BlockDataBasic struct { 90 Height uint32 `json:"height"` 91 Size uint32 `json:"size"` 92 Hash string `json:"hash"` 93 Difficulty float64 `json:"diff"` 94 StakeDiff float64 `json:"sdiff"` 95 Time int64 `json:"time"` // UNIX timestamp 96 NumTx uint32 `json:"txlength"` 97 MiningFee *int64 `json:"fees,omitempty"` 98 TotalSent *int64 `json:"totalsent,omitempty"` 99 // TicketPoolInfo may be nil for side chain blocks. 100 PoolInfo *TicketPoolInfo `json:"ticketpool,omitempty"` 101 } 102 103 // BlockDetails retrieves the block details for the provided block height. 104 type BlockDetails struct { 105 Height uint32 `json:"height"` 106 } 107 108 // BlockDetailsReply is the reply to the block details command. 109 type BlockDetailsReply struct { 110 Block BlockDataBasic `json:"block"` 111 } 112 113 // TicketPool requests the lists of tickets in the ticket pool at a specified 114 // block hash. 115 type TicketPool struct { 116 BlockHash string `json:"blockhash"` 117 } 118 119 // TicketPoolReply is the reply to the TicketPool command. 120 type TicketPoolReply struct { 121 Tickets []string `json:"tickets"` // Ticket hashes 122 } 123 124 // ScriptSig models a signature script. It is defined separately since it only 125 // applies to non-coinbase. Therefore the field in the Vin structure needs to 126 // be a pointer. 127 type ScriptSig struct { 128 Asm string `json:"asm"` 129 Hex string `json:"hex"` 130 } 131 132 // Vin models parts of the tx data. It is defined separately since 133 // getrawtransaction, decoderawtransaction, and searchrawtransaction use the 134 // same structure. 135 type Vin struct { 136 Coinbase string `json:"coinbase"` 137 Stakebase string `json:"stakebase"` 138 Txid string `json:"txid"` 139 Vout uint32 `json:"vout"` 140 Tree int8 `json:"tree"` 141 Sequence uint32 `json:"sequence"` 142 AmountIn float64 `json:"amountin"` 143 BlockHeight uint32 `json:"blockheight"` 144 BlockIndex uint32 `json:"blockindex"` 145 ScriptSig *ScriptSig `json:"scriptsig"` 146 } 147 148 // ScriptPubKey is the script public key data. 149 type ScriptPubKey struct { 150 Asm string `json:"asm"` 151 Hex string `json:"hex"` 152 ReqSigs int32 `json:"reqSigs,omitempty"` 153 Type string `json:"type"` 154 Addresses []string `json:"addresses,omitempty"` 155 CommitAmt *float64 `json:"commitamt,omitempty"` 156 } 157 158 // TxInputID specifies a transaction input as hash:vin_index. 159 type TxInputID struct { 160 Hash string `json:"hash"` 161 Index uint32 `json:"index"` 162 } 163 164 // Vout defines a transaction output. 165 type Vout struct { 166 Value float64 `json:"value"` 167 N uint32 `json:"n"` 168 Version uint16 `json:"version"` 169 ScriptPubKeyDecoded ScriptPubKey `json:"scriptpubkeydecoded"` 170 Spend *TxInputID `json:"spend,omitempty"` 171 } 172 173 // TrimmedTx models data to resemble to result of the decoderawtransaction RPC. 174 type TrimmedTx struct { 175 TxID string `json:"txid"` 176 Version int32 `json:"version"` 177 Locktime uint32 `json:"locktime"` 178 Expiry uint32 `json:"expiry"` 179 Vin []Vin `json:"vin"` 180 Vout []Vout `json:"vout"` 181 } 182 183 // TxsTrimmed requests the trimmed transaction information for the provided 184 // transaction IDs. 185 type TxsTrimmed struct { 186 TxIDs []string `json:"txids"` 187 } 188 189 // TxsTrimmedReply is the reply to the TxsTrimmed command. 190 type TxsTrimmedReply struct { 191 Txs []TrimmedTx `json:"txs"` 192 }