use of com.samourai.wallet.bip69.BIP69InputComparator in project samourai-wallet-android by Samourai-Wallet.
the class Stowaway method doStep3.
//
// receiver
//
public boolean doStep3(HashMap<String, ECKey> keyBag) {
Transaction transaction = this.getTransaction();
List<TransactionInput> inputs = new ArrayList<TransactionInput>();
inputs.addAll(transaction.getInputs());
Collections.sort(inputs, new BIP69InputComparator());
transaction.clearInputs();
for (TransactionInput input : inputs) {
transaction.addInput(input);
}
List<TransactionOutput> outputs = new ArrayList<TransactionOutput>();
outputs.addAll(transaction.getOutputs());
Collections.sort(outputs, new BIP69OutputComparator());
transaction.clearOutputs();
for (TransactionOutput output : outputs) {
transaction.addOutput(output);
}
psbt.setTransaction(transaction);
signTx(keyBag);
this.setStep(3);
return true;
}
use of com.samourai.wallet.bip69.BIP69InputComparator in project samourai-wallet-android by Samourai-Wallet.
the class SendFactory method makeTransaction.
/*
Used by spends
*/
private Transaction makeTransaction(int accountIdx, HashMap<String, BigInteger> receivers, List<MyTransactionOutPoint> unspent) throws Exception {
BigInteger amount = BigInteger.ZERO;
for (Iterator<Map.Entry<String, BigInteger>> iterator = receivers.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, BigInteger> mapEntry = iterator.next();
amount = amount.add(mapEntry.getValue());
}
List<TransactionOutput> outputs = new ArrayList<TransactionOutput>();
Transaction tx = new Transaction(SamouraiWallet.getInstance().getCurrentNetworkParams());
for (Iterator<Map.Entry<String, BigInteger>> iterator = receivers.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, BigInteger> mapEntry = iterator.next();
String toAddress = mapEntry.getKey();
BigInteger value = mapEntry.getValue();
/*
if(value.compareTo(SamouraiWallet.bDust) < 1) {
throw new Exception(context.getString(R.string.dust_amount));
}
*/
if (value == null || (value.compareTo(BigInteger.ZERO) <= 0 && !FormatsUtil.getInstance().isValidBIP47OpReturn(toAddress))) {
throw new Exception(context.getString(R.string.invalid_amount));
}
TransactionOutput output = null;
Script toOutputScript = null;
if (!FormatsUtil.getInstance().isValidBitcoinAddress(toAddress) && FormatsUtil.getInstance().isValidBIP47OpReturn(toAddress)) {
toOutputScript = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data(Hex.decode(toAddress)).build();
output = new TransactionOutput(SamouraiWallet.getInstance().getCurrentNetworkParams(), null, Coin.valueOf(0L), toOutputScript.getProgram());
} else if (FormatsUtil.getInstance().isValidBech32(toAddress)) {
output = Bech32Util.getInstance().getTransactionOutput(toAddress, value.longValue());
} else {
toOutputScript = ScriptBuilder.createOutputScript(org.bitcoinj.core.Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), toAddress));
output = new TransactionOutput(SamouraiWallet.getInstance().getCurrentNetworkParams(), null, Coin.valueOf(value.longValue()), toOutputScript.getProgram());
}
outputs.add(output);
}
List<MyTransactionInput> inputs = new ArrayList<MyTransactionInput>();
for (MyTransactionOutPoint outPoint : unspent) {
Script script = new Script(outPoint.getScriptBytes());
if (script.getScriptType() == Script.ScriptType.NO_TYPE) {
continue;
}
MyTransactionInput input = new MyTransactionInput(SamouraiWallet.getInstance().getCurrentNetworkParams(), null, new byte[0], outPoint, outPoint.getTxHash().toString(), outPoint.getTxOutputN());
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.RBF_OPT_IN, false) == true) {
input.setSequenceNumber(SamouraiWallet.RBF_SEQUENCE_VAL.longValue());
}
inputs.add(input);
}
//
// deterministically sort inputs and outputs, see BIP69 (OBPP)
//
Collections.sort(inputs, new BIP69InputComparator());
for (TransactionInput input : inputs) {
tx.addInput(input);
}
Collections.sort(outputs, new BIP69OutputComparator());
for (TransactionOutput to : outputs) {
tx.addOutput(to);
}
return tx;
}
use of com.samourai.wallet.bip69.BIP69InputComparator in project samourai-wallet-android by Samourai-Wallet.
the class STONEWALLx2 method doStep3.
//
// counterparty
//
protected boolean doStep3(HashMap<String, ECKey> keyBag) {
Transaction transaction = this.getTransaction();
List<TransactionInput> inputs = new ArrayList<TransactionInput>();
inputs.addAll(transaction.getInputs());
Collections.sort(inputs, new BIP69InputComparator());
transaction.clearInputs();
for (TransactionInput input : inputs) {
transaction.addInput(input);
}
List<TransactionOutput> outputs = new ArrayList<TransactionOutput>();
outputs.addAll(transaction.getOutputs());
Collections.sort(outputs, new BIP69OutputComparator());
transaction.clearOutputs();
for (TransactionOutput output : outputs) {
transaction.addOutput(output);
}
psbt.setTransaction(transaction);
signTx(keyBag);
this.setStep(3);
return true;
}
Aggregations