Releases: web3swift-team/web3swift
3.0.0-RC2
What's Changed
- Generic network layer by @yaroslavyaroslav in #577
How to
Using new API is as easy as write three line of a code:
func feeHistory(blockCount: UInt, block: BlockNumber, percentiles:[Double]) async throws -> Web3.Oracle.FeeHistory {
let requestCall: APIRequest = .feeHistory(blockCount, block, percentiles)
let response: APIResponse<Web3.Oracle.FeeHistory> = try await APIRequest.sendRequest(with: web3.provider, for: requestCall) /// explicitly declaring `Result` type is **required**.
return response.result
}
- On the first line you’re creating a request where passing all required and strictly typed parameters.
- On a second you’re both declaring expected
Result
type and making a network request. - On the third one you’re reaching result itself.
And that’s it, you’re done here.
Types overview
There’s follow types have been implemented
Main types
public enum APIRequest
This is the main type of whole network layer API. It responsible to both compose API request to a node and to send it to a node with a given provider (which stores Node URL and session), as cases it have all available JSON RPC requests and most of them have associated values to pass request parameters there.
Additionally it have follow computed properties:
public responseType: APIResultType.Type
- this variable returns appropriateResult
generic parameter type for each API call. Which can be split generally in two parts:- Literals (e.g.
Int
,BigInt
) which could not be extended on client side. - Decodable structures (e.g.
Block
) which could be extended on client side. That said that user able to add additionalResult
type on their side if it’s not literal (e.g. if it’s astruct
orclass
).
- Literals (e.g.
method: REST
- this internal variable returns REST method for each API call. Currently its returning onlyPOST
one.parameters: [RequestParameter]
- this internal variable is purposed to return parameters of request as an heterogeneous Array which is Node expected in most cases.encodedBody: Data
- this internal variable returns encoded data ofRequestBody
type, which is required to compose correct request to a Node.call: String
- this internal variable returns method call string, which is one of property ofRequestBody
type.
There’s two methods are provided for API calls.
public static func sendRequest<Result>(with provider: Web3Provider, for call: APIRequest) async throws -> APIResponse<Result>
- this method is the main one. It composes and sends request to a Node. This method could be called only with explicitly return type declaration likelet response: APIResponse<BigUInt> = try await APIRequest.sendRequest(with: self.provider, for: .gasPrice)
, whereresponse
is the whole APIResponse struct with a service properties and theresponse.result
is a point of interests in example above — gas price.
static func setupRequest(for call: APIRequest, with provider: Web3Provider) -> URLRequest
- this internal method is just composing network request from all properties of relatedAPIRequest
case.
public struct APIResponse<Result>: Decodable where Result: APIResultType
This generic struct is any Ethereum node response container, where all stored properties are utility fields and one generic result: Result
is the property that stores strictly typed result of any given request.
Protocols
To make things work there’s are some protocols be presented which both adds restriction to types that could be passed within new API and add some common methods to Literal types to be able initialize it from a hex string.
APIResultType
This protocol responsible for any nonliteral type that could be stored within APIResponse<Result>
generic struct. This protocol have no requirements except it conforms Decodable
protocol. So any decodable type could be extended to conforms it.
LiteralInitiableFromString
This protocol responsible for any literal types that could be stored within APIResponse<Result>
. This protocol conforms APIResultType
and it adds some requirements to it, like initializer from hex string. Despite that a given type could be extended to implement such initializer ==this should be done on a user side== because to make it work it requires some work within sendRequest
method to be done.
IntegerInitableWithRadix
This protocol is just utility one, which declares some convenient initializer which have both Int
and BigInt
types, but don’t have any common protocol which declares such requirement.
Utility types
struct RequestBody: Encodable
— just a request body that passes into request body.public enum REST: String
— enum of REST methods. OnlyPOST
andGET
presented yet.enum RequestParameter
— this enum is a request composing helper. It make happened to encode request attribute as heterogeneous array.protocol APIRequestParameterType: Encodable
— this type is part of theRequestParameter
enum mechanism which purpose is to restrict types that can be passed as associated types withinRequestParameter
cases.protocol APIRequestParameterElementType: Encodable
— this type purpose is the same asAPIRequestParameterType
one except this one is made forElement
s of anArray
s when the latter is an associated type of a givenRequestParameter
case.
Full Changelog: 3.0.0-RC1...3.0.0-RC2
2.6.5
What's Changed
Full Changelog: 2.6.4...2.6.5
3.0.0-RC1
NOTE: This is the first 3.0.0 release, e.g. it's alpha. We're not guarantee any reliability neither API stability in further versions.
Main features
- This RC removes
Promise
concurrency types from the library and replace them to modernasync/await
concurrency mechanism. - Increased minimal OS version that support by the lib: iOS 13, macOS 10.5 (due to
async/await
). - This is the last version which supports
Carthage
dependency manager, on3.0.0-RC2
it'll be dropped due to its low prevalence.
What's Changed
- Remove Promises by @pharms-eth in #515
- Update unstable branch with 2.6.1 patch by @yaroslavyaroslav in #541
- Refactor ci/cd pipeline by @yaroslavyaroslav in #545
- update docs for automatic gas. by @yaroslavyaroslav in #556
- Automatic Gas rewrite for
unstable
branch by @mloit in #559 - Merge master into develop by @yaroslavyaroslav in #562
- develop to unstable by @yaroslavyaroslav in #563
Full Changelog: 2.6.4...3.0.0-RC1
2.6.4
2.6.3
What's Changed
- Feature/automatic gas 1559 by @mloit in #547
Oracle.suggestGasFeeLegacy
method fixup by @yaroslavyaroslav in #551
Full Changelog: 2.6.2...2.6.3
2.6.2
What's Changed
- Fix #540 by freezing CryptoSwift dependency to last working version (1.4.3) by @yaroslavyaroslav
Full Changelog: 2.6.1...2.6.2
2.6.1
2.6.0
Features
What's Changed
- Remove BrowserViewController if building for anything other than iOS by @mloit in #503
- Feature/pre swiftlint cleanup by @mloit in #495
- Feature/late lint fixups by @mloit in #508
- Fix Base58 Decoding by @mloit in #504
- Swiftlint by @mloit in #499
- ERC1155: Change access control for Interfece-based methods. by @mrklos in #494
- feat: solidity sha3 implementation added by @JeneaVranceanu in #506
- add indentation check [default is 4 spaces per tab-stop] by @mloit in #512
- EIP-1559 support release by @yaroslavyaroslav in #510
- EIP-1559 Gas prediction implementation by @yaroslavyaroslav in #513
- feat: decoding ABI with solidity error types by @JeneaVranceanu in #455
- Gas prediction implementation by @yaroslavyaroslav in #514
- Bug fix/transaction index by @mloit in #521
- EIP-1559 transaction support by @mloit in #509
Full Changelog: 2.5.1...2.6.0
2.5.1
Patch includes following changes
- Drop Carthage cache files by yaroslavyaroslav
- Drop examples cocoapods cache files by yaroslavyaroslav
- Improve ci/cd pipeline by adding localTests job by yaroslavyaroslav
- Rename tests in swift style name convention (CamelCase) by yaroslavyaroslav
- Enable run ganache util in ci/cd pipeline (required for local tests) by yaroslavyaroslav
- Clear lib warnings on build #437 by Valter4578 & mliot
- Change UINT64_MAX to UInt64.max by mloit
- Update CHANGELOG.md by ZeroCode999
- Fix tokenURI method name for ERC721 and ERC721x tokens #419 by Sarquella
- Provide basic tolerance to EIP-1559 data by mloit
- Fix for buffer overflow in [Data|SECP256K1].randomBytes() #470 by mloit
- Arbitrary clean project code by mloit
- Fix github actions config issue that occasionally cancels running jobs by yaroslavyaroslav
- mini-rollup of several issues by mloit
2.5.0
- Fixed Cocoapods building.
- Fixed Carthage building.
- Fixed Swift Package Manager building.
- Added github-actions pipeline.