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

WIP - Fix Amberdata #262

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
49 changes: 37 additions & 12 deletions src/ethereum/ethNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ export class EthereumNetwork {
const fromAddress = amberdataTx.from.address || ''
const toAddress = amberdataTx.to.length > 0 ? amberdataTx.to[0].address : ''

if (
!this.ethEngine.allTokens
.concat(this.ethEngine.customTokens)
.some(
metatoken =>
metatoken.contractAddress &&
metatoken.contractAddress.toLowerCase() ===
amberdataTx.contractCodeAddress.toLowerCase()
)
) {
this.ethEngine.log(
`processAmberdataTxInternal unsupported token ${amberdataTx.contractCodeAddress}`
)
throw new Error('Unsupported contract address')
}

if (fromAddress && toAddress) {
nativeNetworkFee = '0'

Expand Down Expand Up @@ -1465,18 +1481,17 @@ export class EthereumNetwork {
let url = `/addresses/${address}/${
searchRegularTxs ? 'transactions' : 'functions'
}?page=${page}&size=${NUM_TRANSACTIONS_TO_QUERY}`
const endDate = startDate + 2678400000 // Amberdata only supports searching 31 days at a time

if (searchRegularTxs) {
let cleanedResponseObj: FetchGetAmberdataApiResponse
try {
if (startDate) {
const newDateObj = new Date(startDate)
const now = new Date()
if (newDateObj) {
url =
url +
`&startDate=${newDateObj.toISOString()}&endDate=${now.toISOString()}`
}
url =
url +
`&startDate=${new Date(
startDate
).toISOString()}&endDate=${new Date(endDate).toISOString()}`
}

const jsonObj = await this.fetchGetAmberdataApi(url)
Expand Down Expand Up @@ -1508,15 +1523,20 @@ export class EthereumNetwork {
throw new Error('checkTxsAmberdata regular amberdataTx is invalid')
}
}
if (amberdataTxs.length === 0) {
if (endDate > Date.now()) {
break
}
page++
if (amberdataTxs.length === NUM_TRANSACTIONS_TO_QUERY) {
page++
} else {
page = 0
startDate = endDate
}
} else {
let cleanedResponseObj: FetchGetAmberdataApiResponse
try {
if (startDate) {
url = url + `&startDate=${startDate}&endDate=${Date.now()}`
url = url + `&startDate=${startDate}&endDate=${endDate}`
}
const jsonObj = await this.fetchGetAmberdataApi(url)
cleanedResponseObj = asFetchGetAmberdataApiResponse(jsonObj)
Expand Down Expand Up @@ -1546,10 +1566,15 @@ export class EthereumNetwork {
throw new Error('checkTxsAmberdata internal amberdataTx is invalid')
}
}
if (amberdataTxs.length === 0) {
if (endDate > Date.now()) {
break
}
page++
if (amberdataTxs.length === NUM_TRANSACTIONS_TO_QUERY) {
page++
} else {
page = 0
startDate = endDate
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/ethereum/ethTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,14 @@ export type AmberdataAccountsTx = $Call<typeof asAmberdataAccountsTx>

export const asAmberdataAccountsFuncs = asObject({
transactionHash: asString,
timestamp: asString,
timestamp: asNumber,
blockNumber: asString,
value: asString,
initialGas: asString,
leftOverGas: asString,
from: asObject({ address: asString }),
to: asArray(asObject({ address: asString }))
to: asArray(asObject({ address: asString })),
contractCodeAddress: asString
})

export type AmberdataAccountsFuncs = $Call<typeof asAmberdataAccountsFuncs>
Expand All @@ -393,13 +394,14 @@ export type FetchGetAmberdataApiResponse = $Call<

export type AmberdataInternalTx = {|
transactionHash: string,
timestamp: string,
timestamp: number,
blockNumber: string,
value: string,
initialGas: string,
leftOverGas: string,
from: { address: string },
to: Array<{ address: string }>
to: Array<{ address: string }>,
contractCodeAddress: string
|}

export const asEtherscanGetAccountBalance = asObject({
Expand Down