PaymentChannelServerState(StoredServerChannel storedServerChannel, Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { synchronized (storedServerChannel) { this.stateMachine = new StateMachine<>(State.UNINITIALISED, getStateTransitions()); this.wallet = checkNotNull(wallet); this.broadcaster = checkNotNull(broadcaster); this.contract = checkNotNull(storedServerChannel.contract); this.serverKey = checkNotNull(storedServerChannel.myKey); this.storedServerChannel = storedServerChannel; this.bestValueToMe = checkNotNull(storedServerChannel.bestValueToMe); this.minExpireTime = storedServerChannel.refundTransactionUnlockTimeSecs; this.bestValueSignature = storedServerChannel.bestValueSignature; checkArgument(bestValueToMe.equals(Coin.ZERO) || bestValueSignature != null); storedServerChannel.state = this; } }
PaymentChannelServerState(StoredServerChannel storedServerChannel, Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { synchronized (storedServerChannel) { this.stateMachine = new StateMachine<State>(State.UNINITIALISED, getStateTransitions()); this.wallet = checkNotNull(wallet); this.broadcaster = checkNotNull(broadcaster); this.contract = checkNotNull(storedServerChannel.contract); this.serverKey = checkNotNull(storedServerChannel.myKey); this.storedServerChannel = storedServerChannel; this.bestValueToMe = checkNotNull(storedServerChannel.bestValueToMe); this.minExpireTime = storedServerChannel.refundTransactionUnlockTimeSecs; this.bestValueSignature = storedServerChannel.bestValueSignature; checkArgument(bestValueToMe.equals(Coin.ZERO) || bestValueSignature != null); storedServerChannel.state = this; } }
PaymentChannelServerState(StoredServerChannel storedServerChannel, Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { synchronized (storedServerChannel) { this.stateMachine = new StateMachine<>(State.UNINITIALISED, getStateTransitions()); this.wallet = checkNotNull(wallet); this.broadcaster = checkNotNull(broadcaster); this.contract = checkNotNull(storedServerChannel.contract); this.serverKey = checkNotNull(storedServerChannel.myKey); this.storedServerChannel = storedServerChannel; this.bestValueToMe = checkNotNull(storedServerChannel.bestValueToMe); this.minExpireTime = storedServerChannel.refundTransactionUnlockTimeSecs; this.bestValueSignature = storedServerChannel.bestValueSignature; checkArgument(bestValueToMe.equals(Coin.ZERO) || bestValueSignature != null); storedServerChannel.state = this; } }
PaymentChannelServerState(StoredServerChannel storedServerChannel, Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { synchronized (storedServerChannel) { this.stateMachine = new StateMachine<State>(State.UNINITIALISED, getStateTransitions()); this.wallet = checkNotNull(wallet); this.broadcaster = checkNotNull(broadcaster); this.contract = checkNotNull(storedServerChannel.contract); this.serverKey = checkNotNull(storedServerChannel.myKey); this.storedServerChannel = storedServerChannel; this.bestValueToMe = checkNotNull(storedServerChannel.bestValueToMe); this.minExpireTime = storedServerChannel.refundTransactionUnlockTimeSecs; this.bestValueSignature = storedServerChannel.bestValueSignature; checkArgument(bestValueToMe.equals(Coin.ZERO) || bestValueSignature != null); storedServerChannel.state = this; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MBHDPaymentRequestData that = (MBHDPaymentRequestData) o; if (isGlidera != that.isGlidera) return false; if (address != null ? !address.equals(that.address) : that.address != null) return false; if (amountCoin != null ? !amountCoin.equals(that.amountCoin) : that.amountCoin != null) return false; if (amountFiat != null ? !amountFiat.equals(that.amountFiat) : that.amountFiat != null) return false; if (date != null ? !date.equals(that.date) : that.date != null) return false; if (label != null ? !label.equals(that.label) : that.label != null) return false; if (note != null ? !note.equals(that.note) : that.note != null) return false; if (paidAmountCoin != null ? !paidAmountCoin.equals(that.paidAmountCoin) : that.paidAmountCoin != null) return false; if (!payingTransactionHashes.equals(that.payingTransactionHashes)) { return false; } return true; }
/** * @return True if the "next" button should be enabled */ private boolean isNextEnabled() { Optional<Coin> coinAmount = getPanelModel().get() .getEnterAmountModel() .getCoinAmount(); boolean bitcoinAmountOK = coinAmount.isPresent() && !coinAmount.get().equals(Coin.ZERO); boolean recipientOK = getPanelModel().get() .getEnterRecipientModel() .getRecipient() .isPresent(); return bitcoinAmountOK && recipientOK && networkOk; }
for (Coin aCoin : coins) { boolean done = false; for (Iterator<LineItem> it = itemList.iterator();it.hasNext() && !done) { LineItem currentItem = it.next() Coin currentCoin = currentItem.getCoin(); int currentQuantity = currentItem.getQuantity(); if (currentCoin.equals(aCoin)) { currentItem.setQuantity(currentQuantity + 1); done = true; } } if(!done) { LineItem anItem = new LineItem(aCoin, 1); itemsList.add(anItem); } }
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes) { super(params); // Negative values obviously make no sense, except for -1 which is used as a sentinel value when calculating // SIGHASH_SINGLE signatures, so unfortunately we have to allow that here. checkArgument(value.signum() >= 0 || value.equals(Coin.NEGATIVE_SATOSHI), "Negative values not allowed"); checkArgument(!params.hasMaxMoney() || value.compareTo(params.getMaxMoney()) <= 0, "Values larger than MAX_MONEY not allowed"); this.value = value.value; this.scriptBytes = scriptBytes; setParent(parent); availableForSpending = true; length = 8 + VarInt.sizeOf(scriptBytes.length) + scriptBytes.length; }
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes) { super(params); // Negative values obviously make no sense, except for -1 which is used as a sentinel value when calculating // SIGHASH_SINGLE signatures, so unfortunately we have to allow that here. checkArgument(value.signum() >= 0 || value.equals(Coin.NEGATIVE_SATOSHI), "Negative values not allowed"); checkArgument(!params.hasMaxMoney() || value.compareTo(params.getMaxMoney()) <= 0, "Values larger than MAX_MONEY not allowed"); this.value = value.value; this.scriptBytes = scriptBytes; setParent(parent); availableForSpending = true; length = 8 + VarInt.sizeOf(scriptBytes.length) + scriptBytes.length; }
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes) { super(params); // Negative values obviously make no sense, except for -1 which is used as a sentinel value when calculating // SIGHASH_SINGLE signatures, so unfortunately we have to allow that here. checkArgument(value.signum() >= 0 || value.equals(Coin.NEGATIVE_SATOSHI), "Negative values not allowed"); checkArgument(!params.hasMaxMoney() || value.compareTo(params.getMaxMoney()) <= 0, "Values larger than MAX_MONEY not allowed"); this.value = value.value; this.scriptBytes = scriptBytes; setParent(parent); availableForSpending = true; length = 8 + VarInt.sizeOf(scriptBytes.length) + scriptBytes.length; }
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes) { super(params); // Negative values obviously make no sense, except for -1 which is used as a sentinel value when calculating // SIGHASH_SINGLE signatures, so unfortunately we have to allow that here. checkArgument(value.signum() >= 0 || value.equals(Coin.NEGATIVE_SATOSHI), "Negative values not allowed"); checkArgument(!params.hasMaxMoney() || value.compareTo(params.getMaxMoney()) <= 0, "Values larger than MAX_MONEY not allowed"); this.value = value.value; this.scriptBytes = scriptBytes; setParent(parent); availableForSpending = true; length = 8 + VarInt.sizeOf(scriptBytes.length) + scriptBytes.length; }
public CoinSelection select(Coin biTarget, List<OutPointOutput> candidates) { long target = biTarget.value; HashSet<OutPointOutput> selected = new HashSet<>(); // Sort the inputs by age*value so we get the highest "coindays" spent. // TODO: Consider changing the wallets internal format to track just outputs and keep them ordered. ArrayList<OutPointOutput> sortedOutputs = new ArrayList<>(candidates); // When calculating the wallet balance, we may be asked to select all possible coins, if so, avoid sorting // them in order to improve performance. if (!biTarget.equals(NetworkParameters.MAX_MONEY)) { sortOutputs(sortedOutputs); } // Now iterate over the sorted outputs until we have got as close to the target as possible or a little // bit over (excessive value will be change). long total = 0; for (OutPointOutput output : sortedOutputs) { if (total >= target) break; // Only pick chain-included transactions, or transactions that are ours and pending. if (!shouldSelect(output)) continue; selected.add(output); total += output.getValueLong(); } // Total may be lower than target here, if the given candidates were insufficient to create to requested // transaction. return new CoinSelection(Coin.valueOf(total), selected); }
public CoinSelection select(Coin biTarget, List<OutPointOutput> candidates) { long target = biTarget.value; HashSet<OutPointOutput> selected = new HashSet<>(); // Sort the inputs by age*value so we get the highest "coindays" spent. // TODO: Consider changing the wallets internal format to track just outputs and keep them ordered. ArrayList<OutPointOutput> sortedOutputs = new ArrayList<>(candidates); // When calculating the wallet balance, we may be asked to select all possible coins, if so, avoid sorting // them in order to improve performance. if (!biTarget.equals(NetworkParameters.MAX_MONEY)) { sortOutputs(sortedOutputs); } // Now iterate over the sorted outputs until we have got as close to the target as possible or a little // bit over (excessive value will be change). long total = 0; for (OutPointOutput output : sortedOutputs) { if (total >= target) break; // Only pick chain-included transactions, or transactions that are ours and pending. if (!shouldSelect(output)) continue; selected.add(output); total += output.getValueLong(); } // Total may be lower than target here, if the given candidates were insufficient to create to requested // transaction. return new CoinSelection(Coin.valueOf(total), selected); }
@Override public CoinSelection select(Coin target, List<TransactionOutput> candidates) { ArrayList<TransactionOutput> selected = new ArrayList<TransactionOutput>(); // Sort the inputs by age*value so we get the highest "coindays" spent. // TODO: Consider changing the wallets internal format to track just outputs and keep them ordered. ArrayList<TransactionOutput> sortedOutputs = new ArrayList<TransactionOutput>(candidates); // When calculating the wallet balance, we may be asked to select all possible coins, if so, avoid sorting // them in order to improve performance. // TODO: Take in network parameters when instanatiated, and then test against the current network. Or just have a boolean parameter for "give me everything" if (!target.equals(NetworkParameters.MAX_MONEY)) { sortOutputs(sortedOutputs); } // Now iterate over the sorted outputs until we have got as close to the target as possible or a little // bit over (excessive value will be change). long total = 0; for (TransactionOutput output : sortedOutputs) { if (total >= target.value) break; // Only pick chain-included transactions, or transactions that are ours and pending. if (!shouldSelect(output.getParentTransaction())) continue; selected.add(output); total += output.getValue().value; } // Total may be lower than target here, if the given candidates were insufficient to create to requested // transaction. return new CoinSelection(Coin.valueOf(total), selected); }
@Override public CoinSelection select(Coin target, List<TransactionOutput> candidates) { ArrayList<TransactionOutput> selected = new ArrayList<>(); // Sort the inputs by age*value so we get the highest "coindays" spent. // TODO: Consider changing the wallets internal format to track just outputs and keep them ordered. ArrayList<TransactionOutput> sortedOutputs = new ArrayList<>(candidates); // When calculating the wallet balance, we may be asked to select all possible coins, if so, avoid sorting // them in order to improve performance. // TODO: Take in network parameters when instanatiated, and then test against the current network. Or just have a boolean parameter for "give me everything" if (!target.equals(NetworkParameters.MAX_MONEY)) { sortOutputs(sortedOutputs); } // Now iterate over the sorted outputs until we have got as close to the target as possible or a little // bit over (excessive value will be change). long total = 0; for (TransactionOutput output : sortedOutputs) { if (total >= target.value) break; // Only pick chain-included transactions, or transactions that are ours and pending. if (!shouldSelect(output.getParentTransaction())) continue; selected.add(output); total += output.getValue().value; } // Total may be lower than target here, if the given candidates were insufficient to create to requested // transaction. return new CoinSelection(Coin.valueOf(total), selected); }
protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) { Transaction tx = new Transaction(wallet.getParams()); if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) { tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams())); } tx.addInput(contract.getOutput(0)); return SendRequest.forTx(tx); }
protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) { Transaction tx = new Transaction(wallet.getParams()); if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) { tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams())); } tx.addInput(contract.getOutput(0)); return SendRequest.forTx(tx); }
protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) { Transaction tx = new Transaction(wallet.getParams()); if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) { tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams())); } tx.addInput(contract.getOutput(0)); return SendRequest.forTx(tx); }
protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) { Transaction tx = new Transaction(wallet.getParams()); if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) { tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams())); } tx.addInput(contract.getOutput(0)); return SendRequest.forTx(tx); }
@Test public void balance() throws Exception { // Receive 5 coins then half a coin. Coin v1 = valueOf(5, 0); Coin v2 = valueOf(0, 50); Coin expected = valueOf(5, 50); assertEquals(0, wallet.getTransactions(true).size()); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, v1); assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT)); sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, v2); assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT)); assertEquals(expected, wallet.getBalance()); // Now spend one coin. Coin v3 = COIN; Transaction spend = wallet.createSend(OTHER_ADDRESS, v3); wallet.commitTx(spend); assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING)); // Available and estimated balances should not be the same. We don't check the exact available balance here // because it depends on the coin selection algorithm. assertEquals(valueOf(4, 50), wallet.getBalance(Wallet.BalanceType.ESTIMATED)); assertFalse(wallet.getBalance(Wallet.BalanceType.AVAILABLE).equals( wallet.getBalance(Wallet.BalanceType.ESTIMATED))); // Now confirm the transaction by including it into a block. sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, spend); // Change is confirmed. We started with 5.50 so we should have 4.50 left. Coin v4 = valueOf(4, 50); assertEquals(v4, wallet.getBalance(Wallet.BalanceType.AVAILABLE)); }