/** * Construct a free standing Transaction Output. * @param params The network parameters. * @param output The stored output (free standing). */ public FreeStandingTransactionOutput(NetworkParameters params, UTXO output, int chainHeight) { super(params, null, output.getValue(), output.getScript().getProgram()); this.output = output; this.chainHeight = chainHeight; }
/** * Construct a free standing Transaction Output. * @param params The network parameters. * @param output The stored output (free standing). */ public FreeStandingTransactionOutput(NetworkParameters params, UTXO output, int chainHeight) { super(params, null, output.getValue(), output.getScript().getProgram()); this.output = output; this.chainHeight = chainHeight; }
/** * Construct a free standing Transaction Output. * @param params The network parameters. * @param output The stored output (free standing). */ public FreeStandingTransactionOutput(NetworkParameters params, UTXO output, int chainHeight) { super(params, null, output.getValue(), output.getScript().getProgram()); this.output = output; this.chainHeight = chainHeight; }
/** * Construct a free standing Transaction Output. * @param params The network parameters. * @param output The stored output (free standing). */ public FreeStandingTransactionOutput(NetworkParameters params, UTXO output, int chainHeight) { super(params, null, output.getValue(), output.getScript().getProgram()); this.output = output; this.chainHeight = chainHeight; }
@Override public void addUnspentTransactionOutput(UTXO out) throws BlockStoreException { maybeConnect(); PreparedStatement s = null; try { s = conn.get().prepareStatement(getInsertOpenoutputsSQL()); s.setBytes(1, out.getHash().getBytes()); // index is actually an unsigned int s.setInt(2, (int) out.getIndex()); s.setInt(3, out.getHeight()); s.setLong(4, out.getValue().value); s.setBytes(5, out.getScript().getProgram()); s.setString(6, out.getAddress()); s.setInt(7, out.getScript().getScriptType().ordinal()); s.setBoolean(8, out.isCoinbase()); s.executeUpdate(); s.close(); } catch (SQLException e) { if (!(e.getSQLState().equals(getDuplicateKeyErrorCode()))) throw new BlockStoreException(e); } finally { if (s != null) { try { s.close(); } catch (SQLException e) { throw new BlockStoreException(e); } } } }
@Override public void addUnspentTransactionOutput(UTXO out) throws BlockStoreException { maybeConnect(); PreparedStatement s = null; try { s = conn.get().prepareStatement(getInsertOpenoutputsSQL()); s.setBytes(1, out.getHash().getBytes()); // index is actually an unsigned int s.setInt(2, (int) out.getIndex()); s.setInt(3, out.getHeight()); s.setLong(4, out.getValue().value); s.setBytes(5, out.getScript().getProgram()); s.setString(6, out.getAddress()); s.setInt(7, out.getScript().getScriptType().ordinal()); s.setBoolean(8, out.isCoinbase()); s.executeUpdate(); s.close(); } catch (SQLException e) { if (!(e.getSQLState().equals(getDuplicateKeyErrorCode()))) throw new BlockStoreException(e); } finally { if (s != null) { try { s.close(); } catch (SQLException e) { throw new BlockStoreException(e); } } } }
@Override public void addUnspentTransactionOutput(UTXO out) throws BlockStoreException { maybeConnect(); PreparedStatement s = null; try { s = conn.get().prepareStatement(getInsertOpenoutputsSQL()); s.setBytes(1, out.getHash().getBytes()); // index is actually an unsigned int s.setInt(2, (int) out.getIndex()); s.setInt(3, out.getHeight()); s.setLong(4, out.getValue().value); s.setBytes(5, out.getScript().getProgram()); s.setString(6, out.getAddress()); s.setInt(7, out.getScript().getScriptType().ordinal()); s.setBoolean(8, out.isCoinbase()); s.executeUpdate(); s.close(); } catch (SQLException e) { if (!(e.getSQLState().equals(getDuplicateKeyErrorCode()))) throw new BlockStoreException(e); } finally { if (s != null) { try { s.close(); } catch (SQLException e) { throw new BlockStoreException(e); } } } }
@Override public void addUnspentTransactionOutput(UTXO out) throws BlockStoreException { maybeConnect(); PreparedStatement s = null; try { s = conn.get().prepareStatement(getInsertOpenoutputsSQL()); s.setBytes(1, out.getHash().getBytes()); // index is actually an unsigned int s.setInt(2, (int) out.getIndex()); s.setInt(3, out.getHeight()); s.setLong(4, out.getValue().value); s.setBytes(5, out.getScript().getProgram()); s.setString(6, out.getAddress()); s.setInt(7, out.getScript().getScriptType().ordinal()); s.setBoolean(8, out.isCoinbase()); s.executeUpdate(); s.close(); } catch (SQLException e) { if (!(e.getSQLState().equals(getDuplicateKeyErrorCode()))) throw new BlockStoreException(e); } finally { if (s != null) { try { s.close(); } catch (SQLException e) { throw new BlockStoreException(e); } } } }
Script sc = txout.getScript(); Address address = sc.getToAddress(params, true); UTXO output = new UTXO(txout.getHash(), txout.getIndex(), txout.getValue(), txout.getHeight(), txout.isCoinbase(), txout.getScript(), address.toString()); results.add(output);
final Coin payout = Coin.valueOf(totalPayout.getValue()); UTXO inputUtxo = this.utxoList.stream() .filter(utxo -> utxo.getAddress().equals(fromAddress) && utxo.getValue().isGreaterThan(payout)) .findFirst().orElse(null); if (null == inputUtxo) { return; transaction.addOutput(inputUtxo.getValue().subtract(totalPayout), Address.fromBase58(this.networkParameters, (null == dltTransaction.getChangeAddress()) ? fromAddress : dltTransaction.getChangeAddress())); TransactionOutPoint transactionOutPoint = new TransactionOutPoint(this.networkParameters, inputUtxo.getIndex(), inputUtxo.getHash());
Script sc = txout.getScript(); Address address = sc.getToAddress(params, true); UTXO output = new UTXO(txout.getHash(), txout.getIndex(), txout.getValue(), txout.getHeight(), txout.isCoinbase(), txout.getScript(), address.toString()); results.add(output);
Script sc = txout.getScript(); Address address = sc.getToAddress(params, true); UTXO output = new UTXO(txout.getHash(), txout.getIndex(), txout.getValue(), txout.getHeight(), txout.isCoinbase(), txout.getScript(), address.toString()); results.add(output);
Script sc = txout.getScript(); Address address = sc.getToAddress(params, true); UTXO output = new UTXO(txout.getHash(), txout.getIndex(), txout.getValue(), txout.getHeight(), txout.isCoinbase(), txout.getScript(), address.toString()); results.add(output);
@Test public void testJavaSerialization() throws Exception { ECKey key = new ECKey(); UTXO utxo = new UTXO(Sha256Hash.of(new byte[]{1,2,3}), 1, Coin.COIN, 10, true, ScriptBuilder.createOutputScript(key)); ByteArrayOutputStream os = new ByteArrayOutputStream(); new ObjectOutputStream(os).writeObject(utxo); UTXO utxoCopy = (UTXO) new ObjectInputStream( new ByteArrayInputStream(os.toByteArray())).readObject(); assertEquals(utxo, utxoCopy); assertEquals(utxo.getValue(), utxoCopy.getValue()); assertEquals(utxo.getHeight(), utxoCopy.getHeight()); assertEquals(utxo.isCoinbase(), utxoCopy.isCoinbase()); assertEquals(utxo.getScript(), utxoCopy.getScript()); } }
valueIn = valueIn.add(prevOut.getValue()); if (verifyFlags.contains(VerifyFlag.P2SH)) { if (prevOut.getScript().isPayToScriptHash())
valueIn = valueIn.add(prevOut.getValue()); if (verifyFlags.contains(VerifyFlag.P2SH)) { if (prevOut.getScript().isPayToScriptHash())
valueIn = valueIn.add(prevOut.getValue()); if (verifyFlags.contains(VerifyFlag.P2SH)) { if (prevOut.getScript().isPayToScriptHash())
if (prevOut.isCoinbase() && newBlock.getHeight() - prevOut.getHeight() < params.getSpendableCoinbaseDepth()) throw new VerificationException("Tried to spend coinbase at depth " + (newBlock.getHeight() - prevOut.getHeight())); valueIn = valueIn.add(prevOut.getValue()); if (verifyFlags.contains(VerifyFlag.P2SH)) { if (prevOut.getScript().isPayToScriptHash())
if (prevOut.isCoinbase() && newBlock.getHeight() - prevOut.getHeight() < params.getSpendableCoinbaseDepth()) throw new VerificationException("Tried to spend coinbase at depth " + (newBlock.getHeight() - prevOut.getHeight())); valueIn = valueIn.add(prevOut.getValue()); if (verifyFlags.contains(VerifyFlag.P2SH)) { if (prevOut.getScript().isPayToScriptHash())
UTXO output = outputs.get(0); assertEquals("The address is not equal", address.toString(), output.getAddress()); assertEquals("The amount is not equal", totalAmount, output.getValue());