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
protocol SmartContract { | |
func apply(to transaction :Transaction) | |
} |
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 MaximumAmountTransferFundsContract : SmartContract { | |
func apply(to transaction: Transaction) { | |
if transaction.amount > 5000 { | |
transaction.addBrokenRule(BrokenRule(contractName: "MaximumAmountTransferFundsContract", message: "Your amount is more than $5000")) | |
} | |
} | |
} |
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
struct BrokenRule : Codable { | |
var contractName :String | |
var message :String | |
} | |
class Transaction : Codable { | |
var from :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
func addTransaction(transaction :Transaction, contracts :[SmartContract] = [SmartContract]()) { | |
// run the smart contracts | |
contracts.forEach { contract in | |
contract.apply(to: transaction) | |
} | |
if transaction.isValid { | |
self.transactions.append(transaction) | |
} |
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 InternationalDomesticTransferFeesContract : SmartContract { | |
func apply(to transaction: Transaction) { | |
switch transaction.transactionType { | |
case .international: | |
transaction.fees = 10 | |
case .domestic: | |
transaction.fees = 2 | |
} |
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 { | |
private (set) var blocks :[Block] = [Block]() | |
private (set) var contracts :[SmartContract] = [SmartContract]() | |
init() { | |
// initialize contracts | |
initializeContracts() | |
} |
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
//: Playground - noun: a place where people can play | |
import Cocoa | |
import Foundation | |
struct BrokenRule : Codable { | |
var contractName :String | |
var message :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
In this assignment you are going to perform the following SQL scenarioes. Create two tables with the following schema: | |
Shopping List | |
shopping_list_id: Auto increment , not null, unique, primary key | |
name: Name of the shopping list. Max (50) | |
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
var express = require('express') | |
var session = require('express-session') | |
const mustacheExpress = require('mustache-express') | |
const bodyParser = require('body-parser') | |
var app = express() | |
app.engine('mustache',mustacheExpress()) | |
app.use(bodyParser.urlencoded({extended :true})) | |
app.set('views','./views') |
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 { | |
constructor(from,to,amount) { | |
this.from = from | |
this.to = to | |
this.amount = amount | |
} | |
} |