-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from soramitsu/FLW-1725-CEX-accounts-QR-codes
Cex qr decoder
- Loading branch information
Showing
6 changed files
with
67 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
public protocol CexQRDecodable: QRDecodable {} | ||
|
||
public struct CexQRInfo: QRInfo, Equatable { | ||
public let address: String | ||
|
||
public init(address: String) { | ||
self.address = address | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
|
||
public class CexQRDecoder: CexQRDecodable { | ||
|
||
public init() {} | ||
|
||
public func decode(data: Data) throws -> QRInfo { | ||
guard let address = String(data: data, encoding: .utf8) else { | ||
throw QRDecoderError.brokenFormat | ||
} | ||
|
||
return CexQRInfo(address: address) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
|
||
public protocol QRInfo { | ||
var address: String { get } | ||
} | ||
|
||
public protocol QRDecodable { | ||
func decode(data: Data) throws -> QRInfo | ||
} | ||
|
||
public protocol QREncodable { | ||
func encode(info: SubstrateQRInfo) throws -> Data | ||
} | ||
|
||
public enum QREncoderError: Error, Equatable { | ||
case brokenData | ||
} | ||
|
||
public enum QRDecoderError: Error, Equatable { | ||
case brokenFormat | ||
case unexpectedNumberOfFields | ||
case undefinedPrefix | ||
case accountIdMismatch | ||
case wrongDecoder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters