Skip to content

Instantly share code, notes, and snippets.

View azamsharp's full-sized avatar

Mohammad Azam azamsharp

View GitHub Profile
protocol SmartContract {
func apply(to transaction :Transaction)
}
class MaximumAmountTransferFundsContract : SmartContract {
func apply(to transaction: Transaction) {
if transaction.amount > 5000 {
transaction.addBrokenRule(BrokenRule(contractName: "MaximumAmountTransferFundsContract", message: "Your amount is more than $5000"))
}
}
}
struct BrokenRule : Codable {
var contractName :String
var message :String
}
class Transaction : Codable {
var from :String
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)
}
class InternationalDomesticTransferFeesContract : SmartContract {
func apply(to transaction: Transaction) {
switch transaction.transactionType {
case .international:
transaction.fees = 10
case .domestic:
transaction.fees = 2
}
class Blockchain {
private (set) var blocks :[Block] = [Block]()
private (set) var contracts :[SmartContract] = [SmartContract]()
init() {
// initialize contracts
initializeContracts()
}
//: Playground - noun: a place where people can play
import Cocoa
import Foundation
struct BrokenRule : Codable {
var contractName :String
var message :String
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)
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')
class Transaction {
constructor(from,to,amount) {
this.from = from
this.to = to
this.amount = amount
}
}