This file contains hidden or 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
| let btn = UIButton.buttonForAddingAnnotation() |
This file contains hidden or 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
| extension UIView { | |
| func addToParent(view :UIView) -> UIView { | |
| view.addSubview(self) | |
| return self | |
| } | |
| func bottomMargin(from view: UIView, margin :CGFloat) -> UIView { | |
| self.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: margin).isActive = true |
This file contains hidden or 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
| let addFloodButton = UIButton.buttonForAddingAnnotation() | |
| .addToParent(view: self.view) | |
| .centerX(in: self.view) | |
| .bottomMargin(from: self.view, margin: -40) | |
| .setWidth(width: 75) | |
| .setHeight(height: 75) as! UIButton | |
| addFloodButton.addTarget(self, action: #selector(addFloodAnnotationButtonPressed), for: .touchUpInside) |
This file contains hidden or 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
| @objc func tapped(recognizer :UIGestureRecognizer) { | |
| guard let currentFrame = self.sceneView.session.currentFrame else { | |
| return | |
| } | |
| // create a web view | |
| let webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 640, height: 480)) | |
| let request = URLRequest(url: URL(string: "http://www.amazon.com")!) |
This file contains hidden or 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
| class Transaction : Codable { | |
| var driverLicenseNumber :String | |
| var voilationType :String | |
| var noOfVoilations :Int = 1 | |
| var isDrivingLicenseSuspended :Bool = false | |
| init(licenseNoHash :String, voilationType :String) { | |
| self.driverLicenseNumber = licenseNoHash | |
| self.voilationType = voilationType |
This file contains hidden or 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
| class Block : Codable { | |
| var index :Int = 0 | |
| var previousHash :String = "" | |
| var hash :String! | |
| var nonce :Int | |
| private (set) var transactions :[Transaction] = [Transaction]() | |
| var key :String { |
This file contains hidden or 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
| class Blockchain : Codable { | |
| var blocks :[Block] = [Block]() | |
| init(genesisBlock :Block) { | |
| addBlock(genesisBlock) | |
| } | |
This file contains hidden or 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
| self.drop.get("blockchain") { request in | |
| let blockchain = self.blockchainService.getBlockchain() | |
| return try! JSONEncoder().encode(blockchain) | |
| } |
This file contains hidden or 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
| class DrivingRecordSmartContract : Codable { | |
| func apply(transaction :Transaction, allBlocks :[Block]) { | |
| allBlocks.forEach { block in | |
| block.transactions.forEach { trans in | |
| if trans.driverLicenseNumber == transaction.driverLicenseNumber { | |
| transaction.noOfVoilations += 1 |
This file contains hidden or 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
| class DrivingRecordSmartContract : Codable { | |
| func apply(transaction :Transaction, allBlocks :[Block]) { | |
| allBlocks.forEach { block in | |
| block.transactions.forEach { trans in | |
| if trans.driverLicenseNumber == transaction.driverLicenseNumber { | |
| transaction.noOfVoilations += 1 |