use of com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates in project PayFile by mikehearn.
the class PayFileClient method getRemainingBalance.
/**
* Returns balance of the wallet plus whatever is left in the current channel, i.e. how much money is spendable
* after a clean disconnect.
*/
public BigInteger getRemainingBalance() {
final StoredPaymentChannelClientStates extension = StoredPaymentChannelClientStates.getFromWallet(wallet);
checkNotNull(extension);
BigInteger valueRefunded = extension.getBalanceForServer(getServerID());
return wallet.getBalance().add(valueRefunded);
}
use of com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates in project PayFile by mikehearn.
the class PayFileClient method getBalanceForServer.
/**
* Returns how much money is still stuck in a channel with the given server. Does NOT include wallet balance.
*/
public static BigInteger getBalanceForServer(String serverName, int port, Wallet wallet) {
final StoredPaymentChannelClientStates extension = StoredPaymentChannelClientStates.getFromWallet(wallet);
checkNotNull(extension);
return extension.getBalanceForServer(getServerID(serverName, port));
}
use of com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates in project PayFile by mikehearn.
the class PayFileClient method getSecondsUntilExpiry.
/**
* Returns how long you have to wait until this channel will either be settled by the server, or can be auto-settled
* by the client (us).
*/
public static long getSecondsUntilExpiry(String serverName, int port, Wallet wallet) {
final StoredPaymentChannelClientStates extension = StoredPaymentChannelClientStates.getFromWallet(wallet);
checkNotNull(extension);
return extension.getSecondsUntilExpiry(getServerID(serverName, port));
}
use of com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates in project PayFile by mikehearn.
the class Main method init.
private void init(Stage mainWindow) throws IOException {
this.mainWindow = mainWindow;
// commented out for now as Modena looks better, but might want to bring this back.
/* if (System.getProperty("os.name").toLowerCase().contains("mac")) {
AquaFx.style();
} */
// Load the GUI. The Controller class will be automagically created and wired up.
URL location = getClass().getResource("main.fxml");
FXMLLoader loader = new FXMLLoader(location);
mainUI = loader.load();
controller = loader.getController();
// Configure the window with a StackPane so we can overlay things on top of the main UI.
uiStack = new StackPane(mainUI);
mainWindow.setTitle(APP_NAME);
final Scene scene = new Scene(uiStack);
// Add CSS that we need.
TextFieldValidator.configureScene(scene);
mainWindow.setScene(scene);
// Make log output concise.
BriefLogFormatter.init();
// Tell bitcoinj to run event handlers on the JavaFX UI thread. This keeps things simple and means
// we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
// we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
// a future version. Also note that this doesn't affect the default executor for ListenableFutures.
// That must be specified each time.
Threading.USER_THREAD = Platform::runLater;
// Create the app kit. It won't do any heavyweight initialization until after we start it.
bitcoin = new WalletAppKit(params, new File("."), filePrefix + APP_NAME) {
@Override
protected void addWalletExtensions() throws Exception {
super.addWalletExtensions();
wallet().addExtension(new StoredPaymentChannelClientStates(wallet(), peerGroup()));
}
};
if (params == RegTestParams.get()) {
// You should run a regtest mode bitcoind locally.
bitcoin.connectToLocalHost();
} else if (params == MainNetParams.get()) {
// Checkpoints are block headers that ship inside our app: for a new user, we pick the last header
// in the checkpoints file and then download the rest from the network. It makes things much faster.
// Checkpoint files are made using the BuildCheckpoints tool and usually we have to download the
// last months worth or more (takes a few seconds).
bitcoin.setCheckpoints(getClass().getResourceAsStream("checkpoints"));
}
// Now configure and start the appkit. It won't block for very long.
bitcoin.setDownloadListener(controller.progressBarUpdater()).setBlockingStartup(false).setUserAgent("PayFile Client", "1.0").startAndWait();
// Don't make the user wait for confirmations for now, as the intention is they're sending it their own money!
bitcoin.wallet().allowSpendingUnconfirmedTransactions();
System.out.println(bitcoin.wallet());
controller.onBitcoinSetup();
overlayUI("connect_server.fxml");
mainUI.setVisible(false);
mainWindow.show();
}
Aggregations