// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/IWalletProtocol.java
// public interface IWalletProtocol {
// 
//     public TransactionInfo fetchTransactionInfo();
// 
//     public SignatureParts[] getSignatureParts();
// 
//     public EphemeralPublicValueWithProof[] getEphemeralPublicValuesWithProof(EphemeralValueShare[] ephemeralValueShares);
// 
//     public boolean sendEncryptedSignatures(EncryptedSignatureWithProof[] encryptedSignatures);
// }


import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.swing.GlazedListsSwing;
import org.bitcoinj.core.*;
import org.bitcoinj.params.RegTestParams;
import com.google.zxing.WriterException;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import de.uni_bonn.bit.wallet_protocol.IWalletProtocol;
import javax.swing.*;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.UnknownHostException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.text.DecimalFormat;
import java.util.List;
import org.apache.log4j.Logger;
    public void generateTransactionButton_Clicked(ActionEvent e) {
        try {
            //Close the old server, so the port is free again
            if (server != null) {
                server.close();
            }
            KeyShareWalletExtension walletEx = ((KeyShareWalletExtension) wallet.addOrGetExistingExtension(new KeyShareWalletExtension()));

            Address receiverAddress = new Address(TransactionHelper.netParams, addressTextField.getText());
            Double amountDouble = (Double) amountTextField.getValue();
            Coin amount = Coin.valueOf(Math.round(amountDouble * 100000000));
            Wallet.SendRequest sendRequest = Wallet.SendRequest.to(receiverAddress, amount);
            sendRequest.changeAddress = walletEx.getAddress();
            sendRequest.missingSigsMode = Wallet.MissingSigsMode.USE_DUMMY_SIG;
            wallet.completeTx(sendRequest);

            tblOutputs.setModel(GlazedListsSwing.eventTableModel(createOutputsList(sendRequest.tx),
                    new String[]{"address", "amount"},
                    new String[]{"Address", "BTC"},
                    new boolean[]{false, false}));
            //hack to ensure correct column sizes. Real columns sizes are proportions of the preferred width.
            tblOutputs.getColumnModel().getColumn(0).setPreferredWidth(800);
            tblOutputs.getColumnModel().getColumn(1).setPreferredWidth(200);
            tblOutputsPane.setVisible(true);

            List<String> ipAddresses = IPAddressHelper.getAllUsableIPAddresses();

            WalletProtocolImpl walletProtocolImpl = new WalletProtocolImpl(sendRequest.tx, new MyWalletProtocolListener(),
                    walletEx.getPrivateKey(), walletEx.getOtherPublicKey(), walletEx.getPkpDesktop(),
                    walletEx.getPkpPhone(), walletEx.getDesktopBCParameters(), walletEx.getPhoneBCParameters());
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/IWalletProtocol.java
// public interface IWalletProtocol {
// 
//     public TransactionInfo fetchTransactionInfo();
// 
//     public SignatureParts[] getSignatureParts();
// 
//     public EphemeralPublicValueWithProof[] getEphemeralPublicValuesWithProof(EphemeralValueShare[] ephemeralValueShares);
// 
//     public boolean sendEncryptedSignatures(EncryptedSignatureWithProof[] encryptedSignatures);
// }


// Path: desktop_wallet/src/main/java/de/uni_bonn/bit/TransactionDialog.java
import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.swing.GlazedListsSwing;
import org.bitcoinj.core.*;
import org.bitcoinj.params.RegTestParams;
import com.google.zxing.WriterException;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import de.uni_bonn.bit.wallet_protocol.IWalletProtocol;
import javax.swing.*;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.NumberFormatter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.UnknownHostException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.text.DecimalFormat;
import java.util.List;
import org.apache.log4j.Logger;

    public void generateTransactionButton_Clicked(ActionEvent e) {
        try {
            //Close the old server, so the port is free again
            if (server != null) {
                server.close();
            }
            KeyShareWalletExtension walletEx = ((KeyShareWalletExtension) wallet.addOrGetExistingExtension(new KeyShareWalletExtension()));

            Address receiverAddress = new Address(TransactionHelper.netParams, addressTextField.getText());
            Double amountDouble = (Double) amountTextField.getValue();
            Coin amount = Coin.valueOf(Math.round(amountDouble * 100000000));
            Wallet.SendRequest sendRequest = Wallet.SendRequest.to(receiverAddress, amount);
            sendRequest.changeAddress = walletEx.getAddress();
            sendRequest.missingSigsMode = Wallet.MissingSigsMode.USE_DUMMY_SIG;
            wallet.completeTx(sendRequest);

            tblOutputs.setModel(GlazedListsSwing.eventTableModel(createOutputsList(sendRequest.tx),
                    new String[]{"address", "amount"},
                    new String[]{"Address", "BTC"},
                    new boolean[]{false, false}));
            //hack to ensure correct column sizes. Real columns sizes are proportions of the preferred width.
            tblOutputs.getColumnModel().getColumn(0).setPreferredWidth(800);
            tblOutputs.getColumnModel().getColumn(1).setPreferredWidth(200);
            tblOutputsPane.setVisible(true);

            List<String> ipAddresses = IPAddressHelper.getAllUsableIPAddresses();

            WalletProtocolImpl walletProtocolImpl = new WalletProtocolImpl(sendRequest.tx, new MyWalletProtocolListener(),
                    walletEx.getPrivateKey(), walletEx.getOtherPublicKey(), walletEx.getPkpDesktop(),
                    walletEx.getPkpPhone(), walletEx.getDesktopBCParameters(), walletEx.getPhoneBCParameters());
            server = new ProtocolServer(IWalletProtocol.class, walletProtocolImpl);