Merge pull request #548 from James-Sangalli/safer-check-for-ticket-byte32-0

Make check for byte32 ticket value against 0, safer
pull/556/head
James Sangalli 6 years ago committed by GitHub
commit 454d44526c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift
  2. 4
      AlphaWallet/Tokens/Helpers/TokenAdaptor.swift
  3. 6
      AlphaWallet/Tokens/Types/TokenObject.swift

@ -230,7 +230,7 @@ class UniversalLinkCoordinator: Coordinator {
for i in 0..<indices.count {
let token: String = balance[Int(indices[i])]
//all of the indices provided should map to a valid non null ticket
if token == Constants.nullTicket {
if isZeroBalance(token) {
//if null ticket at any index then the deal cannot happen
return [String]()
}

@ -22,9 +22,7 @@ class TokenAdaptor {
for (index, item) in balance.enumerated() {
//id is the value of the bytes32 ticket
let id = item.balance
if id == Constants.nullTicket { // if balance is 0, then skip
continue
}
guard isNonZeroBalance(id) else { continue }
if let ticketInt = BigUInt(id.drop0x, radix: 16) {
let ticket = getTicket(for: ticketInt, index: UInt16(index), in: token)
tickets.append(ticket)

@ -85,5 +85,9 @@ class TokenObject: Object {
}
func isNonZeroBalance(_ balance: String) -> Bool {
return BigUInt(balance) != 0
return !isZeroBalance(balance)
}
func isZeroBalance(_ balance: String) -> Bool {
return BigUInt(balance) == 0
}

Loading…
Cancel
Save