Skip to content

Commit 884efc1

Browse files
Merge pull request #558 from mloit/hotfix/restore-json-functions
2 parents aecadfe + 9f7181f commit 884efc1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Sources/web3swift/Transaction/EthereumTransaction.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,14 @@ extension EthereumTransaction {
445445
return self.envelope.encode(for: .transaction)
446446
}
447447

448+
@available(*, deprecated, message: "use Decodable instead")
449+
public static func fromJSON(_ json: [String: Any]) -> EthereumTransaction? {
450+
do {
451+
let jsonData: Data = try JSONSerialization.data(withJSONObject: json, options: [])
452+
return try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
453+
} catch {
454+
return nil
455+
}
456+
}
457+
448458
}

Sources/web3swift/Web3/Web3+Options.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,16 @@ extension TransactionOptions: Decodable {
280280
}
281281
}
282282
}
283+
284+
extension TransactionOptions {
285+
@available(*, deprecated, message: "use Decodable instead")
286+
public static func fromJSON(_ json: [String: Any]) -> TransactionOptions? {
287+
do {
288+
let jsonData: Data = try JSONSerialization.data(withJSONObject: json, options: [])
289+
return try JSONDecoder().decode(TransactionOptions.self, from: jsonData)
290+
} catch {
291+
return nil
292+
}
293+
}
294+
295+
}

0 commit comments

Comments
 (0)