public static BitTransaction fromTrimmed(Sha256Hash transactionId, Transaction transaction, Value valueSent, Value valueReceived, Value fee) { return new BitTransaction(transactionId, transaction, true, valueSent, valueReceived, fee); }
@VisibleForTesting void addNewTransactionIfNeeded(Transaction tx) { addNewTransactionIfNeeded(new BitTransaction(tx)); }
@Override public void run() { File txCachedFile = getTxCacheFile(txHash); if (txCachedFile.exists()) { try { byte[] txBytes = Files.toByteArray(txCachedFile); BitTransaction tx = new BitTransaction(type, txBytes); if (!tx.getHash().equals(txHash)) { if (!txCachedFile.delete()) { log.warn("Error deleting cached transaction {}", txCachedFile); } } else { listener.onTransactionUpdate(tx); return; } } catch (IOException e) { log.warn("Error reading cached transaction", e); } } // Fallback to fetching from the network getTransactionFromNetwork(txHash, listener); } });
@Override public void getTransaction(Sha256Hash txHash, TransactionEventListener<BitTransaction> listener) { BitTransaction tx = new BitTransaction(coinType, rawTxs.get(txHash)); listener.onTransactionUpdate(tx); }
@Override public void onSuccess(ResultMessage result) { try { String rawTx = result.getResult().getString(0); byte[] txBytes = Utils.HEX.decode(rawTx); BitTransaction tx = new BitTransaction(type, txBytes); if (!tx.getHash().equals(txHash)) { throw new Exception("Requested TX " + txHash + " but got " + tx.getHashAsString()); } listener.onTransactionUpdate(tx); if (cacheDir != null) { try { Files.write(txBytes, getTxCacheFile(txHash)); } catch (IOException e) { log.warn("Error writing cached transaction", e); } } } catch (Exception e) { onFailure(e); } }
public static BitSendRequest emptyWallet(BitAddress destination) { checkNotNull(destination.getType(), "Address is for an unknown network"); checkTypeCompatibility(destination.getType()); BitSendRequest req = new BitSendRequest(destination.getType()); Transaction tx = new Transaction(req.type); tx.addOutput(Coin.ZERO, destination); req.tx = new BitTransaction(tx); req.emptyWallet = true; return req; }
/** * <p>Creates a new SendRequest to the given address for the given value.</p> * * <p>Be very careful when value is smaller than {@link Transaction#MIN_NONDUST_OUTPUT} as the transaction will * likely be rejected by the network in this case.</p> */ public static BitSendRequest to(BitAddress destination, Value amount) { checkNotNull(destination.getType(), "Address is for an unknown network"); checkState(TypeUtils.is(destination.getType(), amount.type), "Incompatible sending amount type"); checkTypeCompatibility(destination.getType()); BitSendRequest req = new BitSendRequest(destination.getType()); Transaction tx = new Transaction(req.type); tx.addOutput(amount.toCoin(), destination); req.tx = new BitTransaction(tx); return req; }
private Sha256Hash send(Value value, WalletPocketHD w1, WalletPocketHD w2) throws Exception { assertEquals(w1.getCoinType(), w2.getCoinType()); CoinType type = w1.getCoinType(); BitSendRequest req = w1.sendCoinsOffline(w2.getReceiveAddress(), value); req.feePerTxSize = type.value("0.01"); w1.completeAndSignTx(req); byte[] txBytes = req.tx.bitcoinSerialize(); w1.addNewTransactionIfNeeded(new BitTransaction(type, txBytes)); w2.addNewTransactionIfNeeded(new BitTransaction(type, txBytes)); return req.tx.getHash(); }
valueReceived, fee); } else { bitTx = new BitTransaction(tx);