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: Add Bitcoin indexing #215

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

feat: Add Bitcoin indexing #215

wants to merge 19 commits into from

Conversation

mj52951
Copy link
Contributor

@mj52951 mj52951 commented Sep 9, 2024

Added Bitcoin indexing functionality.

closes #201
closes #202
closes #203

src/indexer/config/index.ts Outdated Show resolved Hide resolved
src/indexer/index.ts Outdated Show resolved Hide resolved
src/indexer/index.ts Outdated Show resolved Hide resolved
src/indexer/services/bitcoinIndexer/bitcoinIndexer.ts Outdated Show resolved Hide resolved
src/indexer/services/bitcoinIndexer/bitcoinIndexer.ts Outdated Show resolved Hide resolved
}
}

function decodeDepositEvent(tx: Transaction, domain: Domain): DecodedDeposit | undefined {
Copy link
Contributor

@mpetrun5 mpetrun5 Sep 10, 2024

Choose a reason for hiding this comment

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

I think it is more intuitive to throw errors for unexpected behaviours instead of returning undefined and then we don't what happened. Also, would remove the need to have decoding and then undefined checks in saveEvents
Probably decoding errors will need to be caught and handled appropriately in saveEvents and logged as warn as we most likely don't want to try decoding that again, but at least we will know what happened.

Copy link
Contributor Author

@mj52951 mj52951 Sep 11, 2024

Choose a reason for hiding this comment

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

Hm, I might've made a bad approach for the whole workflow then. But what this is essentially doing is checking if the output address is the relayer address (resourceFound) and if it is, it parses and returns the data so it can be stored in the database. If it isn't, it returns undefined. So it'll return undefined for every transaction that isn't actually a Sygma deposit.

try {
amountInUSD = await coinMakerCapService.getValueInUSD(decodedDeposit.amount.toString(), decodedDeposit.resource.symbol)
} catch (error) {
logger.error((error as Error).message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some description of where and why it happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Coinmarketcap service functions already log the whole URL that was unsuccessfully fetched and additionally throw the message Error getting value from CoinMarketCap which is shown to be caught and logged here so not sure should I provide any more context?

}
}

async function saveDeposit(
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we have this logic somewhere else as well.
See if it can be reused instead of copied.

Copy link
Contributor Author

@mj52951 mj52951 Sep 11, 2024

Choose a reason for hiding this comment

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

Yes, something like getUpdatedTransfer function was in the squid-indexer repo. Just, that would require a partial refactor of evm and substrate parts also, so not sure should I do it in this PR ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is a big refactor I would avoid it/do it separetly for now.

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 it's better to do it in a separate PR. Along with refactoring saveProposalExecution functions.

src/indexer/utils/bitcoin/index.ts Show resolved Hide resolved
return executionData
}

async function saveProposalExecution(
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of this save functions have basically the same logic as other networks.
Would be prudent to check if it can be unified.

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 it's better to do it in a separate PR. Along with refactoring saveDeposit functions.

@mj52951 mj52951 force-pushed the mj52951/bitcoin-indexing branch from 58af62e to 49831c2 Compare September 11, 2024 07:15
@mj52951 mj52951 marked this pull request as ready for review September 19, 2024 07:23
@mj52951 mj52951 requested a review from mpetrun5 September 19, 2024 07:43
@mj52951 mj52951 marked this pull request as draft September 19, 2024 07:54
@mj52951 mj52951 marked this pull request as ready for review September 19, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants