diff --git a/rollup.config.js b/rollup.config.js index 8a2ccbf..56fbf4c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -10,12 +10,15 @@ export default { { file: 'dist/MerkleProof2019.js', format: 'cjs', - name: 'MerkleProof2019' + name: 'MerkleProof2019', + exports: 'named', + sourcemap: true }, { file: 'dist/MerkleProof2019-es.js', format: 'es', - name: 'MerkleProof2019' + name: 'MerkleProof2019', + sourcemap: true } ], plugins: [ diff --git a/src/explorers/bitcoin/bitpay.ts b/src/explorers/bitcoin/bitpay.ts index a64538e..b414586 100644 --- a/src/explorers/bitcoin/bitpay.ts +++ b/src/explorers/bitcoin/bitpay.ts @@ -1,11 +1,10 @@ import { stripHashPrefix } from '../../utils/stripHashPrefix'; import { timestampToDateObject } from '../../utils/date'; -import { ExplorerAPI, ExplorerURLs } from '../../models/Explorers'; +import { ExplorerAPI, ExplorerURLs, IParsingFunctionAPI } from '../../models/Explorers'; import { TransactionData } from '../../models/TransactionData'; import { TRANSACTION_APIS, TRANSACTION_ID_PLACEHOLDER } from '../../constants/api'; import CONFIG from '../../constants/config'; import { BLOCKCHAINS } from '../../constants/blockchains'; -import { IParsingFunctionAPI } from '../explorer'; // TODO: use tests/explorers/mocks/mockBitpayResponse as type function parsingFunction ({ jsonResponse }: IParsingFunctionAPI): TransactionData { diff --git a/src/explorers/bitcoin/blockcypher.ts b/src/explorers/bitcoin/blockcypher.ts index ee7272d..df82b51 100644 --- a/src/explorers/bitcoin/blockcypher.ts +++ b/src/explorers/bitcoin/blockcypher.ts @@ -1,11 +1,10 @@ import { stripHashPrefix } from '../../utils/stripHashPrefix'; import { dateToUnixTimestamp } from '../../utils/date'; -import { ExplorerAPI, ExplorerURLs } from '../../models/Explorers'; +import { ExplorerAPI, ExplorerURLs, IParsingFunctionAPI } from '../../models/Explorers'; import { TransactionData } from '../../models/TransactionData'; import { TRANSACTION_APIS, TRANSACTION_ID_PLACEHOLDER } from '../../constants/api'; import CONFIG from '../../constants/config'; import { BLOCKCHAINS } from '../../constants/blockchains'; -import { IParsingFunctionAPI } from '../explorer'; // TODO: use tests/explorers/mocks/mockBlockcypher as type function parsingFunction ({ jsonResponse }: IParsingFunctionAPI): TransactionData { diff --git a/src/explorers/bitcoin/blockexplorer.ts b/src/explorers/bitcoin/blockexplorer.ts index 8d5b4f3..25facd7 100644 --- a/src/explorers/bitcoin/blockexplorer.ts +++ b/src/explorers/bitcoin/blockexplorer.ts @@ -1,11 +1,10 @@ import { stripHashPrefix } from '../../utils/stripHashPrefix'; import { timestampToDateObject } from '../../utils/date'; -import { ExplorerAPI, ExplorerURLs } from '../../models/Explorers'; +import { ExplorerAPI, ExplorerURLs, IParsingFunctionAPI } from '../../models/Explorers'; import { TransactionData } from '../../models/TransactionData'; import { TRANSACTION_APIS, TRANSACTION_ID_PLACEHOLDER } from '../../constants/api'; import { BLOCKCHAINS } from '../../constants/blockchains'; import CONFIG from '../../constants/config'; -import { IParsingFunctionAPI } from '../explorer'; // TODO: use tests/explorers/mocks/mockBlockexplorer as type function parsingFunction ({ jsonResponse }: IParsingFunctionAPI): TransactionData { diff --git a/src/explorers/bitcoin/blockstream.ts b/src/explorers/bitcoin/blockstream.ts index 8c85239..74a00cf 100644 --- a/src/explorers/bitcoin/blockstream.ts +++ b/src/explorers/bitcoin/blockstream.ts @@ -1,10 +1,9 @@ import { stripHashPrefix } from '../../utils/stripHashPrefix'; import { timestampToDateObject } from '../../utils/date'; -import { ExplorerAPI, ExplorerURLs } from '../../models/Explorers'; +import { ExplorerAPI, ExplorerURLs, IParsingFunctionAPI } from '../../models/Explorers'; import { TransactionData } from '../../models/TransactionData'; import { TRANSACTION_APIS, TRANSACTION_ID_PLACEHOLDER } from '../../constants/api'; import { BLOCKCHAINS } from '../../constants/blockchains'; -import { IParsingFunctionAPI } from '../explorer'; // TODO: use tests/explorers/mocks/mockBlockstreamResponse as type function parsingFunction ({ jsonResponse }: IParsingFunctionAPI): TransactionData { diff --git a/src/explorers/ethereum/blockcypher.ts b/src/explorers/ethereum/blockcypher.ts index d2ebbae..3798932 100644 --- a/src/explorers/ethereum/blockcypher.ts +++ b/src/explorers/ethereum/blockcypher.ts @@ -2,11 +2,10 @@ import { stripHashPrefix } from '../../utils/stripHashPrefix'; import { BLOCKCHAINS } from '../../constants/blockchains'; import { TransactionData } from '../../models/TransactionData'; import { TRANSACTION_APIS, TRANSACTION_ID_PLACEHOLDER } from '../../constants/api'; -import { ExplorerAPI, ExplorerURLs } from '../../models/Explorers'; +import { ExplorerAPI, ExplorerURLs, IParsingFunctionAPI } from '../../models/Explorers'; import CONFIG from '../../constants/config'; import { dateToUnixTimestamp } from '../../utils/date'; import { prependHashPrefix } from '../../utils/prependHashPrefix'; -import { IParsingFunctionAPI } from '../explorer'; const serviceURL: ExplorerURLs = { main: `https://api.blockcypher.com/v1/eth/main/txs/${TRANSACTION_ID_PLACEHOLDER}?limit=500`, diff --git a/src/explorers/ethereum/etherscan.ts b/src/explorers/ethereum/etherscan.ts index ad809e8..546fedf 100644 --- a/src/explorers/ethereum/etherscan.ts +++ b/src/explorers/ethereum/etherscan.ts @@ -4,9 +4,8 @@ import { buildTransactionServiceUrl } from '../../services/transaction-apis'; import { BLOCKCHAINS, isTestChain, SupportedChains } from '../../constants/blockchains'; import { TransactionData } from '../../models/TransactionData'; import { TRANSACTION_APIS, TRANSACTION_ID_PLACEHOLDER } from '../../constants/api'; -import { ExplorerAPI, ExplorerURLs } from '../../models/Explorers'; +import { ExplorerAPI, ExplorerURLs, IParsingFunctionAPI } from '../../models/Explorers'; import CONFIG from '../../constants/config'; -import { IParsingFunctionAPI } from '../explorer'; const MAIN_API_BASE_URL = 'https://api.etherscan.io/api?module=proxy'; const TEST_API_BASE_URL = 'https://api-ropsten.etherscan.io/api?module=proxy'; diff --git a/src/explorers/explorer.ts b/src/explorers/explorer.ts index 14e1045..85f4856 100644 --- a/src/explorers/explorer.ts +++ b/src/explorers/explorer.ts @@ -2,7 +2,7 @@ import { buildTransactionServiceUrl } from '../services/transaction-apis'; import { request } from '../services/request'; import { isTestChain, SupportedChains } from '../constants/blockchains'; import { TransactionData } from '../models/TransactionData'; -import { ExplorerAPI } from '../models/Explorers'; +import { ExplorerAPI, TExplorerFunctionsArray } from '../models/Explorers'; import { explorerApi as EtherscanApi } from './ethereum/etherscan'; import { explorerApi as BlockCypherETHApi } from './ethereum/blockcypher'; import { explorerApi as BlockExplorerApi } from './bitcoin/blockexplorer'; @@ -10,21 +10,6 @@ import { explorerApi as BlockstreamApi } from './bitcoin/blockstream'; import { explorerApi as BlockCypherBTCApi } from './bitcoin/blockcypher'; import { explorerApi as BitPayApi } from './bitcoin/bitpay'; -export type TExplorerFunctionsArray = Array<{ - getTxData: (transactionId: string, chain?: SupportedChains) => Promise; - priority?: number; -}>; -export interface IParsingFunctionAPI { - jsonResponse?: any; // the response from the service when called as rest - chain?: SupportedChains; // TODO: look at how to deprecate this. Only used in etherscan - key?: string; // identification key to pass to the service -> TODO: can this be merged into the serviceUrl? Only used in etherscan - keyPropertyName?: string; // the key property to associate with the identification key -> TODO: can this be merged into the serviceUrl? Only used in etherscan - transactionId?: string; // when using in RPCs we pass the tx id to look up since these functions are responsible for service lookup - serviceUrl?: string; // the distant service url -} -export type TExplorerParsingFunction = ((data: IParsingFunctionAPI) => TransactionData) | -((data: IParsingFunctionAPI) => Promise); - export function explorerFactory (TransactionAPIArray: ExplorerAPI[]): TExplorerFunctionsArray { return TransactionAPIArray .map(explorerAPI => ( diff --git a/src/explorers/index.ts b/src/explorers/index.ts index 0ce1623..0081cbe 100644 --- a/src/explorers/index.ts +++ b/src/explorers/index.ts @@ -1,11 +1,10 @@ import { BitcoinTransactionAPIArray as BitcoinExplorers, EthereumTransactionAPIArray as EthereumExplorers, - explorerFactory, - TExplorerFunctionsArray + explorerFactory } from './explorer'; import { TRANSACTION_APIS } from '../constants/api'; -import { ExplorerAPI } from '../models/Explorers'; +import { ExplorerAPI, TExplorerFunctionsArray } from '../models/Explorers'; import { ethereumRPCParsingFunction } from './rpc/ethereum'; import { bitcoinRPCParsingFunction } from './rpc/bitcoin'; diff --git a/src/explorers/rpc/bitcoin.ts b/src/explorers/rpc/bitcoin.ts index ebf3855..0e448f9 100644 --- a/src/explorers/rpc/bitcoin.ts +++ b/src/explorers/rpc/bitcoin.ts @@ -2,7 +2,7 @@ import { TransactionData } from '../../models/TransactionData'; import { stripHashPrefix } from '../../utils/stripHashPrefix'; import { timestampToDateObject } from '../../utils/date'; import { request } from '../../services/request'; -import { IParsingFunctionAPI } from '../explorer'; +import { IParsingFunctionAPI } from '../../models/Explorers'; export async function bitcoinRPCParsingFunction ({ serviceUrl, transactionId }: IParsingFunctionAPI): Promise { const getRawTransactionParams = { diff --git a/src/explorers/rpc/ethereum.ts b/src/explorers/rpc/ethereum.ts index c872d2d..d61366c 100644 --- a/src/explorers/rpc/ethereum.ts +++ b/src/explorers/rpc/ethereum.ts @@ -1,7 +1,7 @@ import { TransactionData } from '../../models/TransactionData'; import { stripHashPrefix } from '../../utils/stripHashPrefix'; import { request } from '../../services/request'; -import { IParsingFunctionAPI } from '../explorer'; +import { IParsingFunctionAPI } from '../../models/Explorers'; export async function ethereumRPCParsingFunction ({ serviceUrl, transactionId }: IParsingFunctionAPI): Promise { const transactionByHashParams = { diff --git a/src/helpers/lookForTx.ts b/src/helpers/lookForTx.ts index 9c49b04..59ac547 100644 --- a/src/helpers/lookForTx.ts +++ b/src/helpers/lookForTx.ts @@ -2,8 +2,8 @@ import { SupportedChains, BLOCKCHAINS } from '../constants/blockchains'; import CONFIG from '../constants/config'; import PromiseProperRace from './promiseProperRace'; import { TransactionData } from '../models/TransactionData'; -import { TExplorerFunctionsArray } from '../explorers/explorer'; import { TExplorerAPIs } from '../explorers'; +import { TExplorerFunctionsArray } from '../models/Explorers'; export function getExplorersByChain (chain: SupportedChains, explorerAPIs: TExplorerAPIs): TExplorerFunctionsArray { switch (chain) { diff --git a/src/models/Explorers.ts b/src/models/Explorers.ts index a8e6df7..2545b7d 100644 --- a/src/models/Explorers.ts +++ b/src/models/Explorers.ts @@ -1,11 +1,27 @@ import { TRANSACTION_APIS } from '../constants/api'; -import { TExplorerParsingFunction } from '../explorers/explorer'; +import { SupportedChains } from '../constants/blockchains'; +import { TransactionData } from './TransactionData'; export interface ExplorerURLs { main: string; test: string; } +export type TExplorerFunctionsArray = Array<{ + getTxData: (transactionId: string, chain?: SupportedChains) => Promise; + priority?: number; +}>; +export interface IParsingFunctionAPI { + jsonResponse?: any; // the response from the service when called as rest + chain?: SupportedChains; // TODO: look at how to deprecate this. Only used in etherscan + key?: string; // identification key to pass to the service -> TODO: can this be merged into the serviceUrl? Only used in etherscan + keyPropertyName?: string; // the key property to associate with the identification key -> TODO: can this be merged into the serviceUrl? Only used in etherscan + transactionId?: string; // when using in RPCs we pass the tx id to look up since these functions are responsible for service lookup + serviceUrl?: string; // the distant service url +} +export type TExplorerParsingFunction = ((data: IParsingFunctionAPI) => TransactionData) | +((data: IParsingFunctionAPI) => Promise); + export interface ExplorerAPI { serviceURL?: string | ExplorerURLs; priority?: 0 | 1 | -1; // 0: custom APIs will run before the default APIs, 1: after, -1: reserved to default APIs