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 ( from .models import (
Token, Token,
LnToBtcSwap, 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( async def save_btc_to_ln(
data: BtcToLnSwap, data: BtcToLnSwap,
) -> BtcToLnSwap: ) -> BtcToLnSwap:

View file

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

View file

@ -287,6 +287,19 @@
this.getBtcToLn() this.getBtcToLn()
}, },
methods: { 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() { getToken() {
var self = this var self = this
axios({ axios({
@ -337,13 +350,20 @@
.get( .get(
`https://api.deezy.io/v1/swap/lookup?bolt11_invoice=${self.swapLnToBtc.response}` `https://api.deezy.io/v1/swap/lookup?bolt11_invoice=${self.swapLnToBtc.response}`
) )
.then(function (response) { .then(async function (response) {
if (response.data.on_chain_txid || count > 4) { if (response.data.on_chain_txid) {
self.swapLnToBtc = { self.swapLnToBtc = {
...self.swapLnToBtc, ...self.swapLnToBtc,
invoicePaid: true, invoicePaid: true,
onchainTxId: response.data.on_chain_txid 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) clearInterval(interval)
} }
}) })

View file

@ -7,19 +7,21 @@
# response.is_error that is its inverse) # response.is_error that is its inverse)
from . import deezy_ext from . import deezy_ext
from . import db
from .models import ( from .models import (
Token, Token,
LnToBtcSwap, LnToBtcSwap,
BtcToLnSwap BtcToLnSwap,
UpdateLnToBtcSwap,
) )
from .crud import ( from .crud import (
get_token, get_token,
get_ln_to_btc, get_ln_to_btc,
get_btc_to_ln, get_btc_to_ln,
save_token, save_token,
save_btc_to_ln, 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 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") @deezy_ext.post("/api/v1/store-btc-to-ln")
async def api_deezy(data: BtcToLnSwap): async def api_deezy(data: BtcToLnSwap):
response = await save_btc_to_ln(data) response = await save_btc_to_ln(data)