mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-25 18:35:32 +00:00
implement graphql.Query.account
although this is not part of EIP 1767 but the hive test cases derived from besu test cases contains this. we add this now to pass more test hive.graphql cases
This commit is contained in:
parent
9e055bd15f
commit
b8c55229e7
@ -590,6 +590,9 @@ proc txCreatedContract(ud: RootRef, params: Args, parent: Node): RespResult {.ap
|
|||||||
let tx = TxNode(parent)
|
let tx = TxNode(parent)
|
||||||
var sender: EthAddress
|
var sender: EthAddress
|
||||||
if not getSender(tx.tx, sender):
|
if not getSender(tx.tx, sender):
|
||||||
|
return err("can't calculate sender")
|
||||||
|
|
||||||
|
if not tx.tx.isContractCreation:
|
||||||
return ok(respNull())
|
return ok(respNull())
|
||||||
|
|
||||||
let hres = getBlockByNumber(ctx, tx.blockNumber)
|
let hres = getBlockByNumber(ctx, tx.blockNumber)
|
||||||
@ -929,6 +932,22 @@ const pendingProcs = {
|
|||||||
"estimateGas": pendingEstimateGas
|
"estimateGas": pendingEstimateGas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc pickBlockNumber(ctx: GraphqlContextRef, number: Node): BlockNumber =
|
||||||
|
if number.kind == nkEmpty:
|
||||||
|
ctx.chainDB.highestBlock
|
||||||
|
else:
|
||||||
|
parseU64(number).toBlockNumber
|
||||||
|
|
||||||
|
proc queryAccount(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
||||||
|
let ctx = GraphqlContextRef(ud)
|
||||||
|
let address = hexToByteArray[20](params[0].val.stringVal)
|
||||||
|
let blockNumber = pickBlockNumber(ctx, params[1].val)
|
||||||
|
let hres = getBlockByNumber(ctx, blockNumber)
|
||||||
|
if hres.isErr:
|
||||||
|
return hres
|
||||||
|
let h = HeaderNode(hres.get())
|
||||||
|
accountNode(ctx, h.header, address)
|
||||||
|
|
||||||
proc queryBlock(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
proc queryBlock(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
||||||
let ctx = GraphqlContextRef(ud)
|
let ctx = GraphqlContextRef(ud)
|
||||||
let number = params[0].val
|
let number = params[0].val
|
||||||
@ -947,10 +966,7 @@ proc queryBlocks(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragm
|
|||||||
let fromNumber = parseU64(params[0].val).toBlockNumber
|
let fromNumber = parseU64(params[0].val).toBlockNumber
|
||||||
|
|
||||||
let to = params[1].val
|
let to = params[1].val
|
||||||
let toNumber = if to.kind == nkEmpty:
|
let toNumber = pickBlockNumber(ctx, to)
|
||||||
ctx.chainDB.highestBlock
|
|
||||||
else:
|
|
||||||
parseU64(to).toBlockNumber
|
|
||||||
|
|
||||||
if fromNumber > toNumber:
|
if fromNumber > toNumber:
|
||||||
return err("from($1) is bigger than to($2)" % [fromNumber.toString, toNumber.toString])
|
return err("from($1) is bigger than to($2)" % [fromNumber.toString, toNumber.toString])
|
||||||
@ -1005,6 +1021,7 @@ proc querySyncing(ud: RootRef, params: Args, parent: Node): RespResult {.apiPrag
|
|||||||
ok(respMap(ctx.ids[ethSyncState]))
|
ok(respMap(ctx.ids[ethSyncState]))
|
||||||
|
|
||||||
const queryProcs = {
|
const queryProcs = {
|
||||||
|
"account": queryAccount,
|
||||||
"block": queryBlock,
|
"block": queryBlock,
|
||||||
"blocks": queryBlocks,
|
"blocks": queryBlocks,
|
||||||
"pending": queryPending,
|
"pending": queryPending,
|
||||||
|
@ -345,6 +345,10 @@ type Pending {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
|
# Account fetches an Ethereum account at the specified block number.
|
||||||
|
# If blockNumber is not provided, it defaults to the most recent block.
|
||||||
|
account(address: Address!, blockNumber: Long): Account!
|
||||||
|
|
||||||
# Block fetches an Ethereum block by number or by hash. If neither is
|
# Block fetches an Ethereum block by number or by hash. If neither is
|
||||||
# supplied, the most recent known block is returned.
|
# supplied, the most recent known block is returned.
|
||||||
block(number: Long, hash: Bytes32): Block
|
block(number: Long, hash: Bytes32): Block
|
||||||
|
Loading…
x
Reference in New Issue
Block a user