fix(@desktop/wallet): Iterate over collectible with balance
This commit is contained in:
parent
0eb2a23600
commit
314d1833a2
|
@ -21,6 +21,7 @@ proc callPrivateRPC*(methodName: string, payload = %* []): string =
|
||||||
let response = status_go.callPrivateRPC($inputJSON)
|
let response = status_go.callPrivateRPC($inputJSON)
|
||||||
result = $response
|
result = $response
|
||||||
if parseJSON(result).hasKey("error"):
|
if parseJSON(result).hasKey("error"):
|
||||||
|
writeStackTrace()
|
||||||
error "rpc response error", result, payload, methodName
|
error "rpc response error", result, payload, methodName
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "error doing rpc request", methodName = methodName, exception=e.msg
|
error "error doing rpc request", methodName = methodName, exception=e.msg
|
||||||
|
|
|
@ -56,17 +56,34 @@ proc tokenOfOwnerByIndex(contract: Erc721Contract, address: Address, index: Stui
|
||||||
return -1
|
return -1
|
||||||
result = fromHex[int](res)
|
result = fromHex[int](res)
|
||||||
|
|
||||||
|
proc balanceOf(contract: Erc721Contract, address: Address): int =
|
||||||
|
let
|
||||||
|
balanceOf = BalanceOf(address: address)
|
||||||
|
payload = %* [{
|
||||||
|
"to": $contract.address,
|
||||||
|
"data": contract.methods["balanceOf"].encodeAbi(balanceOf)
|
||||||
|
}, "latest"]
|
||||||
|
response = callPrivateRPC("eth_call", payload)
|
||||||
|
jsonResponse = parseJson($response)
|
||||||
|
if (not jsonResponse.hasKey("result")):
|
||||||
|
return 0
|
||||||
|
let res = jsonResponse["result"].getStr
|
||||||
|
if (res == "0x"):
|
||||||
|
return 0
|
||||||
|
result = fromHex[int](res)
|
||||||
|
|
||||||
proc tokensOfOwnerByIndex(contract: Erc721Contract, address: Address): seq[int] =
|
proc tokensOfOwnerByIndex(contract: Erc721Contract, address: Address): seq[int] =
|
||||||
var index = 0
|
var index = 0
|
||||||
var token: int
|
var token: int
|
||||||
|
var maxIndex: int = balanceOf(contract, address)
|
||||||
result = @[]
|
result = @[]
|
||||||
while (true):
|
while index < maxIndex and result.len <= MAX_TOKENS:
|
||||||
token = tokenOfOwnerByIndex(contract, address, index.u256)
|
token = tokenOfOwnerByIndex(contract, address, index.u256)
|
||||||
if (token == -1 or token == 0 or result.len > MAX_TOKENS):
|
|
||||||
return result
|
|
||||||
result.add(token)
|
result.add(token)
|
||||||
index = index + 1
|
index = index + 1
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
proc getCryptoKittiesBatch*(address: Address, offset: int = 0): seq[Collectible] =
|
proc getCryptoKittiesBatch*(address: Address, offset: int = 0): seq[Collectible] =
|
||||||
var cryptokitties: seq[Collectible]
|
var cryptokitties: seq[Collectible]
|
||||||
cryptokitties = @[]
|
cryptokitties = @[]
|
||||||
|
|
Loading…
Reference in New Issue