Skip to content

Commit 3bdabce

Browse files
Add documentation to API calls.
1 parent 9f5e942 commit 3bdabce

File tree

1 file changed

+84
-13
lines changed

1 file changed

+84
-13
lines changed

Sources/web3swift/API/APIMethod.swift

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,104 @@ public typealias TransactionHash = Hash // 64 chars length without 0x
7575
/// - `protocol APIRequestParameterElementType: Encodable` — this type purpose is the same as ``APIRequestParameterType` one except this one is made for `Element`s of an `Array` s when the latter is an associated type of a given `RequestParameter` case.
7676
public enum APIRequest {
7777
// MARK: - Official API
78-
// 0 parameter in call
78+
7979
/// Gas price request
8080
case gasPrice
81+
82+
/// Get last block number
8183
case blockNumber
84+
85+
/// Get current network
8286
case getNetwork
87+
88+
/// Get accounts
8389
case getAccounts
84-
// ??
90+
91+
/// Estimate required gas amount for transaction
92+
/// - Parameters:
93+
/// - TransactionParameters: parameters of planned transaction
94+
/// - BlockNumber: block where it should be evalueated
8595
case estimateGas(TransactionParameters, BlockNumber)
96+
97+
/// Send raw transaction
98+
/// - Parameters:
99+
/// - Hash: String representation of a transaction data
86100
case sendRawTransaction(Hash)
101+
102+
/// Send transaction object
103+
/// - Parameters:
104+
/// - TransactionParameters: transaction to be sent into chain
87105
case sendTransaction(TransactionParameters)
106+
107+
/// Get transaction by hash
108+
/// - Parameters:
109+
/// - Hash: transaction hash ID
88110
case getTransactionByHash(Hash)
111+
112+
/// Get transaction receipt
113+
/// - Paramters:
114+
/// - Hash: transaction hash ID
89115
case getTransactionReceipt(Hash)
116+
117+
/// Get logs
118+
/// - Parameters:
119+
/// - EventFilterParameters: event filter parameters for interaction with node
90120
case getLogs(EventFilterParameters)
121+
122+
/// Sign given string by users private key
123+
/// - Parameters:
124+
/// - Address: address where to sign
125+
/// - String: custom string to be signed
91126
case personalSign(Address, String)
127+
128+
/// Call a given contract
129+
///
130+
/// Mostly could be used for intreacting with a contracts, but also could be used for simple transaction sending
131+
/// - Parameters:
132+
/// - TransactionParameters: transaction to be sent into chain
133+
/// - BlockNumber: block where it should be evalueated
92134
case call(TransactionParameters, BlockNumber)
135+
136+
/// Get a transaction counts on a given block
137+
///
138+
/// Consider that there's no out of the box way to get counts of all transactions sent by the address
139+
/// except calling this method on each and every block in the chain by rather self or any third party service.
140+
///
141+
/// - Parameters:
142+
/// - Address: address which is engaged in transaction
143+
/// - BlockNumber: block to check
93144
case getTransactionCount(Address, BlockNumber)
145+
146+
/// Get a balance of a given address
147+
/// - Parameters:
148+
/// - Address: address which balance would be recieved
149+
/// - BlockNumber: block to check
94150
case getBalance(Address, BlockNumber)
95151

96152
/// Returns the value from a storage position at a given address.
97153
///
98154
/// - Parameters:
99-
/// - Address: Address
100-
/// - Storage: slot
101-
/// - BlockNumber: sd
102-
case getStorageAt(Address, Hash, BlockNumber)
155+
/// - Address: Address
156+
/// - Position: Integer of the position in the storage.
157+
/// - BlockNumber: block to check
158+
case getStorageAt(Address, BigUInt, BlockNumber)
103159

160+
/// Returns code of a given address
161+
/// - Parameters:
162+
/// - Address: address what code to get
163+
/// - BlockNumber: block to check
104164
case getCode(Address, BlockNumber)
165+
166+
/// Get block object by hash
167+
/// - Parameters:
168+
/// - Hash: Hash of the block to reach
169+
/// - Bool: Transaction included in block could be received as just array of their hashes or as Transaction objects, set true for latter.
105170
case getBlockByHash(Hash, Bool)
171+
172+
/// Get block object by its number
173+
/// - Parameters:
174+
/// - Hash: Number of the block to reach
175+
/// - Bool: Transaction included in block could be received as just array of their hashes or as Transaction objects, set true for latter.
106176
case getBlockByNumber(BlockNumber, Bool)
107177

108178
/// Returns fee history with a respect to given setup
@@ -112,14 +182,15 @@ public enum APIRequest {
112182
/// than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance.
113183
///
114184
/// - Parameters:
115-
/// - UInt: Requested range of blocks. Clients will return less than the requested range if not all blocks are available.
116-
/// - BlockNumber: Highest block of the requested range.
117-
/// - [Double]: A monotonically increasing list of percentile values.
118-
/// For each block in the requested range, the transactions will be sorted in ascending order
119-
/// by effective tip per gas and the coresponding effective tip for the percentile will be determined, accounting for gas consumed."
185+
/// - UInt: Requested range of blocks. Clients will return less than the requested range if not all blocks are available.
186+
/// - BlockNumber: Highest block of the requested range.
187+
/// - [Double]: A monotonically increasing list of percentile values.
188+
/// For each block in the requested range, the transactions will be sorted in ascending order
189+
/// by effective tip per gas and the coresponding effective tip for the percentile will be determined, accounting for gas consumed."
120190
case feeHistory(BigUInt, BlockNumber, [Double])
121191

122192
// MARK: - Additional API
193+
123194
/// Creates new account.
124195
///
125196
/// Note: it becomes the new current unlocked account. There can only be one unlocked account at a time.
@@ -232,8 +303,8 @@ extension APIRequest {
232303
case .getBalance(let address, let blockNumber):
233304
return [RequestParameter.string(address), RequestParameter.string(blockNumber.stringValue)]
234305

235-
case .getStorageAt(let address, let hash, let blockNumber):
236-
return [RequestParameter.string(address), RequestParameter.string(hash), RequestParameter.string(blockNumber.stringValue)]
306+
case .getStorageAt(let address, let bigUInt, let blockNumber):
307+
return [RequestParameter.string(address), RequestParameter.string(bigUInt.hexString), RequestParameter.string(blockNumber.stringValue)]
237308

238309
case .getCode(let address, let blockNumber):
239310
return [RequestParameter.string(address), RequestParameter.string(blockNumber.stringValue)]

0 commit comments

Comments
 (0)