-
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.
Merge pull request #94 from CityOfZion/CU-86duf6rpu
CU-86duf6rpu - BSEthereum - Implement a new ExplorerService to NeoX u…
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@cityofzion/bs-ethereum/CU-86duf6rpu_2024-09-02-15-56.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@cityofzion/bs-ethereum", | ||
"comment": "Added new explorer service to NeoX", | ||
"type": "patch" | ||
} | ||
], | ||
"packageName": "@cityofzion/bs-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
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,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}` | ||
} | ||
} |