Skip to content

Commit 093218c

Browse files
Merge branch 'develop-upstream' into fix/anyobject-usage-removed
# Conflicts: # Sources/Web3Core/RLP/RLP.swift # Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift # Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift # Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift # Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift # Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift # Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift # Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift # Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift # Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift # Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift # Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift # Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift # Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift # Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift # Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift # Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift # Sources/web3swift/Tokens/ST20/Web3+ST20.swift # Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift # Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift # Sources/web3swift/Utils/ENS/ENSRegistry.swift # Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift # Sources/web3swift/Utils/ENS/ETHRegistrarController.swift
2 parents 6534980 + 496a9fd commit 093218c

29 files changed

+1044
-1440
lines changed

Sources/Web3Core/RLP/RLP.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct RLP {
1818
static var length56 = BigUInt(UInt(56))
1919
static var lengthMax = (BigUInt(UInt(1)) << 256)
2020

21-
internal static func encode(_ element: Any) -> Data? {
21+
internal static func encode(_ element: Any?) -> Data? {
2222
if let string = element as? String {
2323
return encode(string)
2424

@@ -112,8 +112,7 @@ public struct RLP {
112112
return encoded.bytes[0]
113113
}
114114

115-
// FIXME: Make encode generic to avoid casting it's argument to [Any]
116-
internal static func encode(_ elements: [Any]) -> Data? {
115+
internal static func encode(_ elements: [Any?]) -> Data? {
117116
var encodedData = Data()
118117
for e in elements {
119118
if let encoded = encode(e) {

Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,8 @@ extension EIP1559Envelope {
245245
// }
246246

247247
public func encode(for type: EncodeType = .transaction) -> Data? {
248-
let fields: [Any]
248+
let fields: [Any?]
249249
let list = accessList.map { $0.encodeAsList() }
250-
251250
switch type {
252251
case .transaction:
253252
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s]

Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ extension EIP2930Envelope {
206206
}
207207

208208
public func encode(for type: EncodeType = .transaction) -> Data? {
209-
let fields: [Any]
209+
let fields: [Any?]
210210
let list = accessList.map { $0.encodeAsList() }
211211

212212
switch type {

Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extension LegacyEnvelope {
192192
// }
193193

194194
public func encode(for type: EncodeType = .transaction) -> Data? {
195-
let fields: [Any]
195+
let fields: [Any?]
196196
switch type {
197197
case .transaction:
198198
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s]

Sources/Web3Core/Web3Error/Web3Error.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public enum Web3Error: LocalizedError {
2727

2828
public var errorDescription: String? {
2929
switch self {
30-
3130
case .transactionSerializationError:
3231
return "Transaction Serialization Error"
3332
case .connectionError:

Sources/web3swift/Operations/ReadOperation.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class ReadOperation {
3636

3737
// TODO: Remove type erasing here, some broad wide protocol should be added instead
3838
public func callContractMethod() async throws -> [String: Any] {
39-
4039
// MARK: Read data from ABI flow
4140
// FIXME: This should be dropped, and after `execute()` call, just to decode raw data.
4241
let data: Data = try await self.web3.eth.callTransaction(transaction)

Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ public class ERC1155: IERC1155 {
6767
if self._hasReadProperties {
6868
return
6969
}
70-
let contract = self.contract
7170
guard contract.contract.address != nil else {return}
72-
self.transaction.callOnBlock = .latest
7371

74-
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [], extraData: Data())?.callContractMethod() else {return}
72+
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [])?.callContractMethod() else {return}
7573

7674
guard let tokenId = tokenIdPromise["0"] as? BigUInt else {return}
7775
self._tokenId = tokenId
@@ -80,64 +78,55 @@ public class ERC1155: IERC1155 {
8078
}
8179

8280
public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, id: BigUInt, value: BigUInt, data: [UInt8]) throws -> WriteOperation {
83-
let contract = self.contract
84-
self.transaction.from = from
85-
self.transaction.to = self.address
86-
81+
updateTransactionAndContract(from: from)
8782
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data])!
8883
return tx
8984
}
9085

9186
public func safeBatchTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, ids: [BigUInt], values: [BigUInt], data: [UInt8]) throws -> WriteOperation {
92-
let contract = self.contract
93-
self.transaction.from = from
94-
self.transaction.to = self.address
95-
87+
updateTransactionAndContract(from: from)
9688
let tx = contract
9789
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data])!
9890
return tx
9991
}
10092

10193
public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt {
102-
let contract = self.contract
103-
self.transaction.callOnBlock = .latest
10494
let result = try await contract
105-
.createReadOperation("balanceOf", parameters: [account, id], extraData: Data() )!
95+
.createReadOperation("balanceOf", parameters: [account, id])!
10696
.callContractMethod()
107-
108-
/*
109-
let result = try await contract
110-
.prepareToRead("balanceOf", parameters: [account, id], extraData: Data() )!
111-
.execute()
112-
.decodeData()
113-
114-
*/
11597
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
11698
return res
11799
}
118100

119101
public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool, scope: Data) throws -> WriteOperation {
120-
let contract = self.contract
121-
self.transaction.from = from
122-
self.transaction.to = self.address
123-
102+
updateTransactionAndContract(from: from)
124103
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope])!
125104
return tx
126105
}
127106

128107
public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool {
129-
let contract = self.contract
130-
self.transaction.callOnBlock = .latest
131-
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope], extraData: Data() )!.callContractMethod()
108+
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope])!.callContractMethod()
109+
132110
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
133111
return res
134112
}
135113

136114
public func supportsInterface(interfaceID: String) async throws -> Bool {
137-
let contract = self.contract
138-
self.transaction.callOnBlock = .latest
139-
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID], extraData: Data() )!.callContractMethod()
115+
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID])!.callContractMethod()
116+
140117
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
141118
return res
142119
}
143120
}
121+
122+
// MARK: - Private
123+
124+
extension ERC1155 {
125+
126+
private func updateTransactionAndContract(from: EthereumAddress) {
127+
transaction.from = from
128+
transaction.to = address
129+
contract.transaction = transaction
130+
}
131+
132+
}

0 commit comments

Comments
 (0)