Skip to content

Commit

Permalink
Merge pull request #94 from CityOfZion/CU-86duf6rpu
Browse files Browse the repository at this point in the history
CU-86duf6rpu - BSEthereum - Implement a new ExplorerService to NeoX u…
  • Loading branch information
raulduartep authored Sep 2, 2024
2 parents c6f73fa + cbd284c commit 3ff6ebc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Added new explorer service to NeoX",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
8 changes: 7 additions & 1 deletion packages/bs-ethereum/src/BSEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import {
Account,
AccountWithDerivationPath,
BSCalculableFee,
BSWithExplorerService,
BSWithLedger,
BSWithNameService,
BSWithNft,
BlockchainDataService,
BlockchainService,
ExchangeDataService,
ExplorerService,
Network,
NftDataService,
Token,
Expand All @@ -25,14 +27,16 @@ import { MoralisBDSEthereum } from './MoralisBDSEthereum'
import { MoralisEDSEthereum } from './MoralisEDSEthereum'
import { BlockscoutNeoXBDSEthereum } from './BlockscoutNeoXBDSEthereum'
import { BlockscoutNeoXEDSEthereum } from './BlockscoutNeoXEDSEthereum'
import { BlockscoutNeoXESEthereum } from './BlockscoutNeoXESEthereum'

export class BSEthereum<BSCustomName extends string = string>
implements
BlockchainService<BSCustomName, BSEthereumNetworkId>,
BSWithNft,
BSWithNameService,
BSCalculableFee,
BSWithLedger
BSWithLedger,
BSWithExplorerService
{
readonly blockchainName: BSCustomName
readonly derivationPath: string
Expand All @@ -44,6 +48,7 @@ export class BSEthereum<BSCustomName extends string = string>
tokens!: Token[]
nftDataService!: NftDataService
network!: Network<BSEthereumNetworkId>
explorerService!: ExplorerService

constructor(
blockchainName: BSCustomName,
Expand Down Expand Up @@ -129,6 +134,7 @@ export class BSEthereum<BSCustomName extends string = string>
}

this.nftDataService = new GhostMarketNDSEthereum(network)
this.explorerService = new BlockscoutNeoXESEthereum(network)
}

validateAddress(address: string): boolean {
Expand Down
49 changes: 49 additions & 0 deletions packages/bs-ethereum/src/BlockscoutNeoXESEthereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { BuildNftUrlParams, ExplorerService, Network } from '@cityofzion/blockchain-service'
import { BSEthereumNetworkId } from './BSEthereumHelper'

export class BlockscoutNeoXESEthereum implements ExplorerService {
static BASE_URL_BY_CHAIN_ID: Partial<Record<BSEthereumNetworkId, string>> = {
'12227332': 'https://xt4scan.ngd.network',
'47763': 'https://xexplorer.neo.org',
}

static isSupported(network: Network<BSEthereumNetworkId>) {
return !!BlockscoutNeoXESEthereum.BASE_URL_BY_CHAIN_ID[network.id]
}

readonly #network: Network<BSEthereumNetworkId>

constructor(network: Network<BSEthereumNetworkId>) {
this.#network = network
}

buildTransactionUrl(hash: string): string {
if (!BlockscoutNeoXESEthereum.isSupported(this.#network)) {
throw new Error('Network not supported')
}

const baseURL = BlockscoutNeoXESEthereum.BASE_URL_BY_CHAIN_ID[this.#network.id]

return `${baseURL}/tx/${hash}`
}

buildContractUrl(contractHash: string): string {
if (!BlockscoutNeoXESEthereum.isSupported(this.#network)) {
throw new Error('Network not supported')
}

const baseURL = BlockscoutNeoXESEthereum.BASE_URL_BY_CHAIN_ID[this.#network.id]

return `${baseURL}/address/${contractHash}`
}

buildNftUrl(params: BuildNftUrlParams): string {
if (!BlockscoutNeoXESEthereum.isSupported(this.#network)) {
throw new Error('Network not supported')
}

const baseURL = BlockscoutNeoXESEthereum.BASE_URL_BY_CHAIN_ID[this.#network.id]

return `${baseURL}/token/${params.contractHash}/instance/${params.tokenId}`
}
}

0 comments on commit 3ff6ebc

Please sign in to comment.