From 8b0c004883753623415a7dfb20f9f92556a043c5 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 2 Dec 2022 13:41:26 +0200 Subject: [PATCH] feat: allow external signed PSBT --- .../static/components/payment/payment.js | 22 ++++++- .../extensions/watchonly/static/js/index.js | 14 ++++- .../watchonly/templates/watchonly/index.html | 59 ++++++++++++++++++- 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/lnbits/extensions/watchonly/static/components/payment/payment.js b/lnbits/extensions/watchonly/static/components/payment/payment.js index 9f38df1d0..e9689003f 100644 --- a/lnbits/extensions/watchonly/static/components/payment/payment.js +++ b/lnbits/extensions/watchonly/static/components/payment/payment.js @@ -272,15 +272,35 @@ async function payment(path) { this.showChecking = false } }, + + fetchUtxoHexForPsbt: async function (psbtBase64) { + if (this.tx?.inputs && this.tx?.inputs.length) return this.tx.inputs + + const {data: psbtUtxos} = await LNbits.api.request( + 'PUT', + '/watchonly/api/v1/psbt/utxos', + this.adminkey, + {psbtBase64} + ) + + const inputs = [] + for (const utxo of psbtUtxos) { + const txHex = await this.fetchTxHex(utxo.tx_id) + inputs.push({tx_hex: txHex}) + } + return inputs + }, extractTxFromPsbt: async function (psbtBase64) { try { + const inputs = await this.fetchUtxoHexForPsbt(psbtBase64) + const {data} = await LNbits.api.request( 'PUT', '/watchonly/api/v1/psbt/extract', this.adminkey, { psbtBase64, - inputs: this.tx.inputs, + inputs, network: this.network } ) diff --git a/lnbits/extensions/watchonly/static/js/index.js b/lnbits/extensions/watchonly/static/js/index.js index 7e410104d..c87983030 100644 --- a/lnbits/extensions/watchonly/static/js/index.js +++ b/lnbits/extensions/watchonly/static/js/index.js @@ -54,7 +54,10 @@ const watchOnly = async () => { showPayment: false, fetchedUtxos: false, utxosFilter: '', - network: null + network: null, + + showEnterSignedPsbt: false, + signedBase64Psbt: null } }, computed: { @@ -173,6 +176,15 @@ const watchOnly = async () => { this.$refs.paymentRef.updateSignedPsbt(psbtBase64) }, + showEnterSignedPsbtDialog: function () { + this.showEnterSignedPsbt = true + }, + + checkPsbt: function () { + console.log('### checkPsbt', this.signedBase64Psbt) + this.$refs.paymentRef.updateSignedPsbt(this.signedBase64Psbt) + }, + //################### UTXOs ################### scanAllAddresses: async function () { await this.refreshAddresses() diff --git a/lnbits/extensions/watchonly/templates/watchonly/index.html b/lnbits/extensions/watchonly/templates/watchonly/index.html index 67f898101..3dab74d56 100644 --- a/lnbits/extensions/watchonly/templates/watchonly/index.html +++ b/lnbits/extensions/watchonly/templates/watchonly/index.html @@ -52,14 +52,37 @@ >
- New Payment + + + + New Payment + Create a new payment by selecting Inputs and + Outputs + + + + + From Signed PSBT + Paste a signed PSBT + + + + + + + +
Enter the Signed PSBT
+
+ +

+ +

+ +
+ Check PSBT + Close +
+
+
+
+ {% endraw %}