use of org.bitcoinj.params.TestNet3Params in project samourai-wallet-android by Samourai-Wallet.
the class Stowaway method doStep2.
//
// sender
//
public boolean doStep2(HashMap<_TransactionOutPoint, Triple<byte[], byte[], String>> inputs, HashMap<_TransactionOutput, Triple<byte[], byte[], String>> outputs) throws Exception {
Transaction transaction = psbt.getTransaction();
Log.d("Stowaway", "step2 tx:" + transaction.toString());
Log.d("Stowaway", "step2 tx:" + Hex.toHexString(transaction.bitcoinSerialize()));
// tx: modify spend output
long contributedAmount = 0L;
/*
for(TransactionInput input : transaction.getInputs()) {
// Log.d("Stowaway", input.getOutpoint().toString());
contributedAmount += input.getOutpoint().getValue().longValue();
}
*/
for (String outpoint : outpoints.keySet()) {
contributedAmount += outpoints.get(outpoint);
}
long outputAmount = transaction.getOutput(0).getValue().longValue();
TransactionOutput spendOutput = transaction.getOutput(0);
spendOutput.setValue(Coin.valueOf(outputAmount + contributedAmount));
transaction.clearOutputs();
transaction.addOutput(spendOutput);
for (_TransactionOutPoint outpoint : inputs.keySet()) {
Log.d("Stowaway", "outpoint value:" + outpoint.getValue().longValue());
TransactionInput input = new TransactionInput(params, null, new byte[0], outpoint, outpoint.getValue());
transaction.addInput(input);
outpoints.put(outpoint.getTxHash().toString() + "-" + outpoint.getTxOutputN(), outpoint.getValue().longValue());
}
for (_TransactionOutput output : outputs.keySet()) {
transaction.addOutput(output);
}
// psbt: modify spend output
List<PSBTEntry> updatedEntries = new ArrayList<PSBTEntry>();
for (PSBTEntry entry : psbt.getPsbtInputs()) {
if (entry.getKeyType()[0] == PSBT.PSBT_IN_WITNESS_UTXO) {
byte[] data = entry.getData();
byte[] scriptPubKey = new byte[data.length - Long.BYTES];
System.arraycopy(data, Long.BYTES, scriptPubKey, 0, scriptPubKey.length);
entry.setData(PSBT.writeSegwitInputUTXO(outputAmount + contributedAmount, scriptPubKey));
}
updatedEntries.add(entry);
}
psbt.setPsbtInputs(updatedEntries);
for (_TransactionOutPoint outpoint : inputs.keySet()) {
Triple triple = inputs.get(outpoint);
// input type 1
SegwitAddress segwitAddress = new SegwitAddress((byte[]) triple.getLeft(), params);
psbt.addInput(PSBT.PSBT_IN_WITNESS_UTXO, null, PSBT.writeSegwitInputUTXO(outpoint.getValue().longValue(), segwitAddress.segWitRedeemScript().getProgram()));
// input type 6
String[] s = ((String) triple.getRight()).split("/");
psbt.addInput(PSBT.PSBT_IN_BIP32_DERIVATION, (byte[]) triple.getLeft(), PSBT.writeBIP32Derivation((byte[]) triple.getMiddle(), 84, params instanceof TestNet3Params ? 1 : 0, account, Integer.valueOf(s[1]), Integer.valueOf(s[2])));
}
for (_TransactionOutput output : outputs.keySet()) {
Triple triple = outputs.get(output);
// output type 2
String[] s = ((String) triple.getRight()).split("/");
psbt.addOutput(PSBT.PSBT_OUT_BIP32_DERIVATION, (byte[]) triple.getLeft(), PSBT.writeBIP32Derivation((byte[]) triple.getMiddle(), 84, params instanceof TestNet3Params ? 1 : 0, account, Integer.valueOf(s[1]), Integer.valueOf(s[2])));
}
psbt.setTransaction(transaction);
this.setStep(2);
return true;
}
use of org.bitcoinj.params.TestNet3Params in project samourai-wallet-android by Samourai-Wallet.
the class WhirlpoolTx0 method make.
public void make() throws Exception {
tx0 = null;
debug("WhirlpoolTx0", "make: ");
//
if (getChange() < 0L) {
debug("WhirlpoolTx0", "Cannot make premix: negative change:" + getAmountSelected());
throw new Exception("Cannot make premix: negative change:" + getAmountSelected());
}
if (nbPossiblePremix() < 1) {
debug("WhirlpoolTx0", "Cannot make premix: insufficient selected amount:" + getAmountSelected());
throw new Exception("Cannot make premix: insufficient selected amount:" + getAmountSelected());
}
debug("WhirlpoolTx0", "amount selected:" + getAmountSelected() / 1e8);
debug("WhirlpoolTx0", "amount requested:" + ((getPremixRequested() * getPool()) / 1e8));
debug("WhirlpoolTx0", "nb premix possible:" + nbPossiblePremix());
debug("WhirlpoolTx0", "amount after Whirlpool fee:" + getAmountAfterWhirlpoolFee() / 1e8);
debug("WhirlpoolTx0", "fee samourai:" + new DecimalFormat("0.########").format(getFeeSamourai() / 1e8));
debug("WhirlpoolTx0", "fee miners:" + new DecimalFormat("0.########").format(getFee() / 1e8));
debug("WhirlpoolTx0", "change amount:" + getChange() / 1e8);
// [WIP] stub;
tx0 = new Transaction(SamouraiWallet.getInstance().getCurrentNetworkParams() instanceof TestNet3Params ? TestNet3Params.get() : MainNetParams.get());
}
Aggregations