src/main/Node.java
public void floodTransaction(Transaction tx){
        // Perform checks
        if(!isTransactionOnBlockchain(tx)){
            if(!areOutputsSpent(tx)){
                if(!isTransactionAlreadySeen(tx)){
                    // Add to this nodes transactions
                    allTransactions.add(tx);

                    // If enough transaction are present to mine a block do so
                    if(allTransactions.size() == BLOCK_SIZE){
                        // Create a new block using the hash from the last block on the current blockchain
                        Block blockToAdd = new Block(currentBlockchain.blockChain.get(currentBlockchain.blockChain.size()-1).hash);

                        // For each transaction this node has seen, add it to the block
                        for (Transaction transaction : allTransactions) {
                            blockToAdd.addTransaction(transaction);
                        }
                        

                        // Mine the block and add it to the current blockchain
                        if (blockToAdd.mineBlock(Blockchain.DIFFICULTY)){
                            currentBlockchain.blockChain.add(blockToAdd);
                        }
                        
                        // Remove transactions in block from other nodes transaction list
                        for(Iterator<Transaction> iterator = allTransactions.iterator();iterator.hasNext();){
                            Transaction t = iterator.next();
                            iterator.remove();
                        }
                        
                            
                    }

                    // Relay to other nodes
                    for (Node node : nearbyNodes) {
                        node.floodTransaction(tx);
                    }
                }
            }
        }
    }
// When transaction is recieved from wallet, send to nearbyNodes
When transaction is recieved from wallet, send to nearbyNodes
When transaction is recieved from wallet send to nearbyNodes
public void floodTransaction(Transaction tx){
        if(!isTransactionOnBlockchain(tx)){
            if(!areOutputsSpent(tx)){
                if(!isTransactionAlreadySeen(tx)){
                    allTransactions.add(tx);
                    if(allTransactions.size() == BLOCK_SIZE){
                        Block blockToAdd = new Block(currentBlockchain.blockChain.get(currentBlockchain.blockChain.size()-1).hash);
                        for (Transaction transaction : allTransactions) {
                            blockToAdd.addTransaction(transaction);
                        }
                        if (blockToAdd.mineBlock(Blockchain.DIFFICULTY)){
                            currentBlockchain.blockChain.add(blockToAdd);
                        }
                        for(Iterator<Transaction> iterator = allTransactions.iterator();iterator.hasNext();){
                            Transaction t = iterator.next();
                            iterator.remove();
                        }
                    }
                    for (Node node : nearbyNodes) {
                        node.floodTransaction(tx);
                    }
                }
            }
        }
    }
public void floodTransaction ( Transaction tx ) { if ( ! isTransactionOnBlockchain ( tx ) ) { if ( ! areOutputsSpent ( tx ) ) { if ( ! isTransactionAlreadySeen ( tx ) ) { allTransactions . add ( tx ) ; if ( allTransactions . size ( ) == BLOCK_SIZE ) { Block blockToAdd = new Block ( currentBlockchain . blockChain . get ( currentBlockchain . blockChain . size ( ) - 1 ) . hash ) ; for ( Transaction transaction : allTransactions ) { blockToAdd . addTransaction ( transaction ) ; } if ( blockToAdd . mineBlock ( Blockchain . DIFFICULTY ) ) { currentBlockchain . blockChain . add ( blockToAdd ) ; } for ( Iterator < Transaction > iterator = allTransactions . iterator ( ) ; iterator . hasNext ( ) ; ) { Transaction t = iterator . next ( ) ; iterator . remove ( ) ; } } for ( Node node : nearbyNodes ) { node . floodTransaction ( tx ) ; } } } } }
When transaction is recieved from wallet, send to nearbyNodes
When transaction is recieved from wallet send to nearbyNodes
// Perform checks // Add to this nodes transactions // If enough transaction are present to mine a block do so // Create a new block using the hash from the last block on the current blockchain // For each transaction this node has seen, add it to the block // Mine the block and add it to the current blockchain // Remove transactions in block from other nodes transaction list // Relay to other nodes