UIButton Action for each new Swift Blockchain SmartContract sender into TableView column

Viewed 26

In basic words, I'm working on a educative blockchain app where a SmartContract is created with simple info like "Provider" "Destinator" and "Amount", which is needed to be sent with total transparency on the backend which I was able to insert in a small window. I want each transaction detail to to appear in a new TableView ViewController in a new column for each transaction with Provider Destinator and Amount, and have a description of the transaction code by clicking on the transaction in each column.

I was able to create a onTapButton, to create a new transaction and hash it in SHA256, and output it as JSON. Now what I'm trying to do is just send the transaction info in each column, I'm still scratching my head on how to do that. Here is some of the source code without going into too much details:

Transaction (App.swift)

class Transaction : Codable {
    
    var from: String
    var to: String
    var amount: Double
}

JSON Encoder (App.swift)

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!
    }
}

onTapButton (ViewController.swift)

@IBAction func onTapSendButton(_ sender: UIButton) {
        
    self.generateDummyTransactions()
    let str:String = "Mary"
    self.providerForm.text = str
    let str2:String = "Bob"
    self.destinatorForm.text = str2
    //let int:Double = 20.0
    //self.amountSum = int   
}

print function (ViewController.swift)

func generateDummyTransactions() {
            
    _ = self.providerForm
    _ = self.destinatorForm
    _ = self.amountSum
            
    let transaction = Transaction(from: "Mary", to: "Bob", amount: 20, transactionType: TransactionType.domestic)
    let block1 = Block()
    block1.addTransaction(transaction: transaction)
            
    let transaction2 = Transaction(from: "Phil", to: "Gab", amount: 10.0, transactionType: .domestic)
    block1.addTransaction(transaction: transaction2)
    print("------------------------------------------------------")
    let block = blockchain.getNextBlock(transactions: [transaction])
    blockchain.addBlock(block)
            
    // print(blockchain.blocks.count)
    let data = try! JSONEncoder().encode(blockchain)
    let blockchainJSON = String(data : data, encoding: .utf8)
            
    print(blockchainJSON!)
            
    realTimeTextOutput.text = blockchainJSON
}

Here is how I want it to look in the second ViewController for the TableView:

enter image description here

And here is the App plan we are looking at:

enter image description here

I hope it was descriptive enough between the code and photos

0 Answers
Related