Skip to content

Commit 317cd4d

Browse files
Rename EncodableTransaction to CodableTransaction
because it's conforms `Codable` rather `Encodable`.
1 parent 10e4b61 commit 317cd4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+164
-164
lines changed

Sources/Core/Contract/ContractProtocol.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ import BigInt
5656
/// ```
5757
///
5858
/// ⚠️ If you pass in only constructor or only parameters - it will have no effect on the final transaction object.
59-
/// Also, you have an option to set any extra bytes at the end of ``EncodableTransaction/data`` attribute.
59+
/// Also, you have an option to set any extra bytes at the end of ``CodableTransaction/data`` attribute.
6060
/// Alternatively you can encode constructor parameters outside of the deploy function and only set `extraData` to pass in these
6161
/// parameters:
6262
///
6363
/// ```swift
6464
/// // `encodeParameters` call returns `Data?`. Check it for nullability before calling `deploy`
65-
/// // function to create `EncodableTransaction`.
65+
/// // function to create `CodableTransaction`.
6666
/// let encodedConstructorArguments = someConstructor.encodeParameters(arrayOfInputArguments)
6767
/// constructor.deploy(bytecode: smartContractBytecode, extraData: encodedConstructorArguments)
6868
/// ```
@@ -123,7 +123,7 @@ public protocol ContractProtocol {
123123
func deploy(bytecode: Data,
124124
constructor: ABI.Element.Constructor?,
125125
parameters: [AnyObject]?,
126-
extraData: Data?) -> EncodableTransaction?
126+
extraData: Data?) -> CodableTransaction?
127127

128128
/// Creates function call transaction with data set as `method` encoded with given `parameters`.
129129
/// The `method` must be part of the ABI used to init this contract.
@@ -135,7 +135,7 @@ public protocol ContractProtocol {
135135
/// - parameters: method input arguments;
136136
/// - extraData: additional data to append at the end of `transaction.data` field;
137137
/// - Returns: transaction object if `method` was found and `parameters` were successfully encoded.
138-
func method(_ method: String, parameters: [AnyObject], extraData: Data?) -> EncodableTransaction?
138+
func method(_ method: String, parameters: [AnyObject], extraData: Data?) -> CodableTransaction?
139139

140140
/// Decode output data of a function.
141141
/// - Parameters:
@@ -187,7 +187,7 @@ extension ContractProtocol {
187187
func deploy(_ bytecode: Data,
188188
constructor: ABI.Element.Constructor? = nil,
189189
parameters: [AnyObject]? = nil,
190-
extraData: Data? = nil) -> EncodableTransaction? {
190+
extraData: Data? = nil) -> CodableTransaction? {
191191
deploy(bytecode: bytecode,
192192
constructor: constructor,
193193
parameters: parameters,
@@ -200,7 +200,7 @@ extension ContractProtocol {
200200
/// See ``ContractProtocol/method(_:parameters:extraData:)`` for details.
201201
func method(_ method: String = "fallback",
202202
parameters: [AnyObject]? = nil,
203-
extraData: Data? = nil) -> EncodableTransaction? {
203+
extraData: Data? = nil) -> CodableTransaction? {
204204
self.method(method, parameters: parameters ?? [], extraData: extraData)
205205
}
206206

@@ -219,7 +219,7 @@ extension DefaultContractProtocol {
219219
public func deploy(bytecode: Data,
220220
constructor: ABI.Element.Constructor?,
221221
parameters: [AnyObject]?,
222-
extraData: Data?) -> EncodableTransaction? {
222+
extraData: Data?) -> CodableTransaction? {
223223
var fullData = bytecode
224224

225225
if let constructor = constructor,
@@ -239,11 +239,11 @@ extension DefaultContractProtocol {
239239
}
240240

241241
// MARK: Writing Data flow
242-
return EncodableTransaction(to: .contractDeploymentAddress(),
242+
return CodableTransaction(to: .contractDeploymentAddress(),
243243
value: BigUInt(0),
244244
data: fullData
245245
// FIXME: Return parameters
246-
// parameters: EncodableTransaction()
246+
// parameters: CodableTransaction()
247247
)
248248
}
249249

@@ -252,7 +252,7 @@ extension DefaultContractProtocol {
252252
/// - method: Method to call
253253
/// - parameters: Parameters to pass to method call
254254
/// - extraData: Any additional data that needs to be encoded
255-
/// - Returns: preset EncodableTransaction with filled date
255+
/// - Returns: preset CodableTransaction with filled date
256256
///
257257
/// Returned transaction have filled following priperties:
258258
/// - to: contractAddress
@@ -262,16 +262,16 @@ extension DefaultContractProtocol {
262262
public func method(_ method: String,
263263
parameters: [AnyObject],
264264
// FIXME: Return type CodableTransaction
265-
extraData: Data?) -> EncodableTransaction? {
265+
extraData: Data?) -> CodableTransaction? {
266266
guard let to = self.address else { return nil }
267267

268268
// FIXME: This should be changed up to release
269-
var transaction = EncodableTransaction(to: to)
269+
var transaction = CodableTransaction(to: to)
270270

271271
// MARK: - Encoding ABI Data flow
272272
if method == "fallback" {
273273
// FIXME: Return parameters
274-
return EncodableTransaction(to: to, value: BigUInt(0), data: extraData ?? Data()//, parameters: params
274+
return CodableTransaction(to: to, value: BigUInt(0), data: extraData ?? Data()//, parameters: params
275275
)
276276
}
277277

Sources/Core/EthereumNetwork/Request/APIRequest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public enum APIRequest {
9696
/// - Parameters:
9797
/// - TransactionParameters: parameters of planned transaction
9898
/// - BlockNumber: block where it should be evalueated
99-
case estimateGas(EncodableTransaction, BlockNumber)
99+
case estimateGas(CodableTransaction, BlockNumber)
100100

101101
/// Send raw transaction
102102
/// - Parameters:
@@ -106,7 +106,7 @@ public enum APIRequest {
106106
/// Send transaction object
107107
/// - Parameters:
108108
/// - TransactionParameters: transaction to be sent into chain
109-
case sendTransaction(EncodableTransaction)
109+
case sendTransaction(CodableTransaction)
110110

111111
/// Get transaction by hash
112112
/// - Parameters:
@@ -135,7 +135,7 @@ public enum APIRequest {
135135
/// - Parameters:
136136
/// - TransactionParameters: transaction to be sent into chain
137137
/// - BlockNumber: block where it should be evalueated
138-
case call(EncodableTransaction, BlockNumber)
138+
case call(CodableTransaction, BlockNumber)
139139

140140
/// Get a transaction counts on a given block
141141
///

Sources/Core/EthereumNetwork/RequestParameter/RequestParameter+Encodable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension RequestParameter: Encodable {
4646
case is Bool.Type: try enumContainer.encode(rawValue as! Bool)
4747
case is [Bool].Type: try enumContainer.encode(rawValue as! [Bool])
4848

49-
case is EncodableTransaction.Type: try enumContainer.encode(rawValue as! EncodableTransaction)
49+
case is CodableTransaction.Type: try enumContainer.encode(rawValue as! CodableTransaction)
5050
case is EventFilterParameters.Type: try enumContainer.encode(rawValue as! EventFilterParameters)
5151
default: break /// can't be executed, coz possible `self.rawValue` types are strictly defined in it's inplementation.`
5252
}

Sources/Core/EthereumNetwork/RequestParameter/RequestParameter+RawRepresentable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension RequestParameter: RawRepresentable {
3737
case is Bool.Type: self = .bool(rawValue as! Bool)
3838
case is [Bool].Type: self = .boolArray(rawValue as! [Bool])
3939

40-
case is [EncodableTransaction].Type: self = .transaction(rawValue as! EncodableTransaction)
40+
case is [CodableTransaction].Type: self = .transaction(rawValue as! CodableTransaction)
4141
case is [EventFilterParameters].Type: self = .eventFilter(rawValue as! EventFilterParameters)
4242
default: return nil
4343
}

Sources/Core/EthereumNetwork/RequestParameter/RequestParameter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ enum RequestParameter {
5050
case bool(Bool)
5151
case boolArray([Bool])
5252

53-
case transaction(EncodableTransaction)
53+
case transaction(CodableTransaction)
5454
case eventFilter(EventFilterParameters)
5555
}

Sources/Core/Structure/Event+Protocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public struct EventParserResult: EventParserResultProtocol {
3535

3636
/// Protocol for generic Ethereum event parser
3737
public protocol EventParserProtocol {
38-
func parseTransaction(_ transaction: EncodableTransaction) async throws -> [EventParserResultProtocol]
38+
func parseTransaction(_ transaction: CodableTransaction) async throws -> [EventParserResultProtocol]
3939
func parseTransactionByHash(_ hash: Data) async throws -> [EventParserResultProtocol]
4040
func parseBlock(_ block: Block) async throws -> [EventParserResultProtocol]
4141
func parseBlockByNumber(_ blockNumber: BigUInt) async throws -> [EventParserResultProtocol]
42-
func parseTransactionPromise(_ transaction: EncodableTransaction) async throws -> [EventParserResultProtocol]
42+
func parseTransactionPromise(_ transaction: CodableTransaction) async throws -> [EventParserResultProtocol]
4343
func parseTransactionByHashPromise(_ hash: Data) async throws -> [EventParserResultProtocol]
4444
func parseBlockByNumberPromise(_ blockNumber: BigUInt) async throws -> [EventParserResultProtocol]
4545
func parseBlockPromise(_ block: Block) async throws -> [EventParserResultProtocol]

Sources/Core/Structure/Transaction/TransactionDetails.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct TransactionDetails: Decodable {
1212
public var blockHash: Data?
1313
public var blockNumber: BigUInt?
1414
public var transactionIndex: BigUInt?
15-
public var transaction: EncodableTransaction
15+
public var transaction: CodableTransaction
1616

1717
enum CodingKeys: String, CodingKey {
1818
case blockHash
@@ -25,6 +25,6 @@ public struct TransactionDetails: Decodable {
2525
self.blockNumber = try? container.decodeHex(BigUInt.self, forKey: .blockNumber)
2626
self.blockHash = try? container.decodeHex(Data.self, forKey: .blockHash)
2727
self.transactionIndex = try? container.decodeHex(BigUInt.self, forKey: .transactionIndex)
28-
self.transaction = try EncodableTransaction(from: decoder)
28+
self.transaction = try CodableTransaction(from: decoder)
2929
}
3030
}

Sources/Core/Structure/Transaction/TransactionInBlock.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import Foundation
99

1010
public enum TransactionInBlock: Decodable {
1111
case hash(Data)
12-
case transaction(EncodableTransaction)
12+
case transaction(CodableTransaction)
1313
case null
1414

1515
public init(from decoder: Decoder) throws {
1616
let value = try decoder.singleValueContainer()
1717
if let string = try? value.decode(String.self) {
1818
guard let d = Data.fromHex(string) else {throw Web3Error.dataError}
1919
self = .hash(d)
20-
} else if let transaction = try? value.decode(EncodableTransaction.self) {
20+
} else if let transaction = try? value.decode(CodableTransaction.self) {
2121
self = .transaction(transaction)
2222
} else {
2323
self = .null

Sources/Core/Transaction/EncodableTransaction.swift renamed to Sources/Core/Transaction/CodableTransaction.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import BigInt
1010
/// Structure capable of carying the parameters for any transaction type.
1111
/// while all fields in this struct are optional, they are not necessarily
1212
/// optional for the type of transaction they apply to.
13-
public struct EncodableTransaction {
13+
public struct CodableTransaction {
1414
/// internal acccess only. The transaction envelope object itself that contains all the transaction data
1515
/// and type specific implementation
1616
internal var envelope: AbstractEnvelope
@@ -170,7 +170,7 @@ public struct EncodableTransaction {
170170
// self.envelope = newEnvelope
171171
}
172172

173-
/// Create a new EncodableTransaction from a raw stream of bytes from the blockchain
173+
/// Create a new CodableTransaction from a raw stream of bytes from the blockchain
174174
public init?(rawValue: Data) {
175175
guard let env = EnvelopeFactory.createEnvelope(rawValue: rawValue) else { return nil }
176176
self.envelope = env
@@ -197,10 +197,10 @@ public struct EncodableTransaction {
197197
self.accessList = options.accessList
198198
}
199199

200-
public static var emptyTransaction = EncodableTransaction(to: EthereumAddress("0xa64f2fD4F60cEBE072997010cB0cb22695FDdCc5")!)
200+
public static var emptyTransaction = CodableTransaction(to: EthereumAddress("0xa64f2fD4F60cEBE072997010cB0cb22695FDdCc5")!)
201201
}
202202

203-
extension EncodableTransaction: Codable {
203+
extension CodableTransaction: Codable {
204204
enum CodingKeys: String, CodingKey {
205205
case type
206206
case from
@@ -273,7 +273,7 @@ extension EncodableTransaction: Codable {
273273

274274
}
275275

276-
extension EncodableTransaction: CustomStringConvertible {
276+
extension CodableTransaction: CustomStringConvertible {
277277
/// required by CustomString convertable
278278
/// returns a string description for the transaction and its data
279279
public var description: String {
@@ -286,9 +286,9 @@ extension EncodableTransaction: CustomStringConvertible {
286286
}
287287
}
288288

289-
extension EncodableTransaction {
289+
extension CodableTransaction {
290290
// the kitchen sink init: can produce a transaction of any type
291-
/// Universal initializer to create a new EncodableTransaction object
291+
/// Universal initializer to create a new CodableTransaction object
292292
/// - Parameters:
293293
/// - type: TransactionType enum for selecting the type of transaction to create (default is .legacy)
294294
/// - to: EthereumAddress of the destination for this transaction (required)
@@ -314,4 +314,4 @@ extension EncodableTransaction {
314314
}
315315
}
316316

317-
extension EncodableTransaction: APIRequestParameterType { }
317+
extension CodableTransaction: APIRequestParameterType { }

Sources/Core/Transaction/Envelope/AbstractEnvelope.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import BigInt
1818
Adding a new transaction type in the future should be as straight forward as adding to the TransactionType enum here
1919
then creating a new struct that implements to `EIP2718Envelope`, and implementing the required elements for the type
2020
Finally adding the type specific inits to the factory routines in `EnvelopeFactory` so that objectts of the new type
21-
will get generated when `EncodableTransaction` is being created with data for the new type
21+
will get generated when `CodableTransaction` is being created with data for the new type
2222
*/
2323

2424
/// Enumeration for supported transaction types
@@ -60,7 +60,7 @@ public enum EncodeType {
6060
}
6161

6262
/// Protocol definition for all transaction envelope types
63-
/// All envelopes must conform to this protocol to work with `EncodableTransaction`
63+
/// All envelopes must conform to this protocol to work with `CodableTransaction`
6464
/// each implememtation holds all the type specific data
6565
/// and implments the type specific encoding/decoding
6666
public protocol AbstractEnvelope: CustomStringConvertible { // possibly add Codable?
@@ -105,16 +105,16 @@ public protocol AbstractEnvelope: CustomStringConvertible { // possibly add Coda
105105

106106
// required initializers
107107
// for Decodable support
108-
/// initializer for creating an `EncodableTransaction` with the Decodable protocol
109-
/// will return an new `EncodableTransaction` object on success
108+
/// initializer for creating an `CodableTransaction` with the Decodable protocol
109+
/// will return an new `CodableTransaction` object on success
110110
/// thows a `Web3.dataError` if an error occurs while trying to decode a value
111111
/// returns nil if a required field is not found in the decoder stream
112112
init?(from decoder: Decoder) throws // Decodable Protocol
113113

114114
// initializes from a raw stream of bytes
115115
// can fail if input stream is not of the right size/cannot be decoded
116-
/// initializer for creating an `EncodableTransaction` with raw bytestream data
117-
/// will return an new `EncodableTransaction` object on success
116+
/// initializer for creating an `CodableTransaction` with raw bytestream data
117+
/// will return an new `CodableTransaction` object on success
118118
/// returns nil if a required field is not found in the decoder stream, or can't be decoded
119119
init?(rawValue: Data) // Decode from Ethereum Data
120120

0 commit comments

Comments
 (0)