EOSIO / eosio-swift

EOSIO SDK for Swift - API for integrating with EOSIO-based blockchains
https://eosio.github.io/eosio-swift
MIT License
60 stars 35 forks source link

Got 404 error from get_block_info #295

Open jke661s opened 3 years ago

jke661s commented 3 years ago

Hello,

I got 404 error when transferring token to others.

The error is "Invalid HTTP response (404) for https://eos.greymass.com/v1/chain/get_block_info."

The same code works under Jungle 3 Test Net (https://jungle3.cryptolions.io:443).

May I know how to fix it?

Cheers,

opi-smccoole commented 3 years ago

This is a configuration issue between your client and the greymass server. 404 means that the URL endpoint https://eos.greymass.com/v1/chain/get_block_info is not found, so that means its not available (server might not be at the version that has get_block_info?), configured or exposed to your client. get_block_info is used in calculating TAPOS for the transaction (refBlockNum and refBlockPrefix). The only other alternative would be to get this information using get_block (much more expensive than get_block_info) and set the TAPOS in the transaction before signing so that it wouldn't make the get_block_info call.

jke661s commented 3 years ago

Do you mean using get_block to get refBlockNum and refBlockPrefix first, and then set those two values to the transaction before signing?

opi-smccoole commented 3 years ago

Yes, the code will determine that they are already set and will not call getBlockInfo (which calls get_block_info on the chain). The SDK exposes get_block as public func getBlock(requestParameters: EosioRpcBlockRequest, completion: @escaping (EosioResult<EosioRpcBlockResponse, EosioError>) -> Void) so you can use that or the PromiseKit wrapped version to get the information you need. Alternatively you can use an earlier version of the libraries because they did use getBlock() in the past, but then you will not have SPM support or some of the other updates made in 1.0.0

jke661s commented 3 years ago

I noticed that I need to pass a blockNumOrId in when calling this getBlock. May I know how to get this id please?

opi-smccoole commented 3 years ago

You'll have to get the last irreversible block from a getInfoBase() call. The code here can give you an idea: https://github.com/EOSIO/eosio-swift/blob/43bd15ce5abcdf2f8028f6484f677e98caf4c88d/Sources/EosioSwift/EosioTransaction/EosioTransaction.swift#L390

jke661s commented 3 years ago

Thanks. I'll give it a try.

skygrid-engineering commented 3 years ago

@jke661s did you get this working? Can you share any details on what worked for you?

Mattijah commented 3 years ago

Having the same problem. Why do you guys add a feature that's not even supported by the majority (none) of nodes?

opi-smccoole commented 3 years ago

Version 1.0.0 of the SDKs is meant to align with release 2.1 (was previously going to be tagged as 3.0) of EOS. Earlier releases of the SDK can always be used for earlier node versions. When I get a chance I will try to post a code snippet that shows how to work around get_block_info not being present and post it here.

CyrilCermak commented 3 years ago

I have the same issue, luckily, the old version is still there and that one does not use the unsupported get_block_info. So this setup still works fine.

pod "EosioSwift", "~> 0.4"
pod "EosioSwiftAbieosSerializationProvider", "~> 0.4"
pod "EosioSwiftVaultSignatureProvider", "~> 0.4"

Nevertheless, I would expect that the API of this library reflects the stable version of the EOS API documentation. As of now there, there is no get_block_info method stated there.

https://developers.eos.io/manuals/eos/latest/nodeos/plugins/chain_api_plugin/api-reference/index#operation/get_account

I will wait until the chains are updated or the newer version supports the stable chain API's.

Thanks!

CyrilCermak commented 3 years ago

Hi @opi-smccoole, I had a look at it and here is a PR that would give the option to fall back to an older version that does not support the new functionality.

https://github.com/EOSIO/eosio-swift/pull/296