|
8 | 8 | "github.com/NethermindEth/juno/blockchain"
|
9 | 9 | "github.com/NethermindEth/juno/core"
|
10 | 10 | "github.com/NethermindEth/juno/core/felt"
|
| 11 | + "github.com/NethermindEth/juno/db" |
11 | 12 | "github.com/NethermindEth/juno/jsonrpc"
|
12 | 13 | "github.com/NethermindEth/juno/sync"
|
13 | 14 | "github.com/NethermindEth/juno/utils"
|
@@ -110,17 +111,41 @@ func (h *Handler) BlockWithTxHashes(id BlockID) (*BlockWithTxHashes, *jsonrpc.Er
|
110 | 111 | txnHashes[index] = txn.Hash()
|
111 | 112 | }
|
112 | 113 |
|
| 114 | + l1H, jsonErr := h.l1Head() |
| 115 | + if jsonErr != nil { |
| 116 | + return nil, jsonErr |
| 117 | + } |
| 118 | + |
113 | 119 | status := StatusAcceptedL2
|
114 | 120 | if id.Pending {
|
115 | 121 | status = StatusPending
|
| 122 | + } else if isL1Verified(block.Number, l1H) { |
| 123 | + status = StatusAcceptedL1 |
116 | 124 | }
|
| 125 | + |
117 | 126 | return &BlockWithTxHashes{
|
118 | 127 | Status: status,
|
119 | 128 | BlockHeader: adaptBlockHeader(block.Header),
|
120 | 129 | TxnHashes: txnHashes,
|
121 | 130 | }, nil
|
122 | 131 | }
|
123 | 132 |
|
| 133 | +func (h *Handler) l1Head() (*core.L1Head, *jsonrpc.Error) { |
| 134 | + l1Head, err := h.bcReader.L1Head() |
| 135 | + if err != nil && !errors.Is(err, db.ErrKeyNotFound) { |
| 136 | + return nil, jsonrpc.Err(jsonrpc.InternalError, err.Error()) |
| 137 | + } |
| 138 | + // nil is returned if l1 head doesn't exist |
| 139 | + return l1Head, nil |
| 140 | +} |
| 141 | + |
| 142 | +func isL1Verified(n uint64, l1 *core.L1Head) bool { |
| 143 | + if l1 != nil && l1.BlockNumber >= n { |
| 144 | + return true |
| 145 | + } |
| 146 | + return false |
| 147 | +} |
| 148 | + |
124 | 149 | func adaptBlockHeader(header *core.Header) BlockHeader {
|
125 | 150 | var blockNumber *uint64
|
126 | 151 | // if header.Hash == nil it's a pending block
|
@@ -153,10 +178,18 @@ func (h *Handler) BlockWithTxs(id BlockID) (*BlockWithTxs, *jsonrpc.Error) {
|
153 | 178 | txs[index] = adaptTransaction(txn)
|
154 | 179 | }
|
155 | 180 |
|
| 181 | + l1H, jsonErr := h.l1Head() |
| 182 | + if jsonErr != nil { |
| 183 | + return nil, jsonErr |
| 184 | + } |
| 185 | + |
156 | 186 | status := StatusAcceptedL2
|
157 | 187 | if id.Pending {
|
158 | 188 | status = StatusPending
|
| 189 | + } else if isL1Verified(block.Number, l1H) { |
| 190 | + status = StatusAcceptedL1 |
159 | 191 | }
|
| 192 | + |
160 | 193 | return &BlockWithTxs{
|
161 | 194 | Status: status,
|
162 | 195 | BlockHeader: adaptBlockHeader(block.Header),
|
@@ -383,11 +416,26 @@ func (h *Handler) TransactionReceiptByHash(hash felt.Felt) (*TransactionReceipt,
|
383 | 416 | }
|
384 | 417 |
|
385 | 418 | var receiptBlockNumber *uint64
|
| 419 | + status := StatusAcceptedL2 |
| 420 | + |
386 | 421 | if blockHash != nil {
|
387 | 422 | receiptBlockNumber = &blockNumber
|
| 423 | + |
| 424 | + l1H, jsonErr := h.l1Head() |
| 425 | + if jsonErr != nil { |
| 426 | + return nil, jsonErr |
| 427 | + } |
| 428 | + |
| 429 | + if isL1Verified(blockNumber, l1H) { |
| 430 | + status = StatusAcceptedL1 |
| 431 | + } |
| 432 | + } else { |
| 433 | + // Todo: Remove after starknet v0.12.0 is released. As Pending status will be removed from Transactions and only exist for blocks |
| 434 | + status = StatusPending |
388 | 435 | }
|
| 436 | + |
389 | 437 | return &TransactionReceipt{
|
390 |
| - Status: StatusAcceptedL2, // todo |
| 438 | + Status: status, |
391 | 439 | Type: txn.Type,
|
392 | 440 | Hash: txn.Hash,
|
393 | 441 | ActualFee: receipt.Fee,
|
|
0 commit comments