synonymdev / beignet

An instant, self-custodial Bitcoin wallet for JS devs.
MIT License
22 stars 6 forks source link

fix: do not re-query data for confirmed transactions #67

Closed limpbrains closed 5 months ago

limpbrains commented 5 months ago

Each time Beignet refreshes the wallet, it queries data to format all the transactions, even if they are already confirmed. I'm adding a filter to refresh only those with height < 6.

The downside is that we will no longer have an accurate value for tx.height, but we don't really need it. We don't use it in Bitkit, and I'm adding tx.blockhash, so we can always query it if needed.

Should I rename tx.height to tx._height to mark that it is internal?

coreyphillips commented 5 months ago

We should leave tx.height as-is. When running wallet.data.transactions we should receive transactions for the given wallet for applications to use and create a tx list so we should not remove height from the object.

The height is updated once confirmed as seen here when reading wallet.data.transactions:

a4511d60bac6c2e314e1316a6ea93267286c351478e7218cd4e4dc472c44e577: {
    address: 'bcrt1pkh7tcgrrpfsff6x6v7a5dwhv59x0ym4r8d3snsq2855qamyn8drqfaevyd',
    height: 26309,
    scriptHash: '7d012f46014cbaf6dbe1150242f47e9c8a47b20dfc30536c97e34197654a45f3',
    totalInputValue: 0.0939287,
    matchedInputValue: 0.0939287,
    totalOutputValue: 0.0939172,
    matchedOutputValue: 0.0937172,
    fee: 0.0000115,
    satsPerByte: 7,
    type: 'sent',
    value: -0.0002115,
    txid: 'a4511d60bac6c2e314e1316a6ea93267286c351478e7218cd4e4dc472c44e577',
    messages: [],
    timestamp: 1718185834000,
    confirmTimestamp: 1718185834000,
    vin: [ [Object] ],
    rbf: false,
    exists: true,
    vsize: 154
  }
limpbrains commented 5 months ago

Removed any warning, add tests

limpbrains commented 5 months ago

I was testing bitkit + beignet with this patch. I restored abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about wallet Then I was able to do 10 full rescans without hitting limits on our electrum server.