public TrimmedOutput(NetworkParameters params, long value, Sha256Hash txHash, long index, byte[] scriptBytes) { super(params, null, Coin.valueOf(value), scriptBytes); this.index = index; this.txHash = txHash; }
public TrimmedOutput(NetworkParameters params, long value, Sha256Hash txHash, long index, byte[] scriptBytes) { super(params, null, Coin.valueOf(value), scriptBytes); this.index = index; this.txHash = txHash; }
/** * Returns the value of this output. This is the amount of currency that the destination address * receives. */ public Coin getValue() { try { return Coin.valueOf(value); } catch (IllegalArgumentException e) { throw new IllegalStateException(e.getMessage(), e); } }
@Override public Coin getBalance () { final long[] value = {0}; this.outputs.stream().forEach(transactionOutput -> value[0] += transactionOutput.getValue().value); return Coin.valueOf(value[0]); }
/** * Parse a human readable coin value to a {@link org.bitcoinj.core.Coin} instance. * * @throws NumberFormatException * if the string cannot be parsed for some reason */ public Coin parse(String str) throws NumberFormatException { return Coin.valueOf(parseValue(str, Coin.SMALLEST_UNIT_EXPONENT)); }
/** * Parse a human readable coin value to a {@link org.bitcoinj.core.Coin} instance. * * @throws NumberFormatException * if the string cannot be parsed for some reason */ public Coin parse(String str) throws NumberFormatException { return Coin.valueOf(parseValue(str, Coin.SMALLEST_UNIT_EXPONENT)); }
/** * Returns a 1 coin of this type with the correct amount of units (satoshis) * Use {@link com.coinomi.core.coins.CoinType:oneCoin} */ @Deprecated public Coin getOneCoin() { BigInteger units = BigInteger.TEN.pow(getUnitExponent()); return Coin.valueOf(units.longValue()); }
public void addAnchorOutputToAnchor () { List<TransactionOutput> outputList = new ArrayList<>(); outputList.add(new TransactionOutput( Constants.getNetwork(), null, Coin.valueOf(channelStatus.amountClient + channelStatus.amountServer), getAnchorScript().getProgram())); outputList.addAll(anchorTx.getOutputs()); Transaction tx = new Transaction(Constants.getNetwork()); anchorTx.getInputs().stream().forEach(tx::addInput); outputList.stream().forEach(tx::addOutput); this.anchorTx = tx; }
/** * Returns the outputs of the payment request. */ public List<PaymentProtocol.Output> getOutputs() { List<PaymentProtocol.Output> outputs = new ArrayList<PaymentProtocol.Output>(paymentDetails.getOutputsCount()); for (Protos.Output output : paymentDetails.getOutputsList()) { Coin amount = output.hasAmount() ? Coin.valueOf(output.getAmount()) : null; outputs.add(new PaymentProtocol.Output(amount, output.getScript().toByteArray())); } return outputs; }
/** * Returns the outputs of the payment request. */ public List<PaymentProtocol.Output> getOutputs() { List<PaymentProtocol.Output> outputs = new ArrayList<>(paymentDetails.getOutputsCount()); for (Protos.Output output : paymentDetails.getOutputsList()) { Coin amount = output.hasAmount() ? Coin.valueOf(output.getAmount()) : null; outputs.add(new PaymentProtocol.Output(amount, output.getScript().toByteArray())); } return outputs; }
public Transaction getClosingTransaction (ChannelStatus channelStatus, float feePerByte) { //For the sake of privacy (and simplicity) we use lexicographically ordering here, as defined in BIP69 Transaction transaction = new Transaction(Constants.getNetwork()); transaction.addInput(channel.anchorTxHash, 0, Tools.getDummyScript()); //TODO deduct the transaction fee correctly from both amounts //TODO would be better to have another address on file that we can use here.. long feePerParty = (Tools.getTransactionFees(2, 2, feePerByte) / 2); transaction.addOutput(Coin.valueOf(channelStatus.amountClient - feePerParty), channel.channelStatus.addressClient); transaction.addOutput(Coin.valueOf(channelStatus.amountServer - feePerParty), channel.channelStatus.addressServer); return Tools.applyBIP69(transaction); }
public void fillAnchorTransactionWithoutSignatures (WalletHelper walletHelper) { long totalAmount = channelStatus.amountServer + channelStatus.amountClient; if (anchorTx == null) { Script anchorScriptServer = getAnchorScriptOutput(); Script anchorScriptServerP2SH = ScriptBuilder.createP2SHOutputScript(anchorScriptServer); anchorTx = new Transaction(Constants.getNetwork()); anchorTx.addOutput(Coin.valueOf(totalAmount), anchorScriptServerP2SH); } anchorTx = walletHelper.addInputs(anchorTx, channelStatus.amountServer, channelStatus.feePerByte); anchorTxHash = anchorTx.getHash(); }
@Test public void withLocale() throws Exception { final Coin value = Coin.valueOf(-1234567890l); assertEquals("-12.34567890", NO_CODE.withLocale(Locale.US).format(value).toString()); assertEquals("-12,34567890", NO_CODE.withLocale(Locale.GERMANY).format(value).toString()); assertEquals("-१२.३४५६७८९०", NO_CODE.withLocale(new Locale("hi", "IN")).format(value).toString()); // Devanagari }
@Test public void withLocale() throws Exception { final Coin value = Coin.valueOf(-1234567890l); assertEquals("-12.34567890", NO_CODE.withLocale(Locale.US).format(value).toString()); assertEquals("-12,34567890", NO_CODE.withLocale(Locale.GERMANY).format(value).toString()); assertEquals("-१२.३४५६७८९०", NO_CODE.withLocale(new Locale("hi", "IN")).format(value).toString()); // Devanagari }
@Test public void watchingScripts() throws Exception { // Verify that pending transactions to watched addresses are relevant Address watchedAddress = new ECKey().toAddress(PARAMS); wallet.addWatchedAddress(watchedAddress); Coin value = valueOf(5, 0); Transaction t1 = createFakeTx(PARAMS, value, watchedAddress); assertTrue(t1.getWalletOutputs(wallet).size() >= 1); assertTrue(wallet.isPendingTransactionRelevant(t1)); }
@Test public void isConsistent_spent() throws Exception { // This test ensures that isConsistent catches transactions that are marked spent when // they aren't. Transaction tx = createFakeTx(PARAMS, COIN, myAddress); TransactionOutput output = new TransactionOutput(PARAMS, tx, valueOf(0, 5), OTHER_ADDRESS); tx.addOutput(output); assertTrue(wallet.isConsistent()); wallet.addWalletTransaction(new WalletTransaction(Pool.SPENT, tx)); assertFalse(wallet.isConsistent()); }
@Test public void microcoinScaleTest() throws Exception { BtcFormat coinFormat = BtcFormat.getMicroInstance(Locale.US); assertEquals("1,000,000.00", coinFormat.format(Coin.COIN)); assertEquals("-1,000,000.00", coinFormat.format(Coin.COIN.negate())); assertEquals("1,000,000.10", coinFormat.format(Coin.COIN.add(valueOf(10)))); assertEquals(Coin.parseCoin("0.000001"), coinFormat.parseObject("1.00")); assertEquals(valueOf(1), coinFormat.parseObject("0.01")); assertEquals(Coin.parseCoin("0.001"), coinFormat.parseObject("1,000.00")); assertEquals(Coin.parseCoin("0.001"), coinFormat.parseObject("1000")); }
@Test public void isConsistent_pools() throws Exception { // This test ensures that isConsistent catches transactions that are in incompatible pools. Transaction tx = createFakeTx(PARAMS, COIN, myAddress); TransactionOutput output = new TransactionOutput(PARAMS, tx, valueOf(0, 5), OTHER_ADDRESS); tx.addOutput(output); wallet.receiveFromBlock(tx, null, BlockChain.NewBlockType.BEST_CHAIN, 0); assertTrue(wallet.isConsistent()); wallet.addWalletTransaction(new WalletTransaction(Pool.PENDING, tx)); assertFalse(wallet.isConsistent()); }
@Test public void millicoinScaleTest() throws Exception { BtcFormat coinFormat = BtcFormat.getMilliInstance(Locale.US); assertEquals("1,000.00", coinFormat.format(Coin.COIN)); assertEquals("-1,000.00", coinFormat.format(Coin.COIN.negate())); assertEquals(Coin.parseCoin("0.001"), coinFormat.parseObject("1.00")); assertEquals(valueOf(1000), coinFormat.parseObject("0.01")); assertEquals(Coin.parseCoin("1"), coinFormat.parseObject("1,000.00")); assertEquals(Coin.parseCoin("1"), coinFormat.parseObject("1000")); }