public Transaction sendCoins(WalletData perWalletModelData,SendRequest sendRequest,CharSequence password) throws java.io.IOException, AddressFormatException, KeyCrypterException {
  List<Peer> connectedPeers=peerGroup.getConnectedPeers();
  boolean atLeastOnePingWorked=false;
  if (connectedPeers != null) {
    for (    Peer peer : connectedPeers) {
      log.debug("Ping: {}",peer.getAddress().toString());
      try {
        ListenableFuture<Long> result=peer.ping();
        result.get(4,TimeUnit.SECONDS);
        atLeastOnePingWorked=true;
        break;
      }
 catch (      ProtocolException e) {
        log.warn("Peer '" + peer.getAddress().toString() + "' failed ping test. Message was "+ e.getMessage());
      }
catch (      InterruptedException e) {
        log.warn("Peer '" + peer.getAddress().toString() + "' failed ping test. Message was "+ e.getMessage());
      }
catch (      ExecutionException e) {
        log.warn("Peer '" + peer.getAddress().toString() + "' failed ping test. Message was "+ e.getMessage());
      }
catch (      TimeoutException e) {
        log.warn("Peer '" + peer.getAddress().toString() + "' failed ping test. Message was "+ e.getMessage());
      }
    }
  }
  if (!atLeastOnePingWorked) {
    throw new IllegalStateException("All peers failed ping test (check network)");
  }
  log.debug("MultiBitService#sendCoins - Just about to send coins");
  KeyParameter aesKey=null;
  if (perWalletModelData.getWallet().getEncryptionType() != EncryptionType.UNENCRYPTED) {
    aesKey=perWalletModelData.getWallet().getKeyCrypter().deriveKey(password);
  }
  sendRequest.aesKey=aesKey;
  sendRequest.fee=BigInteger.ZERO;
  sendRequest.feePerKb=BitcoinModel.SEND_FEE_PER_KB_DEFAULT;
  sendRequest.tx.getConfidence().addEventListener(perWalletModelData.getWallet().getTxConfidenceListener());
  try {
    perWalletModelData.getWallet().sign(sendRequest);
    perWalletModelData.getWallet().commitTx(sendRequest.tx);
    peerGroup.broadcastTransaction(sendRequest.tx);
    log.debug("Sending transaction '" + Utils.bytesToHexString(sendRequest.tx.bitcoinSerialize()) + "'");
  }
 catch (  VerificationException e1) {
    e1.printStackTrace();
  }
  Transaction sendTransaction=sendRequest.tx;
  log.debug("MultiBitService#sendCoins - Sent coins has completed");
  assert sendTransaction != null;
  if (sendTransaction != null) {
    log.debug("MultiBitService#sendCoins - Sent coins. Transaction hash is {}",sendTransaction.getHashAsString() + ", identityHashcode = " + System.identityHashCode(sendTransaction));
    if (sendTransaction.getConfidence() != null) {
      log.debug("Added bitcoinController " + System.identityHashCode(bitcoinController) + " as listener to tx = "+ sendTransaction.getHashAsString());
      sendTransaction.getConfidence().addEventListener(bitcoinController);
    }
 else {
      log.debug("Cannot add bitcoinController as listener to tx = " + sendTransaction.getHashAsString() + " no transactionConfidence");
    }
    try {
      bitcoinController.getFileHandler().savePerWalletModelData(perWalletModelData,false);
    }
 catch (    WalletSaveException wse) {
      log.error(wse.getClass().getCanonicalName() + " " + wse.getMessage());
      MessageManager.INSTANCE.addMessage(new Message(wse.getClass().getCanonicalName() + " " + wse.getMessage()));
    }
catch (    WalletVersionException wse) {
      log.error(wse.getClass().getCanonicalName() + " " + wse.getMessage());
      MessageManager.INSTANCE.addMessage(new Message(wse.getClass().getCanonicalName() + " " + wse.getMessage()));
    }
    try {
      List<WalletData> perWalletModelDataList=bitcoinController.getModel().getPerWalletModelDataList();
      if (perWalletModelDataList != null) {
        for (        WalletData loopPerWalletModelData : perWalletModelDataList) {
          if (!perWalletModelData.getWalletFilename().equals(loopPerWalletModelData.getWalletFilename())) {
            Wallet loopWallet=loopPerWalletModelData.getWallet();
            if (loopWallet.isPendingTransactionRelevant(sendTransaction)) {
              if (loopPerWalletModelData.getWalletInfo() != null) {
synchronized (loopPerWalletModelData.getWalletInfo()) {
                  loopPerWalletModelData.setDirty(true);
                }
              }
 else {
                loopPerWalletModelData.setDirty(true);
              }
              if (loopWallet.getTransaction(sendTransaction.getHash()) == null) {
                log.debug("MultiBit adding a new pending transaction for the wallet '" + loopPerWalletModelData.getWalletDescription() + "'\n"+ sendTransaction.toString());
                loopWallet.receivePending(sendTransaction,null);
              }
            }
          }
        }
      }
    }
 catch (    ScriptException e) {
      e.printStackTrace();
    }
catch (    VerificationException e) {
      e.printStackTrace();
    }
  }
  return sendTransaction;
}

public Transaction sendCoins ( WalletData perWalletModelData , SendRequest sendRequest , CharSequence password ) throws java . io . IOException , AddressFormatException , KeyCrypterException { List < Peer > connectedPeers = peerGroup . getConnectedPeers ( ) ; boolean atLeastOnePingWorked = false ; if ( connectedPeers != null ) { for ( Peer peer : connectedPeers ) { log . debug ( "Ping: {}" , peer . getAddress ( ) . toString ( ) ) ; try { ListenableFuture < Long > result = peer . ping ( ) ; result . get ( 4 , TimeUnit . SECONDS ) ; atLeastOnePingWorked = true ; break ; } catch ( ProtocolException e ) { log . warn ( "Peer '" + peer . getAddress ( ) . toString ( ) + "' failed ping test. Message was " + e . getMessage ( ) ) ; } catch ( InterruptedException e ) { log . warn ( "Peer '" + peer . getAddress ( ) . toString ( ) + "' failed ping test. Message was " + e . getMessage ( ) ) ; } catch ( ExecutionException e ) { log . warn ( "Peer '" + peer . getAddress ( ) . toString ( ) + "' failed ping test. Message was " + e . getMessage ( ) ) ; } catch ( TimeoutException e ) { log . warn ( "Peer '" + peer . getAddress ( ) . toString ( ) + "' failed ping test. Message was " + e . getMessage ( ) ) ; } } } if ( ! atLeastOnePingWorked ) { throw new IllegalStateException ( "All peers failed ping test (check network)" ) ; } log . debug ( "MultiBitService#sendCoins - Just about to send coins" ) ; KeyParameter aesKey = null ; if ( perWalletModelData . getWallet ( ) . getEncryptionType ( ) != EncryptionType . UNENCRYPTED ) { aesKey = perWalletModelData . getWallet ( ) . getKeyCrypter ( ) . deriveKey ( password ) ; } sendRequest . aesKey = aesKey ; sendRequest . fee = BigInteger . ZERO ; sendRequest . feePerKb = BitcoinModel . SEND_FEE_PER_KB_DEFAULT ; sendRequest . tx . getConfidence ( ) . addEventListener ( perWalletModelData . getWallet ( ) . getTxConfidenceListener ( ) ) ; try { perWalletModelData . getWallet ( ) . sign ( sendRequest ) ; perWalletModelData . getWallet ( ) . commitTx ( sendRequest . tx ) ; peerGroup . broadcastTransaction ( sendRequest . tx ) ; log . debug ( "Sending transaction '" + Utils . bytesToHexString ( sendRequest . tx . bitcoinSerialize ( ) ) + "'" ) ; } catch ( VerificationException e1 ) { e1 . printStackTrace ( ) ; } Transaction sendTransaction = sendRequest . tx ; log . debug ( "MultiBitService#sendCoins - Sent coins has completed" ) ; assert sendTransaction != null ; if ( sendTransaction != null ) { log . debug ( "MultiBitService#sendCoins - Sent coins. Transaction hash is {}" , sendTransaction . getHashAsString ( ) + ", identityHashcode = " + System . identityHashCode ( sendTransaction ) ) ; if ( sendTransaction . getConfidence ( ) != null ) { log . debug ( "Added bitcoinController " + System . identityHashCode ( bitcoinController ) + " as listener to tx = " + sendTransaction . getHashAsString ( ) ) ; sendTransaction . getConfidence ( ) . addEventListener ( bitcoinController ) ; } else { log . debug ( "Cannot add bitcoinController as listener to tx = " + sendTransaction . getHashAsString ( ) + " no transactionConfidence" ) ; } try { bitcoinController . getFileHandler ( ) . savePerWalletModelData ( perWalletModelData , false ) ; } catch ( WalletSaveException wse ) { log . error ( wse . getClass ( ) . getCanonicalName ( ) + " " + wse . getMessage ( ) ) ; MessageManager . INSTANCE . addMessage ( new Message ( wse . getClass ( ) . getCanonicalName ( ) + " " + wse . getMessage ( ) ) ) ; } catch ( WalletVersionException wse ) { log . error ( wse . getClass ( ) . getCanonicalName ( ) + " " + wse . getMessage ( ) ) ; MessageManager . INSTANCE . addMessage ( new Message ( wse . getClass ( ) . getCanonicalName ( ) + " " + wse . getMessage ( ) ) ) ; } try { List < WalletData > perWalletModelDataList = bitcoinController . getModel ( ) . getPerWalletModelDataList ( ) ; if ( perWalletModelDataList != null ) { for ( WalletData loopPerWalletModelData : perWalletModelDataList ) { if ( ! perWalletModelData . getWalletFilename ( ) . equals ( loopPerWalletModelData . getWalletFilename ( ) ) ) { Wallet loopWallet = loopPerWalletModelData . getWallet ( ) ; if ( loopWallet . isPendingTransactionRelevant ( sendTransaction ) ) { if ( loopPerWalletModelData . getWalletInfo ( ) != null ) { synchronized ( loopPerWalletModelData . getWalletInfo ( ) ) { loopPerWalletModelData . setDirty ( true ) ; } } else { loopPerWalletModelData . setDirty ( true ) ; } if ( loopWallet . getTransaction ( sendTransaction . getHash ( ) ) == null ) { log . debug ( "MultiBit adding a new pending transaction for the wallet '" + loopPerWalletModelData . getWalletDescription ( ) + "'\n" + sendTransaction . toString ( ) ) ; loopWallet . receivePending ( sendTransaction , null ) ; } } } } } } catch ( ScriptException e ) { e . printStackTrace ( ) ; } catch ( VerificationException e ) { e . printStackTrace ( ) ; } } return sendTransaction ; }
send bitcoins from the active wallet .
