-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add base blockchain support + blockscout explorer abi
- Loading branch information
Showing
25 changed files
with
351 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Framework Ethereum Package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { BlockchainFrameworkImplementation } from '@aleph-indexer/framework' | ||
import { baseFetcherClientFactory } from './src/services/fetcher/client.js' | ||
import { baseIndexerClientFactory } from './src/services/indexer/client.js' | ||
import { baseParserClientFactory } from './src/services/parser/client.js' | ||
import { baseFetcherFactory } from './src/services/fetcher/factory.js' | ||
import { baseIndexerFactory } from './src/services/indexer/factory.js' | ||
import { baseParserFactory } from './src/services/parser/factory.js' | ||
import { baseWorkerDomainFactory } from './src/domain/worker.js' | ||
|
||
export * from './src/domain/worker.js' | ||
export * from './src/services/fetcher/index.js' | ||
export * from './src/services/parser/index.js' | ||
export * from './src/services/indexer/index.js' | ||
|
||
export default { | ||
fetcher: { | ||
main: baseFetcherFactory, | ||
client: baseFetcherClientFactory, | ||
}, | ||
parser: { | ||
main: baseParserFactory, | ||
client: baseParserClientFactory, | ||
}, | ||
indexer: { | ||
main: baseIndexerFactory, | ||
client: baseIndexerClientFactory, | ||
domain: { | ||
worker: baseWorkerDomainFactory, | ||
main: null, | ||
}, | ||
}, | ||
} as BlockchainFrameworkImplementation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "@aleph-indexer/base", | ||
"version": "1.1.11", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"type": "module", | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "ALEPH.im", | ||
"license": "ISC", | ||
"peerDependencies": { | ||
"graphql": "^15.8.0", | ||
"graphql-type-json": "^0.3.2", | ||
"luxon": "3.2.1" | ||
}, | ||
"devDependencies": { | ||
"@types/luxon": "3.2.0", | ||
"@types/node": "^17.0.33", | ||
"graphql": "^15.8.0", | ||
"graphql-type-json": "^0.3.2", | ||
"luxon": "3.2.1" | ||
}, | ||
"dependencies": { | ||
"@aleph-indexer/core": "^1.1.10", | ||
"@aleph-indexer/ethereum": "^1.1.11", | ||
"@aleph-indexer/framework": "^1.1.11", | ||
"moleculer": "^0.14.24" | ||
}, | ||
"typedoc": { | ||
"entryPoint": "./index.ts", | ||
"displayName": "Base Indexer Framework" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './worker.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ParserContext } from '@aleph-indexer/framework' | ||
import { | ||
BaseParsedLog, | ||
BaseParsedTransaction, | ||
} from '../services/parser/src/types.js' | ||
|
||
export type BaseTransactionIndexerWorkerDomainI = { | ||
baseTransactionBufferLength?: number // default 1000 | ||
baseFilterTransaction( | ||
context: ParserContext, | ||
entity: BaseParsedTransaction, | ||
): Promise<boolean> | ||
baseIndexTransactions( | ||
context: ParserContext, | ||
entities: BaseParsedTransaction[], | ||
): Promise<void> | ||
} | ||
|
||
export type BaseLogIndexerWorkerDomainI = { | ||
baseLogBufferLength?: number // default 1000 | ||
baseFilterLog(context: ParserContext, entity: BaseParsedLog): Promise<boolean> | ||
baseIndexLogs( | ||
context: ParserContext, | ||
entities: BaseParsedLog[], | ||
): Promise<void> | ||
} | ||
|
||
export type BaseIndexerWorkerDomainI = BaseTransactionIndexerWorkerDomainI & | ||
BaseLogIndexerWorkerDomainI | ||
|
||
export { ethereumWorkerDomainFactory as baseWorkerDomainFactory } from '@aleph-indexer/ethereum' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { BlockchainId } from '@aleph-indexer/framework' | ||
import { | ||
EthereumAccountTransactionHistoryStorage, | ||
EthereumClient, | ||
EthereumClientOptions, | ||
EthereumLogBloomStorage, | ||
} from '@aleph-indexer/ethereum' | ||
|
||
export class BaseClient extends EthereumClient { | ||
protected genesisBlockTimestamp = 1686789347000 | ||
|
||
constructor( | ||
protected blockchainId: BlockchainId, | ||
protected options: EthereumClientOptions, | ||
protected accountSignatureDAL?: EthereumAccountTransactionHistoryStorage, | ||
protected logBloomDAL?: EthereumLogBloomStorage, | ||
) { | ||
super(blockchainId, options, accountSignatureDAL, logBloomDAL) | ||
|
||
// @note: Quick fix for BASE it doesn't affect ethereum | ||
// Take a look at https://github.com/web3/web3.js/pull/3948#issuecomment-821779691 | ||
// @note: Take a look at: | ||
// @note: https://github.com/web3/web3.js/pull/3948#issuecomment-821779691 | ||
console.log('⚡️ monkey patched "web3-utils" "hexToNumber" for BASE chain') | ||
|
||
const hexToNumberOld = this.sdk.utils.hexToNumber | ||
this.sdk.utils.hexToNumber = function (value) { | ||
try { | ||
return hexToNumberOld(value) | ||
} catch (e: any) { | ||
if (e?.message !== 'Number can only safely store up to 53 bits') throw e | ||
return Number.MAX_SAFE_INTEGER | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './client.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ethereumFetcherClientFactory } from '@aleph-indexer/ethereum' | ||
|
||
export { ethereumFetcherClientFactory as baseFetcherClientFactory } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import { ServiceBroker } from 'moleculer' | ||
import { Utils } from '@aleph-indexer/core' | ||
import { | ||
BlockchainFetcherI, | ||
FetcherMsClient, | ||
BlockchainId, | ||
getBlockchainEnv | ||
} from '@aleph-indexer/framework' | ||
import { ethereumConfigFactory, ethereumDalsFetcherFactory, ethereumFetcherInstanceFactory } from '@aleph-indexer/ethereum' | ||
import { BaseClient } from '../../sdk/index.js' | ||
|
||
export function baseClientFetcherFactory( | ||
blockchainId: BlockchainId, | ||
config: ReturnType<typeof ethereumConfigFactory>, | ||
DALs: ReturnType<typeof ethereumDalsFetcherFactory>): BaseClient { | ||
const url = getBlockchainEnv(blockchainId, 'RPC', true) | ||
|
||
return new BaseClient( | ||
blockchainId, | ||
{ ...config, url }, | ||
DALs.accountTransactionHistoryDAL, | ||
DALs.logBloomDAL | ||
) | ||
} | ||
|
||
export async function baseFetcherFactory( | ||
blockchainId: BlockchainId, | ||
basePath: string, | ||
broker: ServiceBroker, | ||
fetcherClient: FetcherMsClient, | ||
): Promise<BlockchainFetcherI> { | ||
if (basePath) await Utils.ensurePath(basePath) | ||
|
||
// Config | ||
|
||
const config = ethereumConfigFactory(blockchainId) | ||
|
||
// DALs | ||
|
||
const DALs = ethereumDalsFetcherFactory(basePath) | ||
|
||
// Instances | ||
|
||
const baseClient = baseClientFetcherFactory( | ||
blockchainId, | ||
config, | ||
DALs | ||
) | ||
|
||
return ethereumFetcherInstanceFactory( | ||
blockchainId, | ||
broker, | ||
fetcherClient, | ||
baseClient, | ||
config, | ||
DALs | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './client.js' | ||
export * from './factory.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ethereumIndexerClientFactory } from '@aleph-indexer/ethereum' | ||
|
||
export { ethereumIndexerClientFactory as baseIndexerClientFactory } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ethereumIndexerFactory } from '@aleph-indexer/ethereum' | ||
|
||
export { ethereumIndexerFactory as baseIndexerFactory } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './client.js' | ||
export * from './factory.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ethereumParserClientFactory } from '@aleph-indexer/ethereum' | ||
|
||
export { ethereumParserClientFactory as baseParserClientFactory } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import { BlockchainId, BlockchainParserI, getBlockchainEnv } from '@aleph-indexer/framework' | ||
import {ethereumAbiParserFactory, ethereumParserInstanceFactory } from '@aleph-indexer/ethereum' | ||
import { BaseClient } from '../../sdk/index.js' | ||
import { BaseParsedTransaction, BaseRawTransaction } from './src/types.js' | ||
|
||
export function baseClientParserFactory( | ||
blockchainId: BlockchainId, | ||
): BaseClient { | ||
const url = getBlockchainEnv(blockchainId, 'RPC', true) | ||
|
||
return new BaseClient(blockchainId, { url }) | ||
} | ||
|
||
export async function baseParserFactory( | ||
blockchainId: BlockchainId, | ||
basePath: string, | ||
layoutPath?: string, | ||
): Promise< | ||
BlockchainParserI< | ||
BaseRawTransaction, | ||
BaseParsedTransaction | ||
> | ||
> { | ||
const baseClient = baseClientParserFactory(blockchainId) | ||
|
||
const baseAbiFactory = await ethereumAbiParserFactory( | ||
blockchainId, | ||
baseClient, | ||
basePath, | ||
layoutPath | ||
) | ||
|
||
return ethereumParserInstanceFactory( | ||
blockchainId, | ||
baseClient, | ||
baseAbiFactory, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './client.js' | ||
export * from './factory.js' | ||
export * from './src/types.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { | ||
EthereumParsedAccountState, | ||
EthereumParsedLog, | ||
EthereumParsedTransaction, | ||
EthereumRawTransaction, | ||
} from '@aleph-indexer/ethereum' | ||
|
||
export type BaseRawTransaction = EthereumRawTransaction | ||
export type BaseParsedTransaction = EthereumParsedTransaction | ||
export type BaseParsedLog = EthereumParsedLog | ||
export type BaseParsedAccountState = EthereumParsedAccountState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"dist", | ||
"scripts", | ||
"tests", | ||
"**/*.spec.ts", | ||
"**/*.test.ts", | ||
"**/__tests__", | ||
"**/__mocks__" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '../../types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.