src/main/Wallet.java
public Transaction sendFunds(PublicKey recipient, float value){
		if(getBalance() < value){
			System.out.println("Wallet: Not enough funds! Value: " + value + ", Current Balance: " + balance);
			return null;
		}

		ArrayList<TransactionInput> inputs = new ArrayList<TransactionInput>();
		
		float total = 0;
		for (Map.Entry<String, TransactionOutput> item: walletUTXOs.entrySet()){
			TransactionOutput UTXO = item.getValue();

			if(UTXO.value >= value){
				inputs.add(new TransactionInput(UTXO.id, UTXO.value));
				break;
			}else{
				total += UTXO.value;
				//System.out.println("UTXO value: " + UTXO.value);
				inputs.add(new TransactionInput(UTXO.id, UTXO.value));
				if(total > value) break;
			}
		}
	
		Transaction tx = new Transaction(publicKey, recipient, value, inputs, currentBlockchain);
		tx.outputs.add(new TransactionOutput(tx.reciepient, tx.value, tx.transactionId));
		tx.generateSignature(privateKey);

		updateBalance();

		for(TransactionInput input: inputs){
			walletUTXOs.remove(input.previousOutId);
		}
		updateNode(tx);
		return tx;
	}
// Checks to make sure the wallet has the sufficient funds to send the coins first
Checks to make sure the wallet has the sufficient funds to send the coins first
Checks to make sure the wallet has the sufficient funds to send the coins first
public Transaction sendFunds(PublicKey recipient, float value){
		if(getBalance() < value){
			System.out.println("Wallet: Not enough funds! Value: " + value + ", Current Balance: " + balance);
			return null;
		}
		ArrayList<TransactionInput> inputs = new ArrayList<TransactionInput>();
		float total = 0;
		for (Map.Entry<String, TransactionOutput> item: walletUTXOs.entrySet()){
			TransactionOutput UTXO = item.getValue();
			if(UTXO.value >= value){
				inputs.add(new TransactionInput(UTXO.id, UTXO.value));
				break;
			}else{
				total += UTXO.value;
				inputs.add(new TransactionInput(UTXO.id, UTXO.value));
				if(total > value) break;
			}
		}
		Transaction tx = new Transaction(publicKey, recipient, value, inputs, currentBlockchain);
		tx.outputs.add(new TransactionOutput(tx.reciepient, tx.value, tx.transactionId));
		tx.generateSignature(privateKey);
		updateBalance();
		for(TransactionInput input: inputs){
			walletUTXOs.remove(input.previousOutId);
		}
		updateNode(tx);
		return tx;
	}
public Transaction sendFunds ( PublicKey recipient , float value ) { if ( getBalance ( ) < value ) { System . out . println ( "Wallet: Not enough funds! Value: " + value + ", Current Balance: " + balance ) ; return null ; } ArrayList < TransactionInput > inputs = new ArrayList < TransactionInput > ( ) ; float total = 0 ; for ( Map . Entry < String , TransactionOutput > item : walletUTXOs . entrySet ( ) ) { TransactionOutput UTXO = item . getValue ( ) ; if ( UTXO . value >= value ) { inputs . add ( new TransactionInput ( UTXO . id , UTXO . value ) ) ; break ; } else { total += UTXO . value ; inputs . add ( new TransactionInput ( UTXO . id , UTXO . value ) ) ; if ( total > value ) break ; } } Transaction tx = new Transaction ( publicKey , recipient , value , inputs , currentBlockchain ) ; tx . outputs . add ( new TransactionOutput ( tx . reciepient , tx . value , tx . transactionId ) ) ; tx . generateSignature ( privateKey ) ; updateBalance ( ) ; for ( TransactionInput input : inputs ) { walletUTXOs . remove ( input . previousOutId ) ; } updateNode ( tx ) ; return tx ; }
Checks to make sure the wallet has the sufficient funds to send the coins first
Checks to make sure the wallet has the sufficient funds to send the coins first
//System.out.println("UTXO value: " + UTXO.value);