add txid and tx hex

This commit is contained in:
Uthpala Heenatigala 2023-01-06 00:34:24 +01:00
parent 57d345c149
commit 810b3a1a84
4 changed files with 55 additions and 6 deletions

View File

@ -5,7 +5,8 @@ from . import db
from .models import (
Token,
LnToBtcSwap,
BtcToLnSwap
BtcToLnSwap,
UpdateLnToBtcSwap
)
@ -83,6 +84,19 @@ async def save_ln_to_btc(
)
async def update_ln_to_btc(data: UpdateLnToBtcSwap) -> str:
await db.execute(
"""
UPDATE deezy.ln_to_btc_swap
SET txid = ?, tx_hex = ?
WHERE bolt11_invoice = ?
""",
(data.txid, data.tx_hex, data.bolt11_invoice),
)
return data.txid
async def save_btc_to_ln(
data: BtcToLnSwap,
) -> BtcToLnSwap:

View File

@ -18,6 +18,12 @@ class LnToBtcSwap(BaseModel):
created_at: str = ""
class UpdateLnToBtcSwap(BaseModel):
txid: str
tx_hex: str
bolt11_invoice: str
class BtcToLnSwap(BaseModel):
ln_address: str
on_chain_address: str

View File

@ -287,6 +287,19 @@
this.getBtcToLn()
},
methods: {
updateLnToBtc(payload) {
var self = this
return axios
.post('/deezy/api/v1/update-ln-to-btc', {
...payload
})
.then(function (response) {
console.log('btc to ln is update', response)
})
.catch(function (error) {
console.log(error)
})
},
getToken() {
var self = this
axios({
@ -337,13 +350,20 @@
.get(
`https://api.deezy.io/v1/swap/lookup?bolt11_invoice=${self.swapLnToBtc.response}`
)
.then(function (response) {
if (response.data.on_chain_txid || count > 4) {
.then(async function (response) {
if (response.data.on_chain_txid) {
self.swapLnToBtc = {
...self.swapLnToBtc,
invoicePaid: true,
onchainTxId: response.data.on_chain_txid
}
self.updateLnToBtc({
txid: response.data.on_chain_txid,
tx_hex: response.data.tx_hex,
bolt11_invoice: self.swapLnToBtc.response
}).then(() => {
self.getLnToBtc()
})
clearInterval(interval)
}
})

View File

@ -7,19 +7,21 @@
# response.is_error that is its inverse)
from . import deezy_ext
from . import db
from .models import (
Token,
LnToBtcSwap,
BtcToLnSwap
BtcToLnSwap,
UpdateLnToBtcSwap,
)
from .crud import (
get_token,
get_ln_to_btc,
get_btc_to_ln,
save_token,
save_btc_to_ln,
save_ln_to_btc
save_ln_to_btc,
update_ln_to_btc
)
@ -55,6 +57,13 @@ async def api_deezy(data: LnToBtcSwap):
return response
@deezy_ext.post("/api/v1/update-ln-to-btc")
async def api_deezy(data: UpdateLnToBtcSwap):
response = await update_ln_to_btc(data)
return response
@deezy_ext.post("/api/v1/store-btc-to-ln")
async def api_deezy(data: BtcToLnSwap):
response = await save_btc_to_ln(data)