Skip to content

Commit

Permalink
fix: fixing cast error
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Mar 5, 2024
1 parent a9e5559 commit 288e221
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Sources/EOSIO/ABIDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,18 @@ public extension ABIDecoder {
case is Int.Type:
return Int(try self.readVarint()) as! T
case is UInt.Type:
return UInt(try self.readVaruint()) as! T
return UInt(try self.readVaruint()) as! T
case let abiType as ABIDecodable.Type:
return try abiType.init(fromAbi: self) as! T
let decodedAbiType = try abiType.init(fromAbi: self)

// Instead of forcefully casting, verify the type at runtime.
if let result = decodedAbiType as? T {
return result
} else {
// As a temporary solution, we'll just return an empty array whenever a non supported type is found.
// This is not ideal, but it's better than crashing the app.
return [] as! T
}
default:
throw Error.typeNotConformingToABIDecodable(type)
}
Expand Down

0 comments on commit 288e221

Please sign in to comment.