Skip to content

Commit 5b720e5

Browse files
committed
Merge branch 'develop' into feature/add-bip-44
2 parents 8af8fa5 + 50d0d83 commit 5b720e5

34 files changed

+848
-1315
lines changed

Example/myWeb3Wallet/Podfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment the next line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
platform :ios, '15.0'
33

44
target 'myWeb3Wallet' do
55
# Comment the next line if you don't want to use dynamic frameworks
@@ -19,3 +19,12 @@ pod 'web3swift', :git => 'https://github.com/veerChauhan/web3swift.git', :branch
1919
end
2020

2121
end
22+
23+
# set iOS deployment target for every pod to avoid warnings
24+
post_install do |installer|
25+
installer.pods_project.targets.each do |target|
26+
target.build_configurations.each do |config|
27+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
28+
end
29+
end
30+
end

Example/myWeb3Wallet/myWeb3Wallet.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@
754754
isa = XCBuildConfiguration;
755755
baseConfigurationReference = D6018FABA256C0117F85A829 /* Pods-myWeb3Wallet-myWeb3WalletUITests.debug.xcconfig */;
756756
buildSettings = {
757-
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
757+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
758758
CODE_SIGN_STYLE = Automatic;
759759
CURRENT_PROJECT_VERSION = 1;
760760
DEVELOPMENT_TEAM = VPS9LBWQ55;
@@ -778,7 +778,7 @@
778778
isa = XCBuildConfiguration;
779779
baseConfigurationReference = 7574A738941D92CC94F93A9E /* Pods-myWeb3Wallet-myWeb3WalletUITests.release.xcconfig */;
780780
buildSettings = {
781-
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
781+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
782782
CODE_SIGN_STYLE = Automatic;
783783
CURRENT_PROJECT_VERSION = 1;
784784
DEVELOPMENT_TEAM = VPS9LBWQ55;

Sources/Web3Core/RLP/RLP.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ public struct RLP {
113113
}
114114

115115
// FIXME: Make encode generic to avoid casting it's argument to [AnyObject]
116-
internal static func encode(_ elements: [AnyObject]) -> Data? {
116+
internal static func encode(_ elements: [Any?]) -> Data? {
117117
var encodedData = Data()
118118
for e in elements {
119-
if let encoded = encode(e) {
119+
if let encoded = encode(e as AnyObject) {
120120
encodedData.append(encoded)
121121
} else {
122122
guard let asArray = e as? [AnyObject] else {return nil}

Sources/Web3Core/Structure/Transaction/TransactionReceipt.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ public struct TransactionReceipt {
1616
public var contractAddress: EthereumAddress?
1717
public var cumulativeGasUsed: BigUInt
1818
public var gasUsed: BigUInt
19+
public var effectiveGasPrice: BigUInt
1920
public var logs: [EventLog]
2021
public var status: TXStatus
2122
public var logsBloom: EthereumBloomFilter?
2223

2324
static func notProcessed(transactionHash: Data) -> TransactionReceipt {
24-
TransactionReceipt(transactionHash: transactionHash, blockHash: Data(), blockNumber: BigUInt(0), transactionIndex: BigUInt(0), contractAddress: nil, cumulativeGasUsed: BigUInt(0), gasUsed: BigUInt(0), logs: [EventLog](), status: .notYetProcessed, logsBloom: nil)
25+
TransactionReceipt(transactionHash: transactionHash, blockHash: Data(), blockNumber: 0, transactionIndex: 0, contractAddress: nil, cumulativeGasUsed: 0, gasUsed: 0, effectiveGasPrice: 0, logs: [], status: .notYetProcessed, logsBloom: nil)
2526
}
2627
}
2728

@@ -45,6 +46,7 @@ extension TransactionReceipt: Decodable {
4546
case logs
4647
case logsBloom
4748
case status
49+
case effectiveGasPrice
4850
}
4951

5052
public init(from decoder: Decoder) throws {
@@ -64,6 +66,8 @@ extension TransactionReceipt: Decodable {
6466

6567
self.gasUsed = try container.decodeHex(BigUInt.self, forKey: .gasUsed)
6668

69+
self.effectiveGasPrice = (try? container.decodeHex(BigUInt.self, forKey: .effectiveGasPrice)) ?? 0
70+
6771
let status = try? container.decodeHex(BigUInt.self, forKey: .status)
6872
switch status {
6973
case nil: self.status = .notYetProcessed
@@ -72,6 +76,10 @@ extension TransactionReceipt: Decodable {
7276
}
7377

7478
self.logs = try container.decode([EventLog].self, forKey: .logs)
79+
80+
if let hexBytes = try? container.decodeHex(Data.self, forKey: .logsBloom) {
81+
self.logsBloom = EthereumBloomFilter(hexBytes)
82+
}
7583
}
7684
}
7785

Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ extension EIP1559Envelope {
245245
// }
246246

247247
public func encode(for type: EncodeType = .transaction) -> Data? {
248-
let fields: [AnyObject]
248+
let fields: [Any?]
249249
let list = accessList.map { $0.encodeAsList() as AnyObject }
250250

251251
switch type {
252252
case .transaction:
253-
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
253+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s]
254254
case .signature:
255-
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list] as [AnyObject]
255+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list]
256256
}
257257
guard var result = RLP.encode(fields) else { return nil }
258258
result.insert(UInt8(self.type.rawValue), at: 0)

Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ extension EIP2930Envelope {
206206
}
207207

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

212212
switch type {
213213
case .transaction:
214-
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
214+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s]
215215
case .signature:
216-
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list] as [AnyObject]
216+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list]
217217
}
218218
guard var result = RLP.encode(fields) else { return nil }
219219
result.insert(UInt8(self.type.rawValue), at: 0)

Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ extension LegacyEnvelope {
192192
// }
193193

194194
public func encode(for type: EncodeType = .transaction) -> Data? {
195-
let fields: [AnyObject]
195+
let fields: [Any?]
196196
switch type {
197197
case .transaction:
198-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s] as [AnyObject]
198+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s]
199199
case .signature:
200200
if let chainID = chainID, chainID != 0 {
201-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)] as [AnyObject]
201+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)]
202202
} else {
203-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data] as [AnyObject]
203+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data]
204204
}
205205
}
206206
return RLP.encode(fields)

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ 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

7472
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return}
7573

@@ -80,34 +78,25 @@ 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-
87-
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject] )!
81+
updateTransactionAndContract(from: from)
82+
let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject])!
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
97-
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject] )!
89+
.createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject])!
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] as [AnyObject], extraData: Data() )!
95+
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
10696
.callContractMethod()
107-
10897
/*
10998
let result = try await contract
110-
.prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
99+
.prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
111100
.execute()
112101
.decodeData()
113102

@@ -117,27 +106,32 @@ public class ERC1155: IERC1155 {
117106
}
118107

119108
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-
124-
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject] )!
109+
updateTransactionAndContract(from: from)
110+
let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject])!
125111
return tx
126112
}
127113

128114
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] as [AnyObject], extraData: Data() )!.callContractMethod()
115+
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data())!.callContractMethod()
132116
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
133117
return res
134118
}
135119

136120
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] as [AnyObject], extraData: Data() )!.callContractMethod()
121+
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod()
140122
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
141123
return res
142124
}
143125
}
126+
127+
// MARK: - Private
128+
129+
extension ERC1155 {
130+
131+
private func updateTransactionAndContract(from: EthereumAddress) {
132+
transaction.from = from
133+
transaction.to = address
134+
contract.transaction = transaction
135+
}
136+
137+
}

0 commit comments

Comments
 (0)