Skip to content

Commit

Permalink
chore: add split function
Browse files Browse the repository at this point in the history
  • Loading branch information
AricRedemption committed Aug 28, 2024
1 parent 592d88d commit f382f47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/lib/wallets/btc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const split = async (feeRate: number, utxos: UTXO[]) => {
const addressType = wallet.getScriptType()
const payment = await createPayment(addressType)

const buildPsbt = async (utxos: UTXO[]) => {
const buildPsbt = async (utxos: UTXO[], fee: number) => {
const psbt = new Psbt({ network: btcNetwork })
let total = getTotalSatoshi(utxos)

Expand All @@ -83,7 +83,7 @@ export const split = async (feeRate: number, utxos: UTXO[]) => {
psbt.addOutput({
value: total
.minus(1999 * 1600)
.minus(68971 * 2)
.minus(fee)
.toNumber(),
address: address,
})
Expand All @@ -104,12 +104,12 @@ export const split = async (feeRate: number, utxos: UTXO[]) => {

let total = getTotalSatoshi(utxos)

let psbt = await buildPsbt(utxos)
let psbt = await buildPsbt(utxos, 0)

psbt = await buildPsbt(utxos)
console.log('virtualSize', psbt.extractTransaction().virtualSize())
psbt = await buildPsbt(utxos, Math.ceil(psbt.extractTransaction().virtualSize() * feeRate))
// console.log('virtualSize', psbt.extractTransaction().virtualSize())

console.log(Math.floor(new Decimal(68971 * 2).div(psbt.extractTransaction().virtualSize()).toNumber()))
// console.log(Math.floor(new Decimal(68971 * 2).div(psbt.extractTransaction().virtualSize()).toNumber()))

// return { txId: psbt.extractTransaction().getId() }

Expand Down
7 changes: 4 additions & 3 deletions src/pages/settings/components/BTCMerge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const mergeFn = async () => {
const splitFn = async () => {
if (feeRate.value && utxos.value) {
operationLock.value = true
await sleep(1000)
const { txId } = await split(feeRate.value, utxos.value)
operationLock.value = false
isOpenResultModal.value = true
Expand Down Expand Up @@ -217,16 +218,16 @@ const broadcast = () => {

<TransactionResultModal v-model:is-open-result="isOpenResultModal" :result="transactionResult" />
</div>
<!-- <button
<button
@click="splitFn"
:class="[
{ 'cursor-not-allowed opacity-50': false },
{ 'cursor-not-allowed opacity-50': mergeDisabled },
'bg-blue-primary text-white text-xs w-61.5 rounded-3xl my-12 py-4 mx-auto flex items-center justify-center gap-x-2',
]"
>
<ArrowPathIcon class="animate-spin w-4 h-4" v-if="operationLock" />
Split
</button> -->
</button>

<button
@click="mergeFn"
Expand Down

0 comments on commit f382f47

Please sign in to comment.