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

CU-86du7e4k8 BSEthereum - Implement new BlockchainDataService for Neo… #78

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/blockchain-service",
"comment": "Implement new BlockchainDataService for NeoX using Blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/blockchain-service"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Implement new BlockchainDataService for NeoX using Blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo-legacy",
"comment": "Implement new BlockchainDataService for NeoX using Blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/bs-neo-legacy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Implement new BlockchainDataService for NeoX using Blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/bs-neo3"
}
4 changes: 2 additions & 2 deletions packages/blockchain-service/src/BSAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export class BSAggregator<

if (index !== 0) {
try {
const { totalCount } = await service.blockchainDataService.getTransactionsByAddress({
const { transactions } = await service.blockchainDataService.getTransactionsByAddress({
address: generatedAccount.address,
})
if (!totalCount || totalCount <= 0) hasError = true
if (!transactions || transactions.length <= 0) hasError = true
} catch {
hasError = true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './interfaces'
export * from './BSAggregator'
export * from './functions'
export * from './CryptoCompareEDS'
export * from './functions'
export * from './interfaces'
7 changes: 2 additions & 5 deletions packages/blockchain-service/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,12 @@ export type ContractParameter = {
type: string
}
export type TransactionsByAddressResponse = {
totalCount?: number
limit?: number
nextCursor?: string
transactions: TransactionResponse[]
nextPageParams?: any
}
export type TransactionsByAddressParams = {
address: string
page?: number
cursor?: string
nextPageParams?: any
}
export type ContractMethod = {
name: string
Expand Down
12 changes: 10 additions & 2 deletions packages/bs-ethereum/src/BSEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import Transport from '@ledgerhq/hw-transport'
import { BSEthereumNetworkId, BSEthereumHelper } from './BSEthereumHelper'
import { MoralisBDSEthereum } from './MoralisBDSEthereum'
import { MoralisEDSEthereum } from './MoralisEDSEthereum'
import { BlockscoutNeoXBDSEthereum } from './BlockscoutNeoXBDSEthereum'
import { BlockscoutNeoXEDSEthereum } from './BlockscoutNeoXEDSEthereum'

export class BSEthereum<BSCustomName extends string = string>
implements
Expand Down Expand Up @@ -68,8 +70,14 @@ export class BSEthereum<BSCustomName extends string = string>

this.network = network

this.blockchainDataService = new MoralisBDSEthereum(network)
this.exchangeDataService = new MoralisEDSEthereum(network, this.blockchainDataService)
if (BlockscoutNeoXBDSEthereum.isSupported(network)) {
this.exchangeDataService = new BlockscoutNeoXEDSEthereum(network)
this.blockchainDataService = new BlockscoutNeoXBDSEthereum(network)
} else {
this.exchangeDataService = new MoralisEDSEthereum(network, this.blockchainDataService)
this.blockchainDataService = new MoralisBDSEthereum(network)
}

this.nftDataService = new GhostMarketNDSEthereum(network)
}

Expand Down
32 changes: 19 additions & 13 deletions packages/bs-ethereum/src/BSEthereumHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export type BSEthereumNetworkId = NetworkId<
| '43114'
| '59144'
| '11155111'
| '12227331'
| '47763'
| '12227332'
>

export class BSEthereumHelper {
Expand All @@ -40,7 +41,8 @@ export class BSEthereumHelper {
'43114': 'AVAX',
'59144': 'ETH',
'11155111': 'ETH',
'12227331': 'GAS',
'47763': 'GAS',
'12227332': 'GAS',
}

static #RPC_LIST_BY_NETWORK_ID: Record<BSEthereumNetworkId, string[]> = {
Expand Down Expand Up @@ -132,21 +134,28 @@ export class BSEthereumHelper {
'https://1rpc.io/sepolia',
'https://eth-sepolia.api.onfinality.io/public',
],
'12227331': ['https://neoxseed1.ngd.network'],
'47763': ['https://mainnet-1.rpc.banelabs.org'],
'12227332': ['https://neoxt4seed1.ngd.network'],
}

static DERIVATION_PATH = "m/44'/60'/0'/0/?"
static DEFAULT_PATH = "44'/60'/0'/0/0"

static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId = '12227331'
static NEOX_NETWORK_IDS: BSEthereumNetworkId[] = [this.NEOX_TESTNET_NETWORK_ID]
static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId = '12227332'
static NEOX_MAINNET_NETWORK_ID: BSEthereumNetworkId = '47763'
static NEOX_NETWORK_IDS: BSEthereumNetworkId[] = [this.NEOX_TESTNET_NETWORK_ID, this.NEOX_MAINNET_NETWORK_ID]

static NEOX_TESTNET_NETWORK: Network<BSEthereumNetworkId> = {
id: this.NEOX_TESTNET_NETWORK_ID,
name: 'NeoX Testnet',
url: this.#RPC_LIST_BY_NETWORK_ID[this.NEOX_TESTNET_NETWORK_ID][0],
}
static NEOX_NETWORKS: Network<BSEthereumNetworkId>[] = [this.NEOX_TESTNET_NETWORK]
static NEOX_MAINNET_NETWORK: Network<BSEthereumNetworkId> = {
id: this.NEOX_MAINNET_NETWORK_ID,
name: 'NeoX Mainnet',
url: this.#RPC_LIST_BY_NETWORK_ID[this.NEOX_MAINNET_NETWORK_ID][0],
}
static NEOX_NETWORKS: Network<BSEthereumNetworkId>[] = [this.NEOX_TESTNET_NETWORK, this.NEOX_MAINNET_NETWORK]

static MAINNET_NETWORK_IDS: BSEthereumNetworkId[] = [
'1',
Expand All @@ -160,14 +169,9 @@ export class BSEthereumHelper {
'42220',
'43114',
'59144',
this.NEOX_MAINNET_NETWORK_ID,
]
static TESTNET_NETWORK_IDS: BSEthereumNetworkId[] = [
'1101',
'80002',
'11155111',
'12227331',
this.NEOX_TESTNET_NETWORK_ID,
]
static TESTNET_NETWORK_IDS: BSEthereumNetworkId[] = ['1101', '80002', '11155111', this.NEOX_TESTNET_NETWORK_ID]
static ALL_NETWORK_IDS: BSEthereumNetworkId[] = [...this.MAINNET_NETWORK_IDS, ...this.TESTNET_NETWORK_IDS]

static MAINNET_NETWORKS: Network<BSEthereumNetworkId>[] = [
Expand Down Expand Up @@ -226,6 +230,7 @@ export class BSEthereumHelper {
name: 'Linea Mainnet',
url: this.#RPC_LIST_BY_NETWORK_ID['59144'][0],
},
this.NEOX_MAINNET_NETWORK,
]
static TESTNET_NETWORKS: Network<BSEthereumNetworkId>[] = [
{
Expand All @@ -251,6 +256,7 @@ export class BSEthereumHelper {

static getNativeAsset(network: Network<BSEthereumNetworkId>) {
const symbol = this.getNativeSymbol(network)

return { ...this.#NATIVE_ASSET, symbol, name: symbol }
}

Expand Down
Loading
Loading