Skip to content

Commit

Permalink
Merge pull request #35 from CityOfZion/CU-86a23fgy0
Browse files Browse the repository at this point in the history
CU-86a23fgy0 - Create a new Bitquery test account and update config to use it
  • Loading branch information
luc10921 authored Feb 2, 2024
2 parents 30188f4 + d259843 commit 7c3e9d6
Show file tree
Hide file tree
Showing 9 changed files with 873 additions and 854 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Change bitquery providers to receive apiKey on class initialization",
"type": "major"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
1,679 changes: 841 additions & 838 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions packages/bs-ethereum/src/BSEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ export class BSEthereum<BSCustomName extends string = string>
readonly blockchainName: BSCustomName
readonly feeToken: Token
readonly derivationPath: string
private readonly bitqueryApiKey: string

blockchainDataService!: BlockchainDataService
exchangeDataService!: ExchangeDataService
tokens: Token[]
nftDataService!: NftDataService
network!: Network

constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>) {
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, bitqueryApiKey: string) {
this.blockchainName = blockchainName
this.derivationPath = DERIVATION_PATH
this.tokens = TOKENS[network.type]
this.bitqueryApiKey = bitqueryApiKey

this.feeToken = this.tokens.find(token => token.symbol === 'ETH')!
this.setNetwork(network)
Expand All @@ -55,10 +57,10 @@ export class BSEthereum<BSCustomName extends string = string>
if (network.type === 'custom') {
this.blockchainDataService = new RpcBDSEthereum(network)
} else {
this.blockchainDataService = new BitqueryBDSEthereum(network)
this.blockchainDataService = new BitqueryBDSEthereum(network, this.bitqueryApiKey)
}

this.exchangeDataService = new BitqueryEDSEthereum(network.type)
this.exchangeDataService = new BitqueryEDSEthereum(network.type, this.bitqueryApiKey)
this.nftDataService = new GhostMarketNDSEthereum(network.type)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/bs-ethereum/src/BitqueryBDSEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@cityofzion/blockchain-service'
import { Client, fetchExchange } from '@urql/core'
import fetch from 'node-fetch'
import { BITQUERY_API_KEY, BITQUERY_NETWORK_BY_NETWORK_TYPE, BITQUERY_URL, NATIVE_ASSETS, TOKENS } from './constants'
import { BITQUERY_NETWORK_BY_NETWORK_TYPE, BITQUERY_URL, NATIVE_ASSETS, TOKENS } from './constants'
import {
BitqueryTransaction,
bitqueryGetBalanceQuery,
Expand All @@ -28,7 +28,7 @@ export class BitqueryBDSEthereum extends RpcBDSEthereum {

maxTimeToConfirmTransactionInMs: number = 1000 * 60 * 8

constructor(network: Network) {
constructor(network: Network, apiKey: string) {
super(network)

if (network.type === 'custom') throw new Error('Custom network not supported')
Expand All @@ -40,7 +40,7 @@ export class BitqueryBDSEthereum extends RpcBDSEthereum {
fetch,
fetchOptions: {
headers: {
'X-API-KEY': BITQUERY_API_KEY,
'X-API-KEY': apiKey,
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions packages/bs-ethereum/src/BitqueryEDSEthereum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service'
import { Client, fetchExchange } from '@urql/core'
import fetch from 'node-fetch'
import { BITQUERY_API_KEY, BITQUERY_URL } from './constants'
import { BITQUERY_URL } from './constants'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import { bitqueryGetPricesQuery } from './graphql'
Expand All @@ -11,7 +11,7 @@ export class BitqueryEDSEthereum implements ExchangeDataService {
private readonly client: Client
private readonly networkType: NetworkType

constructor(networkType: NetworkType) {
constructor(networkType: NetworkType, apiKey: string) {
this.networkType = networkType

this.client = new Client({
Expand All @@ -20,7 +20,7 @@ export class BitqueryEDSEthereum implements ExchangeDataService {
fetch,
fetchOptions: {
headers: {
'X-API-KEY': BITQUERY_API_KEY,
'X-API-KEY': apiKey,
},
},
})
Expand Down
7 changes: 5 additions & 2 deletions packages/bs-ethereum/src/__tests__/BDSEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { BitqueryBDSEthereum } from '../BitqueryBDSEthereum'
import { RpcBDSEthereum } from '../RpcBDSEthereum'
import { DEFAULT_URL_BY_NETWORK_TYPE } from '../constants'

const bitqueryBDSEthereum = new BitqueryBDSEthereum({ type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet })
const bitqueryBDSEthereum = new BitqueryBDSEthereum(
{ type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet },
process.env.BITQUERY_API_KEY as string
)
const rpcBDSEthereum = new RpcBDSEthereum({ type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet })

describe('BDSEthereum', () => {
Expand Down Expand Up @@ -79,7 +82,7 @@ describe('BDSEthereum', () => {
symbol: 'ETH',
name: 'Ethereum',
hash: '-',
decimals: 16,
decimals: 18,
})
}
)
Expand Down
6 changes: 4 additions & 2 deletions packages/bs-ethereum/src/__tests__/BSEthereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let account: Account

describe('BSEthereum', () => {
beforeAll(() => {
bsEthereum = new BSEthereum('neo3', { type: 'testnet' })
bsEthereum = new BSEthereum('neo3', { type: 'testnet' }, process.env.BITQUERY_API_KEY as string)
wallet = ethers.Wallet.createRandom()
account = {
key: wallet.privateKey,
Expand Down Expand Up @@ -71,7 +71,9 @@ describe('BSEthereum', () => {
it('Should be able to encrypt key', async () => {
const password = 'TestPassword'
const validEncryptedJson = await bsEthereum.encrypt(wallet.privateKey, password)
expect(validEncryptedJson).toEqual(expect.objectContaining({ address: wallet.address }))
expect(JSON.parse(validEncryptedJson)).toEqual(
expect.objectContaining({ address: wallet.address.replace('0x', '').toLowerCase() })
)
})

it.skip('Should be able to calculate transfer fee', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let bitqueryEDSEthereum: BitqueryEDSEthereum

describe('FlamingoEDSNeo3', () => {
beforeAll(() => {
bitqueryEDSEthereum = new BitqueryEDSEthereum('mainnet')
bitqueryEDSEthereum = new BitqueryEDSEthereum('mainnet', process.env.BITQUERY_API_KEY as string)
})

it('Should return a list with prices of tokens using USD', async () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/bs-ethereum/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ export const NATIVE_ASSETS = commom

export const DEFAULT_URL_BY_NETWORK_TYPE: Record<NetworkType, string> = {
mainnet: 'https://ethereum-mainnet-rpc.allthatnode.com',
testnet: 'https://ethereum-goerli-rpc.allthatnode.com',
testnet: 'https://ethereum-goerli.publicnode.com',
custom: 'http://127.0.0.1:8545',
}

export const BITQUERY_API_KEY = 'BQYMp76Ny15C8ORbI2BOstFUhoMCahLI'
export const BITQUERY_URL = 'https://graphql.bitquery.io'
export const BITQUERY_NETWORK_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, BitqueryNetwork> = {
mainnet: 'ethereum',
Expand Down

0 comments on commit 7c3e9d6

Please sign in to comment.