Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created April 8, 2018 16:50
Show Gist options
  • Save azamsharp/9ef504cd8af45c62dcf5fbec0390c04d to your computer and use it in GitHub Desktop.
Save azamsharp/9ef504cd8af45c62dcf5fbec0390c04d to your computer and use it in GitHub Desktop.
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 {
get {
let transactionsData = try! JSONEncoder().encode(self.transactions)
let transactionsJSONString = String(data: transactionsData, encoding: .utf8)
return String(self.index) + self.previousHash + String(self.nonce) + transactionsJSONString!
}
}
func addTransaction(transaction :Transaction) {
self.transactions.append(transaction)
}
init() {
self.nonce = 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment