Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): fill backend todos #8

Merged
merged 5 commits into from
Jul 25, 2024
Merged

feat(backend): fill backend todos #8

merged 5 commits into from
Jul 25, 2024

Conversation

ShookLyngs
Copy link
Contributor

@ShookLyngs ShookLyngs commented Jul 24, 2024

TODOs

BitcoinAddress:

  • satoshi: Calculates via the BitcoinApiService.getAddressTxsUtxo() API
  • pendingSatoshi: Calculates via the BitcoinApiService.getAddressTxsUtxo() API
  • transactionCount: Calculates via the added BitcoinApiService.getAddress() API
  • transactions: Returns from the BitcoinApiService.getAddressTxs() API, the implementation comes with pagination and is different from the original design by @ahonn, because the resolver only returns up to 50 records; If the user wishes to load more, a afterTxid argument is available, like in the following code:
    {
      btcBlock(hashOrHeight: "0000000000000017b4ca3cf7748ffb59ba986670b288df26b3ea8cb850673cae") {
        miner {
          transactions(afterTxid: "14b6a01d23cb7046491653204a44d4896ce00896a5b630f38291c4d0c4919eb6") {
            txid
          }
        }
      }
    }

BitcoinBlock:

  • miner: Returns the vout[0].address of the first transaction in a block
  • feeRateRange: The calculation logic is written but we have trouble fetching from the data source; We can query the transactions of a block via the BitcoinApiService.getBlockTxs() API and summarize the results, but there are two issues blocking:
    1. The BitcoinApiService.getBlockTxs() API has pagination and only returns up to 25 records per request
      BitcoinBlockTransactionsLoader only returns the first 25 transactions of each block #9
    2. A block can contain hundreds of transactions, we could send tens of requests just for one block
  • totalFee: Same issue as above

BitcoinOutput:

  • address

TransactionService:

  • getTransactionByBtcTxid: Need to find the isomorphic CKB transaction using a txid, this feature looks very similar to the implementaion in btc-assets-api#182

@ShookLyngs ShookLyngs requested a review from Flouse July 24, 2024 21:25
Copy link

vercel bot commented Jul 24, 2024

@ShookLyngs is attempting to deploy a commit to the Cell Studio Team on Vercel.

To accomplish this, @ShookLyngs needs to request access to the Team.

Afterwards, an owner of the Team is required to accept their membership request.

If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.

Comment on lines 39 to 46
public async totalFee(
@Parent() block: BitcoinBaseBlock,
@Loader(BitcoinBlockTransactionsLoader)
blockTxsLoader: DataLoader<string, BitcoinBlockTransactionsLoaderResponse>,
): Promise<number> {
const txs = await blockTxsLoader.load(block.id);
return txs.reduce((sum, tx) => sum + tx.fee, 0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of https://mempool.space/docs/api/rest#get-block has a totalFees field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the version we use don't have totalFees and feeRange in the response; See: https://cell.mempool.space/testnet/api/block/0000000000000017b4ca3cf7748ffb59ba986670b288df26b3ea8cb850673cae

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored at: 502a512

}

@ResolveField(() => FeeRateRange)
public async feeRateRange(@Parent() block: BitcoinBaseBlock): Promise<FeeRateRange> {
// TODO: Implement this resolver
public async feeRateRange(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the feeRange field in the response of https://mempool.space/docs/api/rest#get-block?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored at: 502a512

@ShookLyngs
Copy link
Contributor Author

Conclusion after discussing with @Flouse:

  1. We can try to fetch the list of the block's txid[], then fetch each transaction and save to Redis; After all transactions have been fetched, we can use the stored data for the calculation of totalFee and feeRateRange
  2. We can leave the implementation of the TransactionService.getTransactionByBtcTxid() for later

@ShookLyngs ShookLyngs marked this pull request as ready for review July 25, 2024 06:26
@ShookLyngs ShookLyngs requested a review from Flouse July 25, 2024 06:26
@Flouse
Copy link
Contributor

Flouse commented Jul 25, 2024

  • We can try to fetch the list of the block's txid[], then fetch each transaction and save to Redis; After all transactions have been fetched, we can use the stored data for the calculation of totalFee and feeRateRange

or use https://mempool.space/testnet/api/v1/block/0000000000000017b4ca3cf7748ffb59ba986670b288df26b3ea8cb850673cae

@ShookLyngs
Copy link
Contributor Author

ShookLyngs commented Jul 25, 2024

The /v1/block/:hash route does contain the extras field. Now the totalFee and feeRateRange fields from the BitcoinBlockResolver have been refactored. Note that this field only exists in the mempool.space API, so it's expected to be undefined when the backend service is running in electrs mode.

{
  btcBlock(hashOrHeight: "0000000000000017b4ca3cf7748ffb59ba986670b288df26b3ea8cb850673cae") {
    totalFee
    feeRateRange {
      min
      max
    }
  }
}

@ShookLyngs ShookLyngs changed the title [WIP] feat: fill backend todos feat(backend): fill backend todos Jul 25, 2024
Copy link

vercel bot commented Jul 25, 2024

@Flouse is attempting to deploy a commit to the Cell Studio Team on Vercel.

To accomplish this, @Flouse needs to request access to the Team.

Afterwards, an owner of the Team is required to accept their membership request.

If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.

@Flouse Flouse merged commit de22171 into main Jul 25, 2024
3 of 4 checks passed
@Flouse Flouse deleted the feat/fill-backend-todos branch July 25, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants