|
21 | 21 | ".."/[transaction, evm/state, config, constants], |
22 | 22 | ../transaction/call_evm, |
23 | 23 | ../core/[tx_pool, tx_pool/tx_item], |
| 24 | + ../core/chain/forked_chain, |
24 | 25 | ../common/common, |
25 | 26 | web3/eth_api_types |
26 | 27 |
|
|
75 | 76 | chainDB: CoreDbRef |
76 | 77 | ethNode: EthereumNode |
77 | 78 | txPool: TxPoolRef |
| 79 | + chain: ForkedChainRef |
78 | 80 |
|
79 | 81 | {.push gcsafe, raises: [].} |
80 | 82 | {.pragma: apiRaises, raises: [].} |
@@ -154,28 +156,28 @@ proc getStateDB(com: CommonRef, header: Header): LedgerRef {.deprecated: "Ledge |
154 | 156 |
|
155 | 157 | proc getBlockByNumber(ctx: GraphqlContextRef, number: Node): RespResult = |
156 | 158 | try: |
157 | | - let header = ?ctx.chainDB.getBlockHeader(toBlockNumber(number)) |
| 159 | + let header = ?ctx.chain.headerByNumber(toBlockNumber(number)) |
158 | 160 | ok(headerNode(ctx, header)) |
159 | 161 | except ValueError as exc: |
160 | 162 | err(exc.msg) |
161 | 163 |
|
162 | 164 | proc getBlockByNumber(ctx: GraphqlContextRef, number: base.BlockNumber): RespResult = |
163 | | - let header = ?ctx.chainDB.getBlockHeader(number) |
| 165 | + let header = ?ctx.chain.headerByNumber(number) |
164 | 166 | ok(headerNode(ctx, header)) |
165 | 167 |
|
166 | 168 | proc getBlockByHash(ctx: GraphqlContextRef, hash: Node): RespResult = |
167 | 169 | try: |
168 | | - let header = ?ctx.chainDB.getBlockHeader(toHash(hash)) |
| 170 | + let header = ?ctx.chain.headerByHash(toHash(hash)) |
169 | 171 | ok(headerNode(ctx, header)) |
170 | 172 | except ValueError as exc: |
171 | 173 | err(exc.msg) |
172 | 174 |
|
173 | 175 | proc getBlockByHash(ctx: GraphqlContextRef, hash: Hash32): RespResult = |
174 | | - let header = ?ctx.chainDB.getBlockHeader(hash) |
| 176 | + let header = ?ctx.chain.headerByHash(hash) |
175 | 177 | ok(headerNode(ctx, header)) |
176 | 178 |
|
177 | 179 | proc getLatestBlock(ctx: GraphqlContextRef): RespResult = |
178 | | - let header = ?ctx.chainDB.getCanonicalHead() |
| 180 | + let header = ctx.chain.latestHeader |
179 | 181 | ok(headerNode(ctx, header)) |
180 | 182 |
|
181 | 183 | proc getTxCount(ctx: GraphqlContextRef, txRoot: Hash32): RespResult = |
@@ -1295,7 +1297,7 @@ proc queryLogs(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma. |
1295 | 1297 | proc queryGasPrice(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} = |
1296 | 1298 | let ctx = GraphqlContextRef(ud) |
1297 | 1299 | try: |
1298 | | - bigIntNode(calculateMedianGasPrice(ctx.chainDB)) |
| 1300 | + bigIntNode(calculateMedianGasPrice(ctx.chain)) |
1299 | 1301 | except CatchableError as em: |
1300 | 1302 | err("can't get gasPrice: " & em.msg) |
1301 | 1303 |
|
@@ -1420,23 +1422,24 @@ proc initEthApi(ctx: GraphqlContextRef) = |
1420 | 1422 | echo res.error |
1421 | 1423 | quit(QuitFailure) |
1422 | 1424 |
|
1423 | | -proc setupGraphqlContext*(com: CommonRef, |
| 1425 | +proc setupGraphqlContext*(chain: ForkedChainRef, |
1424 | 1426 | ethNode: EthereumNode, |
1425 | 1427 | txPool: TxPoolRef): GraphqlContextRef = |
1426 | 1428 | let ctx = GraphqlContextRef( |
1427 | | - chainDB: com.db, |
1428 | | - com : com, |
| 1429 | + chainDB: chain.com.db, |
| 1430 | + com : chain.com, |
1429 | 1431 | ethNode: ethNode, |
1430 | | - txPool : txPool |
| 1432 | + txPool : txPool, |
| 1433 | + chain : chain, |
1431 | 1434 | ) |
1432 | 1435 | graphql.init(ctx) |
1433 | 1436 | ctx.initEthApi() |
1434 | 1437 | ctx |
1435 | 1438 |
|
1436 | | -proc setupGraphqlHttpHandler*(com: CommonRef, |
| 1439 | +proc setupGraphqlHttpHandler*(chain: ForkedChainRef, |
1437 | 1440 | ethNode: EthereumNode, |
1438 | 1441 | txPool: TxPoolRef): GraphqlHttpHandlerRef = |
1439 | | - let ctx = setupGraphqlContext(com, ethNode, txPool) |
| 1442 | + let ctx = setupGraphqlContext(chain, ethNode, txPool) |
1440 | 1443 | GraphqlHttpHandlerRef.new(ctx) |
1441 | 1444 |
|
1442 | 1445 | {.pop.} |
0 commit comments