github.com/aychain/blockbook@v0.1.1-0.20181121092459-6d1fc7e07c5b/api/types.go (about) 1 package api 2 3 import ( 4 "blockbook/bchain" 5 "blockbook/common" 6 "blockbook/db" 7 "math/big" 8 "time" 9 ) 10 11 // APIError extends error by information if the error details should be returned to the end user 12 type APIError struct { 13 Text string 14 Public bool 15 } 16 17 func (e *APIError) Error() string { 18 return e.Text 19 } 20 21 // NewAPIError creates ApiError 22 func NewAPIError(s string, public bool) error { 23 return &APIError{ 24 Text: s, 25 Public: public, 26 } 27 } 28 29 // ScriptSig contains input script 30 type ScriptSig struct { 31 Hex string `json:"hex"` 32 Asm string `json:"asm,omitempty"` 33 } 34 35 // Vin contains information about single transaction input 36 type Vin struct { 37 Txid string `json:"txid"` 38 Vout uint32 `json:"vout"` 39 Sequence int64 `json:"sequence,omitempty"` 40 N int `json:"n"` 41 ScriptSig ScriptSig `json:"scriptSig"` 42 AddrDesc bchain.AddressDescriptor `json:"-"` 43 Addresses []string `json:"addresses"` 44 Searchable bool `json:"-"` 45 Value string `json:"value"` 46 ValueSat big.Int `json:"-"` 47 } 48 49 // ScriptPubKey contains output script and addresses derived from it 50 type ScriptPubKey struct { 51 Hex string `json:"hex"` 52 Asm string `json:"asm,omitempty"` 53 AddrDesc bchain.AddressDescriptor `json:"-"` 54 Addresses []string `json:"addresses"` 55 Searchable bool `json:"-"` 56 Type string `json:"type,omitempty"` 57 } 58 59 // Vout contains information about single transaction output 60 type Vout struct { 61 Value string `json:"value"` 62 ValueSat big.Int `json:"-"` 63 N int `json:"n"` 64 ScriptPubKey ScriptPubKey `json:"scriptPubKey"` 65 Spent bool `json:"spent"` 66 SpentTxID string `json:"spentTxId,omitempty"` 67 SpentIndex int `json:"spentIndex,omitempty"` 68 SpentHeight int `json:"spentHeight,omitempty"` 69 } 70 71 // Tx holds information about a transaction 72 type Tx struct { 73 Txid string `json:"txid"` 74 Version int32 `json:"version,omitempty"` 75 Locktime uint32 `json:"locktime,omitempty"` 76 Vin []Vin `json:"vin"` 77 Vout []Vout `json:"vout"` 78 Blockhash string `json:"blockhash,omitempty"` 79 Blockheight int `json:"blockheight"` 80 Confirmations uint32 `json:"confirmations"` 81 Time int64 `json:"time,omitempty"` 82 Blocktime int64 `json:"blocktime"` 83 ValueOut string `json:"valueOut"` 84 ValueOutSat big.Int `json:"-"` 85 Size int `json:"size,omitempty"` 86 ValueIn string `json:"valueIn"` 87 ValueInSat big.Int `json:"-"` 88 Fees string `json:"fees"` 89 FeesSat big.Int `json:"-"` 90 Hex string `json:"hex"` 91 } 92 93 // Paging contains information about paging for address, blocks and block 94 type Paging struct { 95 Page int `json:"page"` 96 TotalPages int `json:"totalPages"` 97 ItemsOnPage int `json:"itemsOnPage"` 98 } 99 100 // Address holds information about address and its transactions 101 type Address struct { 102 Paging 103 AddrStr string `json:"addrStr"` 104 Balance string `json:"balance"` 105 TotalReceived string `json:"totalReceived"` 106 TotalSent string `json:"totalSent"` 107 UnconfirmedBalance string `json:"unconfirmedBalance"` 108 UnconfirmedTxApperances int `json:"unconfirmedTxApperances"` 109 TxApperances int `json:"txApperances"` 110 Transactions []*Tx `json:"txs,omitempty"` 111 Txids []string `json:"transactions,omitempty"` 112 } 113 114 // AddressUtxo holds information about address and its transactions 115 type AddressUtxo struct { 116 Txid string `json:"txid"` 117 Vout uint32 `json:"vout"` 118 Amount string `json:"amount"` 119 AmountSat big.Int `json:"satoshis"` 120 Height int `json:"height,omitempty"` 121 Confirmations int `json:"confirmations"` 122 } 123 124 // Blocks is list of blocks with paging information 125 type Blocks struct { 126 Paging 127 Blocks []db.BlockInfo `json:"blocks"` 128 } 129 130 // Block contains information about block 131 type Block struct { 132 Paging 133 bchain.BlockInfo 134 TxCount int `json:"TxCount"` 135 Transactions []*Tx `json:"txs,omitempty"` 136 } 137 138 // BlockbookInfo contains information about the running blockbook instance 139 type BlockbookInfo struct { 140 Coin string `json:"coin"` 141 Host string `json:"host"` 142 Version string `json:"version"` 143 GitCommit string `json:"gitcommit"` 144 BuildTime string `json:"buildtime"` 145 SyncMode bool `json:"syncMode"` 146 InitialSync bool `json:"initialsync"` 147 InSync bool `json:"inSync"` 148 BestHeight uint32 `json:"bestHeight"` 149 LastBlockTime time.Time `json:"lastBlockTime"` 150 InSyncMempool bool `json:"inSyncMempool"` 151 LastMempoolTime time.Time `json:"lastMempoolTime"` 152 MempoolSize int `json:"mempoolSize"` 153 DbSize int64 `json:"dbSize"` 154 DbSizeFromColumns int64 `json:"dbSizeFromColumns,omitempty"` 155 DbColumns []common.InternalStateColumn `json:"dbColumns,omitempty"` 156 About string `json:"about"` 157 } 158 159 // SystemInfo contains information about the running blockbook and backend instance 160 type SystemInfo struct { 161 Blockbook *BlockbookInfo `json:"blockbook"` 162 Backend *bchain.ChainInfo `json:"backend"` 163 }