Skip to content

Commit

Permalink
Add tx validation for flyover
Browse files Browse the repository at this point in the history
  • Loading branch information
lserra-iov authored and alexjavabraz committed Jan 22, 2025
1 parent ce01532 commit f2edad8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/common/services/FlyoverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,29 @@ export default class FlyoverService {
});
});
}

public validatePegin(quote: PeginQuote, signature: string, depositAddress: string, tx: string) {
return new Promise<string>((resolve, reject) => {
this.flyover?.validatePeginTransaction({
quoteInfo: {
quote: quote.originalQuote,
quoteHash: quote.quoteHash,
},
acceptInfo: {
signature,
bitcoinDepositAddressHash: depositAddress,
},
btcTx: tx,
})
.then(resolve)
.catch((error) => {
reject(new ServiceError(
'FlyoverService',
'validatePegin',
'There was an error validating the peg-in transaction, can not be completed.',
error.message,
));
});
});
}
}
3 changes: 3 additions & 0 deletions src/common/types/Flyover/PeginQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export default class PeginQuote implements QuotePegIn2WP {

quoteHash: string;

originalQuote;

constructor({ quote, quoteHash }: Quote) {
this.originalQuote = quote;
this.quote = {
...quote,
timeForDepositInSeconds: quote.timeForDeposit,
Expand Down
16 changes: 13 additions & 3 deletions src/pegin/components/create/ConfirmTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { Machine } from '@/common/utils';
import TxBuilder from '@/pegin/middleware/TxBuilder/TxBuilder';
import * as constants from '@/common/store/constants';
import { ApiService, WalletService } from '@/common/services';
import { ApiService, FlyoverService, WalletService } from '@/common/services';
import { useState, useGetter, useStateAttribute } from '@/common/store/helper';
import {
LiquidityProvider2WP,
Expand Down Expand Up @@ -67,6 +67,7 @@ export default defineComponent({
const recipientAddress = useStateAttribute<string>('flyoverPegin', 'rootstockRecipientAddress');
const peginType = useStateAttribute<string>('pegInTx', 'peginType');
const acceptedQuoteSignature = useStateAttribute<string>('flyoverPegin', 'acceptedQuoteSignature');
const flyoverService = useStateAttribute<FlyoverService>('flyoverPegin', 'flyoverService');
const isFlyover = computed(() => peginType.value === constants.peginType.FLYOVER);
function getLPName(): string {
Expand Down Expand Up @@ -128,8 +129,17 @@ export default defineComponent({
pegInTxState.value.selectedAccount,
))
.then((tx) => walletService.value.sign(tx))
.then(({ signedTx }) => ApiService
.broadcast(signedTx))
.then(async ({ signedTx }) => {
if (isFlyover.value) {
await flyoverService.value.validatePegin(
selectedQuote.value,
acceptedQuoteSignature.value,
pegInTxState.value.normalizedTx.outputs[0].address as string,
signedTx,
);
}
return ApiService.broadcast(signedTx);
})
.then((id) => {
ApiService.registerTx({
txHash: id,
Expand Down
2 changes: 1 addition & 1 deletion src/pegin/components/create/SendBitcoin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ export default defineComponent({
? selectedFlyoverQuote.value.quote.confirmations : 0,
},
});
clearWallets();
}
clearWallets();
}
function closeErrorDialog() {
Expand Down

0 comments on commit f2edad8

Please sign in to comment.