fixes some of graphql resolver

following recent fixes in upstream hive,
we also update our graphql resolvers
This commit is contained in:
jangko 2021-06-17 16:11:24 +07:00
parent eb7c0be3d4
commit d0782cdb0d
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
8 changed files with 110 additions and 58 deletions

View File

@ -2,8 +2,10 @@
"request": "{block (number: 25) {account(address: \"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef\") { balance } }}",
"responses": [{
"data": {
"account": {
"balance": "0x"
"block": {
"account": {
"balance": "0x0"
}
}
}
}],

View File

@ -2,8 +2,10 @@
"request": "{block{account(address: \"0xdeaff00ddeaff00ddeaff00ddeaff00ddeaff00d\") { balance } }}",
"responses": [{
"data": {
"account": {
"balance": "0x"
"block": {
"account": {
"balance": "0x0"
}
}
}
}],

View File

@ -1,13 +1,15 @@
{
"request" :"{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x00000000000000000000000000000021\") } }",
"responses":[{
"data" : {
"account" : {
"storage" : "0x0000000000000000000000000000000000000000000000000000000000000000"
"request": "{block{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x0000000000000000000000000000000000000000000000000000000000000021\") } }}",
"responses": [
{
"data": {
"block": {
"account": {
"storage": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
}
}
}
}],
],
"statusCode": 200
}

View File

@ -1,13 +1,15 @@
{
"request" :"{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x00000000000000000000000000000004\") } }",
"responses": [{
"data" : {
"account" :{
"storage" :"0xaabbccffffffffffffffffffffffffffffffffffffffffffffffffffffffffee"
"request": "{block{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x0000000000000000000000000000000000000000000000000000000000000004\") } }}",
"responses": [
{
"data": {
"block": {
"account": {
"storage": "0xaabbccffffffffffffffffffffffffffffffffffffffffffffffffffffffffee"
}
}
}
}
}],
],
"statusCode": 200
}

View File

@ -1,13 +1,24 @@
{
"request" :"{ account(address: \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\") { transactionCount } }",
"responses": [{
"data" : {
"account" :{
"transactionCount" : 32
"request": "{block{ account(address: \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\") { transactionCount } }}",
"responses": [
{
"data": {
"block": {
"account": {
"transactionCount": 32
}
}
}
},
{
"data": {
"block": {
"account": {
"transactionCount": "0x20"
}
}
}
}
}],
],
"statusCode": 200
}

View File

@ -1,27 +1,52 @@
{
"request": "{ transaction(hash: \"0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed\") {block{hash logsBloom} hash createdContract{address} cumulativeGasUsed gas gasUsed logs{topics} from{address} to{address} index } }",
"responses": [{
"data": {
"transaction": {
"block": {
"hash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
"createdContract": {
"address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"
},
"cumulativeGasUsed": 493172,
"from": {
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
},
"gas": 3141592,
"gasUsed": 493172,
"hash": "0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed",
"index": 0,
"logs": [],
"to": null
"responses": [
{
"data": {
"transaction": {
"block": {
"hash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
"createdContract": {
"address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"
},
"cumulativeGasUsed": 493172,
"from": {
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
},
"gas": 3141592,
"gasUsed": 493172,
"hash": "0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed",
"index": 0,
"logs": [],
"to": null
}
}
},
{
"data": {
"transaction": {
"block": {
"hash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
"createdContract": {
"address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"
},
"cumulativeGasUsed": 493172,
"from": {
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
},
"gas": "0x2fefd8",
"gasUsed": 493172,
"hash": "0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed",
"index": 0,
"logs": [],
"to": null
}
}
}
}],
],
"statusCode": 200
}

View File

@ -169,8 +169,11 @@ proc stripLeadingZeros(x: string): string =
strip(x, leading = true, trailing = false, chars = {'0'})
proc bigIntNode(val: UInt256): RespResult =
let hex = stripLeadingZeros(val.toHex)
ok(Node(kind: nkString, stringVal: "0x" & hex, pos: Pos()))
if val == 0.u256:
ok(Node(kind: nkString, stringVal: "0x0", pos: Pos()))
else:
let hex = stripLeadingZeros(val.toHex)
ok(Node(kind: nkString, stringVal: "0x" & hex, pos: Pos()))
proc bigIntNode(x: uint64 | int64): RespResult =
# stdlib toHex is not suitable for hive
@ -218,8 +221,11 @@ proc getOmmerCount(ctx: GraphqlContextRef, ommersHash: Hash256): RespResult =
proc getOmmers(ctx: GraphqlContextRef, ommersHash: Hash256): RespResult =
try:
let uncles = getUncles(ctx.chainDB, ommersHash)
if uncles.len == 0:
return ok(respNull())
when false:
# EIP 1767 says no ommers == null
# but hive test case want empty array []
if uncles.len == 0:
return ok(respNull())
var list = respList()
for n in uncles:
list.add headerNode(ctx, n)
@ -301,8 +307,11 @@ proc getTxByHash(ctx: GraphqlContextRef, hash: Hash256): RespResult =
proc accountNode(ctx: GraphqlContextRef, header: BlockHeader, address: EthAddress): RespResult =
let db = getAccountDb(ctx.chainDB, header)
if not db.accountExists(address):
return ok(respNull())
when false:
# EIP 1767 unclear about non existent account
# but hive test case demand something
if not db.accountExists(address):
return ok(respNull())
let acc = db.getAccount(address)
ok(accountNode(ctx, acc, address, db))
@ -637,8 +646,7 @@ proc txCreatedContract(ud: RootRef, params: Args, parent: Node): RespResult {.ap
return hres
let h = HeaderNode(hres.get())
let db = getAccountDb(ctx.chainDB, h.header)
let creationNonce = db.getNonce(sender)
let contractAddress = generateAddress(sender, creationNonce)
let contractAddress = generateAddress(sender, tx.tx.nonce)
ctx.accountNode(h.header, contractAddress)
proc txLogs(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =

View File

@ -154,7 +154,7 @@
"code":"0x",
"storage":"0x0000000000000000000000000000000000000000000000000000000000000000"
},
"nullAccount":null
"nullAccount":{"__typename":"Account"}
}
}
"""