Skip to content

Commit 351b671

Browse files
Update for network layer:
- `GasPrice` - `GetTransactionCount`
1 parent 27a28e2 commit 351b671

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

Sources/web3swift/API/Web3+APIMethod.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ extension APIRequest {
102102
case .getBalance: return BigUInt.self
103103
case .getBlockByHash: return Block.self
104104
case .getBlockByNumber: return Block.self
105+
case .gasPrice: return BigUInt.self
105106
case .feeHistory: return Web3.Oracle.FeeHistory.self
107+
case .getTransactionCount: return UInt.self
106108
default: return String.self
107109
}
108110
}

Sources/web3swift/Promises/Promise+Web3+Eth+GetGasPrice.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ import BigInt
1010

1111
extension web3.Eth {
1212
public func gasPrice() async throws -> BigUInt {
13-
let request = JSONRPCRequestFabric.prepareRequest(.gasPrice, parameters: [])
14-
let response = try await web3.dispatch(request)
15-
16-
guard let value: BigUInt = response.getValue() else {
17-
if response.error != nil {
18-
throw Web3Error.nodeError(desc: response.error!.message)
19-
}
20-
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
21-
}
22-
return value
23-
13+
let response: APIResponse<BigUInt> = try await APIRequest.sendRequest(with: self.provider, for: .gasPrice)
14+
return response.result
2415
}
2516
}

Sources/web3swift/Promises/Promise+Web3+Eth+GetTransactionCount.swift

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,16 @@
55
//
66

77
import Foundation
8-
import BigInt
98

109

1110
extension web3.Eth {
12-
public func getTransactionCount(for address: EthereumAddress, onBlock: String = "latest") async throws -> BigUInt {
13-
let addr = address.address
14-
return try await getTransactionCount(address: addr, onBlock: onBlock)
11+
public func getTransactionCount(for address: EthereumAddress, onBlock: BlockNumber) async throws -> UInt {
12+
try await getTransactionCount(address: address.address, onBlock: onBlock)
1513
}
1614

17-
public func getTransactionCount(address: String, onBlock: String = "latest") async throws -> BigUInt {
18-
let request = JSONRPCRequestFabric.prepareRequest(.getTransactionCount, parameters: [address.lowercased(), onBlock])
19-
let response = try await web3.dispatch(request)
20-
21-
guard let value: BigUInt = response.getValue() else {
22-
if response.error != nil {
23-
throw Web3Error.nodeError(desc: response.error!.message)
24-
}
25-
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
26-
}
27-
return value
15+
public func getTransactionCount(address: Address, onBlock: BlockNumber) async throws -> UInt {
16+
let requestCall: APIRequest = .getTransactionCount(address, onBlock)
17+
let response: APIResponse<UInt> = APIRequest.sendRequest(with: self.provider, for: requestCall)
18+
return response.result
2819
}
2920
}

0 commit comments

Comments
 (0)