Skip to content

Commit dd2b134

Browse files
Merge pull request #669 from onflow/janez/flow-block-height
Add debug_flowHeight API endpoint
2 parents 0974579 + 0fff9b1 commit dd2b134

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ The EVM Gateway implements APIs according to the Ethereum specification: https:/
267267
* debug_traceBlockByNumber
268268
* debug_traceBlockByHash
269269

270+
- debug_flowHeightByBlock - returns the flow block height for the given EVM block (id or height)
271+
270272
**Unsupported APIs**
271273
- Wallet APIs: we don't officially support wallet APIs (eth_accounts, eth_sign, eth_signTransaction, eth_sendTransaction) due to security
272274
concerns that come with managing the keys on production environments, however, it is possible to configure the gateway to allow these

api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ var validMethods = map[string]struct{}{
7676
"debug_traceBlockByNumber": {},
7777
"debug_traceBlockByHash": {},
7878
"debug_traceCall": {},
79+
"debug_flowHeightByBlock": {},
7980

8081
// web3 namespace
8182
"web3_clientVersion": {},

api/debug.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,25 @@ func (d *DebugAPI) TraceCall(
361361
return tracer.GetResult()
362362
}
363363

364+
// FlowHeightByBlock returns the Flow height for the given EVM block specified either by EVM
365+
// block height or EVM block hash.
366+
func (d *DebugAPI) FlowHeightByBlock(
367+
_ context.Context,
368+
blockNrOrHash rpc.BlockNumberOrHash,
369+
) (uint64, error) {
370+
height, err := resolveBlockTag(&blockNrOrHash, d.blocks, d.logger)
371+
if err != nil {
372+
return 0, err
373+
}
374+
375+
cdcHeight, err := d.blocks.GetCadenceHeight(height)
376+
if err != nil {
377+
return 0, err
378+
}
379+
380+
return cdcHeight, nil
381+
}
382+
364383
func (d *DebugAPI) executorAtBlock(block *models.Block) (*evm.BlockExecutor, error) {
365384
snapshot, err := d.registerStore.GetSnapshotAt(block.Height)
366385
if err != nil {

tests/e2e_web3js_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func TestWeb3_E2E(t *testing.T) {
3636
runWeb3Test(t, "debug_traces_test")
3737
})
3838

39+
t.Run("test debug utils", func(t *testing.T) {
40+
runWeb3Test(t, "debug_util_test")
41+
})
42+
3943
t.Run("test setup sanity check", func(t *testing.T) {
4044
runWeb3Test(t, "setup_test")
4145
})

tests/web3js/debug_util_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { assert } = require('chai')
2+
const helpers = require('./helpers')
3+
const conf = require('./config')
4+
5+
it('should retrieve flow height', async () => {
6+
let response = await helpers.callRPCMethod(
7+
'debug_flowHeightByBlock',
8+
['latest']
9+
)
10+
assert.equal(response.status, 200)
11+
assert.isDefined(response.body)
12+
13+
let height = response.body.result
14+
assert.equal(height, conf.startBlockHeight)
15+
})

0 commit comments

Comments
 (0)