web3swift icon indicating copy to clipboard operation
web3swift copied to clipboard

Promise.wait() performs infinite time

Open motarykin opened this issue 2 years ago • 3 comments

Hello.

My code gets a balance of ERC721 on wallet and after trying to go through getTokenOwnedByIndex. 6 request simultaneously runs and wait. I connected proxy and see the balance request was sent and returned. getTokenOwnedByIndex requests event don't make any network request.

image

Code stucks after some made token. After reset wallet code starts work well, but after some count it stucks.

Code:

        guard let web3Provider = web3Provider else {
            throw Web3NetworkError.noProvider
        }
        
        guard let contractABI = contractABI else {
            throw Web3NetworkError.invalidContractABI
        }
        
        let contract = web3Provider.contract(contractABI, at: contractAddress)!
        
        var transactionOptions = TransactionOptions()
        transactionOptions.callOnBlock = .latest
        let result = try contract.read("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject])!.call(transactionOptions: transactionOptions)
        guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
        return res

motarykin avatar Mar 10 '22 21:03 motarykin

Extra info: usually reproducible when tokens are requested by id, but kill the app and launch these requests again. Is there any caching inside lib?

Strange, that balance request finished successfully, but next tokenOfOwnerByIndex are stucks.

ghost avatar Mar 11 '22 09:03 ghost

Also, investigated a bit more. Looks like the issue is in queue. When there are 6 requests for tokenOfOwnerByIndex they're stuck. When there are 5 requests for tokenOfOwnerByIndex they're pass, but when trying to fetch TokenURI, only 3 pass. When there are 3 requests, every request passes.

So, should requests be performed in serial queue?

ghost avatar Mar 11 '22 10:03 ghost

Thank you for that. There'll be no Promises in version 3.0.0 which is currently in deep development. So the issue would be resolved itself.

ETA 3.0.0 is about 3 months, but there's RC available (pretty unstable yet).

yaroslavyaroslav avatar May 31 '22 18:05 yaroslavyaroslav