use of com.samourai.wallet.cahoots.psbt.PSBT in project samourai-wallet-android by Samourai-Wallet.
the class Cahoots method fromJSON.
public void fromJSON(JSONObject cObj) {
try {
JSONObject obj = null;
if (cObj.has("cahoots")) {
obj = cObj.getJSONObject("cahoots");
}
if (obj != null && obj.has("type") && obj.has("step") && obj.has("psbt") && obj.has("ts") && obj.has("id") && obj.has("version") && obj.has("spend_amount")) {
if (obj.has("params") && obj.getString("params").equals("testnet")) {
this.params = TestNet3Params.get();
} else {
this.params = MainNetParams.get();
}
this.version = obj.getInt("version");
this.ts = obj.getLong("ts");
this.strID = obj.getString("id");
this.type = obj.getInt("type");
this.step = obj.getInt("step");
this.spendAmount = obj.getLong("spend_amount");
this.feeAmount = obj.getLong("fee_amount");
JSONArray _outpoints = obj.getJSONArray("outpoints");
for (int i = 0; i < _outpoints.length(); i++) {
JSONObject entry = _outpoints.getJSONObject(i);
outpoints.put(entry.getString("outpoint"), entry.getLong("value"));
}
this.strDestination = obj.getString("dest");
this.strCollabChange = obj.getString("collabChange");
// this.strPayNymInit = obj.getString("paynym_init");
if (obj.has("account")) {
this.account = obj.getInt("account");
} else {
this.account = 0;
}
if (obj.has("cpty_account")) {
this.cptyAccount = obj.getInt("cpty_account");
} else {
this.cptyAccount = 0;
}
if (obj.has("fingerprint")) {
fingerprint = Hex.decode(obj.getString("fingerprint"));
}
if (obj.has("fingerprint_collab")) {
fingerprintCollab = Hex.decode(obj.getString("fingerprint_collab"));
}
this.psbt = obj.getString("psbt").equals("") ? null : new PSBT(Z85.getInstance().decode(obj.getString("psbt")), params);
if (this.psbt != null) {
this.psbt.read();
}
}
} catch (JSONException je) {
je.printStackTrace();
} catch (Exception e) {
// throw new RuntimeException(e);
}
}
use of com.samourai.wallet.cahoots.psbt.PSBT in project samourai-wallet-android by Samourai-Wallet.
the class CahootsUtil method doPSBT.
public void doPSBT(final String strPSBT) {
String msg = null;
PSBT psbt = new PSBT(strPSBT, SamouraiWallet.getInstance().getCurrentNetworkParams());
try {
psbt.read();
msg = psbt.dump();
} catch (Exception e) {
msg = e.getMessage();
}
final EditText edPSBT = new EditText(context);
edPSBT.setSingleLine(false);
edPSBT.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
edPSBT.setLines(10);
edPSBT.setHint(R.string.PSBT);
edPSBT.setGravity(Gravity.START);
TextWatcher textWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
edPSBT.setSelection(0);
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
;
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
;
}
};
edPSBT.addTextChangedListener(textWatcher);
edPSBT.setText(msg);
AlertDialog.Builder dlg = new AlertDialog.Builder(context).setTitle(R.string.app_name).setMessage(R.string.PSBT).setView(edPSBT).setCancelable(true).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
if (!((Activity) context).isFinishing()) {
dlg.show();
}
}
use of com.samourai.wallet.cahoots.psbt.PSBT in project samourai-wallet-android by Samourai-Wallet.
the class Stowaway method doStep1.
//
// receiver
//
public boolean doStep1(HashMap<_TransactionOutPoint, Triple<byte[], byte[], String>> inputs, HashMap<_TransactionOutput, Triple<byte[], byte[], String>> outputs) throws Exception {
if (this.getStep() != 0 || this.getSpendAmount() == 0L) {
return false;
}
if (this.getType() == Cahoots.CAHOOTS_STONEWALLx2 && outputs == null) {
return false;
}
Transaction transaction = new Transaction(params);
for (_TransactionOutPoint outpoint : inputs.keySet()) {
TransactionInput input = new TransactionInput(params, null, new byte[0], outpoint, outpoint.getValue());
Log.d("Stowaway", "input value:" + input.getValue().longValue());
transaction.addInput(input);
outpoints.put(outpoint.getTxHash().toString() + "-" + outpoint.getTxOutputN(), outpoint.getValue().longValue());
}
for (_TransactionOutput output : outputs.keySet()) {
transaction.addOutput(output);
}
PSBT psbt = new PSBT(transaction);
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])));
}
this.psbt = psbt;
Log.d("Stowaway", "input value:" + psbt.getTransaction().getInputs().get(0).getValue().longValue());
this.setStep(1);
return true;
}
use of com.samourai.wallet.cahoots.psbt.PSBT in project samourai-wallet-android by Samourai-Wallet.
the class STONEWALLx2 method doStep1.
//
// counterparty
//
protected boolean doStep1(HashMap<_TransactionOutPoint, Triple<byte[], byte[], String>> inputs, HashMap<_TransactionOutput, Triple<byte[], byte[], String>> outputs) throws Exception {
if (this.getStep() != 0 || this.getSpendAmount() == 0L) {
return false;
}
if (this.getType() == Cahoots.CAHOOTS_STONEWALLx2 && outputs == null) {
return false;
}
Transaction transaction = new Transaction(params);
for (_TransactionOutPoint outpoint : inputs.keySet()) {
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 psbt = new PSBT(transaction);
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, cptyAccount, 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, cptyAccount, Integer.valueOf(s[1]), Integer.valueOf(s[2])));
}
this.psbt = psbt;
// Log.d("STONEWALLx2", "input value:" + psbt.getTransaction().getInputs().get(0).getValue().longValue());
this.setStep(1);
return true;
}
Aggregations