formatting.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /**
  2. * About provider formatting?
  3. *
  4. * @_section: api/providers/formatting:Formatting [provider-formatting]
  5. */
  6. import type { Signature } from "../crypto/index.js";
  7. import type { AccessList } from "../transaction/index.js";
  8. //////////////////////
  9. // Block
  10. /**
  11. * a **BlockParams** encodes the minimal required properties for a
  12. * formatted block.
  13. */
  14. export interface BlockParams {
  15. /**
  16. * The block hash.
  17. */
  18. hash?: null | string;
  19. /**
  20. * The block number.
  21. */
  22. number: number;
  23. /**
  24. * The timestamp for this block, which is the number of seconds
  25. * since epoch that this block was included.
  26. */
  27. timestamp: number;
  28. /**
  29. * The hash of the previous block in the blockchain. The genesis block
  30. * has the parentHash of the [[ZeroHash]].
  31. */
  32. parentHash: string;
  33. /**
  34. * The hash tree root of the parent beacon block for the given
  35. * execution block. See [[link-eip-4788]].
  36. */
  37. parentBeaconBlockRoot?: null | string;
  38. /**
  39. * A random sequence provided during the mining process for
  40. * proof-of-work networks.
  41. */
  42. nonce: string;
  43. /**
  44. * For proof-of-work networks, the difficulty target is used to
  45. * adjust the difficulty in mining to ensure a expected block rate.
  46. */
  47. difficulty: bigint;
  48. /**
  49. * The maximum amount of gas a block can consume.
  50. */
  51. gasLimit: bigint;
  52. /**
  53. * The amount of gas a block consumed.
  54. */
  55. gasUsed: bigint;
  56. /**
  57. * The total amount of BLOb gas consumed by transactions within
  58. * the block. See [[link-eip4844].
  59. */
  60. blobGasUsed?: null | bigint;
  61. /**
  62. * The running total of BLOb gas consumed in excess of the target
  63. * prior to the block. See [[link-eip-4844]].
  64. */
  65. excessBlobGas?: null | bigint;
  66. /**
  67. * The miner (or author) of a block.
  68. */
  69. miner: string;
  70. /**
  71. * The latest RANDAO mix of the post beacon state of
  72. * the previous block.
  73. */
  74. prevRandao?: null | string;
  75. /**
  76. * Additional data the miner choose to include.
  77. */
  78. extraData: string;
  79. /**
  80. * The protocol-defined base fee per gas in an [[link-eip-1559]]
  81. * block.
  82. */
  83. baseFeePerGas: null | bigint;
  84. /**
  85. * The root hash for the global state after applying changes
  86. * in this block.
  87. */
  88. stateRoot?: null | string;
  89. /**
  90. * The hash of the transaction receipts trie.
  91. */
  92. receiptsRoot?: null | string;
  93. /**
  94. * The list of transactions in the block.
  95. */
  96. transactions: ReadonlyArray<string | TransactionResponseParams>;
  97. };
  98. //////////////////////
  99. // Log
  100. /**
  101. * a **LogParams** encodes the minimal required properties for a
  102. * formatted log.
  103. */
  104. export interface LogParams {
  105. /**
  106. * The transaction hash for the transaxction the log occurred in.
  107. */
  108. transactionHash: string;
  109. /**
  110. * The block hash of the block that included the transaction for this
  111. * log.
  112. */
  113. blockHash: string;
  114. /**
  115. * The block number of the block that included the transaction for this
  116. * log.
  117. */
  118. blockNumber: number;
  119. /**
  120. * Whether this log was removed due to the transaction it was included
  121. * in being removed dur to an orphaned block.
  122. */
  123. removed: boolean;
  124. /**
  125. * The address of the contract that emitted this log.
  126. */
  127. address: string;
  128. /**
  129. * The data emitted with this log.
  130. */
  131. data: string;
  132. /**
  133. * The topics emitted with this log.
  134. */
  135. topics: ReadonlyArray<string>;
  136. /**
  137. * The index of this log.
  138. */
  139. index: number;
  140. /**
  141. * The transaction index of this log.
  142. */
  143. transactionIndex: number;
  144. }
  145. //////////////////////
  146. // Transaction Receipt
  147. /**
  148. * a **TransactionReceiptParams** encodes the minimal required properties
  149. * for a formatted transaction receipt.
  150. */
  151. export interface TransactionReceiptParams {
  152. /**
  153. * The target of the transaction. If null, the transaction was trying
  154. * to deploy a transaction with the ``data`` as the initi=code.
  155. */
  156. to: null | string;
  157. /**
  158. * The sender of the transaction.
  159. */
  160. from: string;
  161. /**
  162. * If the transaction was directly deploying a contract, the [[to]]
  163. * will be null, the ``data`` will be initcode and if successful, this
  164. * will be the address of the contract deployed.
  165. */
  166. contractAddress: null | string;
  167. /**
  168. * The transaction hash.
  169. */
  170. hash: string;
  171. /**
  172. * The transaction index.
  173. */
  174. index: number;
  175. /**
  176. * The block hash of the block that included this transaction.
  177. */
  178. blockHash: string;
  179. /**
  180. * The block number of the block that included this transaction.
  181. */
  182. blockNumber: number;
  183. /**
  184. * The bloom filter for the logs emitted during execution of this
  185. * transaction.
  186. */
  187. logsBloom: string;
  188. /**
  189. * The logs emitted during the execution of this transaction.
  190. */
  191. logs: ReadonlyArray<LogParams>;
  192. /**
  193. * The amount of gas consumed executing this transaciton.
  194. */
  195. gasUsed: bigint;
  196. /**
  197. * The amount of BLOb gas used. See [[link-eip-4844]].
  198. */
  199. blobGasUsed?: null | bigint;
  200. /**
  201. * The total amount of gas consumed during the entire block up to
  202. * and including this transaction.
  203. */
  204. cumulativeGasUsed: bigint;
  205. /**
  206. * The actual gas price per gas charged for this transaction.
  207. */
  208. gasPrice?: null | bigint;
  209. /**
  210. * The actual BLOb gas price that was charged. See [[link-eip-4844]].
  211. */
  212. blobGasPrice?: null | bigint;
  213. /**
  214. * The actual gas price per gas charged for this transaction.
  215. */
  216. effectiveGasPrice?: null | bigint;
  217. /**
  218. * The [[link-eip-2718]] envelope type.
  219. */
  220. type: number;
  221. //byzantium: boolean;
  222. /**
  223. * The status of the transaction execution. If ``1`` then the
  224. * the transaction returned success, if ``0`` then the transaction
  225. * was reverted. For pre-byzantium blocks, this is usually null, but
  226. * some nodes may have backfilled this data.
  227. */
  228. status: null | number;
  229. /**
  230. * The root of this transaction in a pre-bazatium block. In
  231. * post-byzantium blocks this is null.
  232. */
  233. root: null | string;
  234. }
  235. /*
  236. export interface LegacyTransactionReceipt {
  237. byzantium: false;
  238. status: null;
  239. root: string;
  240. }
  241. export interface ByzantiumTransactionReceipt {
  242. byzantium: true;
  243. status: number;
  244. root: null;
  245. }
  246. */
  247. //////////////////////
  248. // Transaction Response
  249. /**
  250. * a **TransactionResponseParams** encodes the minimal required properties
  251. * for a formatted transaction response.
  252. */
  253. export interface TransactionResponseParams {
  254. /**
  255. * The block number of the block that included this transaction.
  256. */
  257. blockNumber: null | number;
  258. /**
  259. * The block hash of the block that included this transaction.
  260. */
  261. blockHash: null | string;
  262. /**
  263. * The transaction hash.
  264. */
  265. hash: string;
  266. /**
  267. * The transaction index.
  268. */
  269. index: number;
  270. /**
  271. * The [[link-eip-2718]] transaction type.
  272. */
  273. type: number;
  274. /**
  275. * The target of the transaction. If ``null``, the ``data`` is initcode
  276. * and this transaction is a deployment transaction.
  277. */
  278. to: null | string;
  279. /**
  280. * The sender of the transaction.
  281. */
  282. from: string;
  283. /**
  284. * The nonce of the transaction, used for replay protection.
  285. */
  286. nonce: number;
  287. /**
  288. * The maximum amount of gas this transaction is authorized to consume.
  289. */
  290. gasLimit: bigint;
  291. /**
  292. * For legacy transactions, this is the gas price per gas to pay.
  293. */
  294. gasPrice: bigint;
  295. /**
  296. * For [[link-eip-1559]] transactions, this is the maximum priority
  297. * fee to allow a producer to claim.
  298. */
  299. maxPriorityFeePerGas: null | bigint;
  300. /**
  301. * For [[link-eip-1559]] transactions, this is the maximum fee that
  302. * will be paid.
  303. */
  304. maxFeePerGas: null | bigint;
  305. /**
  306. * For [[link-eip-4844]] transactions, this is the maximum fee that
  307. * will be paid per BLOb.
  308. */
  309. maxFeePerBlobGas?: null | bigint;
  310. /**
  311. * The transaction data.
  312. */
  313. data: string;
  314. /**
  315. * The transaction value (in wei).
  316. */
  317. value: bigint;
  318. /**
  319. * The chain ID this transaction is valid on.
  320. */
  321. chainId: bigint;
  322. /**
  323. * The signature of the transaction.
  324. */
  325. signature: Signature;
  326. /**
  327. * The transaction access list.
  328. */
  329. accessList: null | AccessList;
  330. /**
  331. * The [[link-eip-4844]] BLOb versioned hashes.
  332. */
  333. blobVersionedHashes?: null | Array<string>;
  334. };