Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
update rpc nodes + disable tzstats indexer + fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmdssi committed Jan 25, 2024
1 parent b5e81a1 commit 023b5e6
Show file tree
Hide file tree
Showing 21 changed files with 367 additions and 347 deletions.
38 changes: 19 additions & 19 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const serverConfig = {

export const tezosNodeUrls = (
process.env.TEZOS_NODE_URLS ||
'https://ghostnet.smartpy.io,https://ghostnet.ecadinfra.com,https://rpc.ghost.tzstats.com'
'https://ghostnet.tezos.marigold.dev/,https://ghostnet.smartpy.io/,https://ghostnet.ecadinfra.com /'
).split(',');

export const amqpConfig: AmqpConfig = {
Expand All @@ -40,23 +40,23 @@ export const webProcessConfig: ProcessConfig = {
exitTimeout: parseInt(3000, process.env.WEB_PROCESS_TIMEOUT),
};

export const tzstatsIndexerConfig: IndexerConfig = {
name: IndexerEnum.TZSTATS,
apiUrl: process.env.TZSTATS_URL || 'https://api.ghost.tzstats.com/',
pathToOperation: 'explorer/op/',
pathToUserInfo: 'explorer/account/',
pathToContractCalls: 'explorer/contract/',
keyToOperation: parseInt(0, process.env.TZSTATS_KEY_TO_OPERATION),
keyToBlockLevel: process.env.TZSTATS_KEY_TO_BLOCK_LEVEL || 'height',
keyToOperationStatus: 'status',
successStatus: 'applied',
keyToBalance: 'spendable_balance',
balanceUnit: 1,
keyToReveal: 'is_revealed',
keyToCreationDate: 'time',
};

const tzktIndexerConfig: IndexerConfig = {
// export const tzstatsIndexerConfig: IndexerConfig = {
// name: IndexerEnum.TZSTATS,
// apiUrl: process.env.TZSTATS_URL || 'https://api.ghost.tzstats.com/',
// pathToOperation: 'explorer/op/',
// pathToUserInfo: 'explorer/account/',
// pathToContractCalls: 'explorer/contract/',
// keyToOperation: parseInt(0, process.env.TZSTATS_KEY_TO_OPERATION),
// keyToBlockLevel: process.env.TZSTATS_KEY_TO_BLOCK_LEVEL || 'height',
// keyToOperationStatus: 'status',
// successStatus: 'applied',
// keyToBalance: 'spendable_balance',
// balanceUnit: 1,
// keyToReveal: 'is_revealed',
// keyToCreationDate: 'time',
// };

export const tzktIndexerConfig: IndexerConfig = {
name: IndexerEnum.TZKT,
apiUrl: process.env.TZKT_URL || 'https://api.ghostnet.tzkt.io/',
pathToOperation: 'v1/operations/',
Expand All @@ -75,7 +75,7 @@ const tzktIndexerConfig: IndexerConfig = {
};

export const indexerConfigs: IndexerConfig[] = [
tzstatsIndexerConfig,
// tzstatsIndexerConfig,
tzktIndexerConfig,
];

Expand Down
2 changes: 1 addition & 1 deletion src/const/interfaces/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export interface IndexerConfig {
}

export enum IndexerEnum {
TZSTATS = 'tzstats',
// TZSTATS = 'tzstats',
TZKT = 'tzkt',
}
46 changes: 23 additions & 23 deletions src/helpers/mappers/transactions-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IndexerEnum } from '../../const/interfaces/indexer';
import { UnsupportedIndexerError } from '../../const/errors/indexer-error';
import { IndexerTransaction } from '../../const/interfaces/transaction';
import { deleteObjectSubLevel } from '../filter-object';
// import { deleteObjectSubLevel } from '../filter-object';

/**
* Convert the transaction returned by any indexer to our IndexerTransaction interface
Expand All @@ -17,28 +17,28 @@ export function mapIndexerTransactionToTransaction(
indexerName: IndexerEnum,
): IndexerTransaction {
switch (indexerName) {
case IndexerEnum.TZSTATS:
return {
indexer: IndexerEnum.TZSTATS,
destination: rawTx.receiver,
source: rawTx.sender,
timestamp: rawTx.time,
status: rawTx.status,
baker_fee: rawTx.fee,
storage_fee: rawTx.burned || 0,
storage_limit: rawTx.storage_limit || 0,
counter: rawTx.counter,
hash: rawTx.hash,
block: rawTx.block,
type: rawTx.type,
height: rawTx.height,
entrypoint: rawTx.parameters?.entrypoint,
parameters: deleteObjectSubLevel(rawTx.parameters?.value || '', [
'@or_0',
'@or_1',
]),
amount: rawTx.volume || 0,
};
// case IndexerEnum.TZSTATS:
// return {
// indexer: IndexerEnum.TZSTATS,
// destination: rawTx.receiver,
// source: rawTx.sender,
// timestamp: rawTx.time,
// status: rawTx.status,
// baker_fee: rawTx.fee,
// storage_fee: rawTx.burned || 0,
// storage_limit: rawTx.storage_limit || 0,
// counter: rawTx.counter,
// hash: rawTx.hash,
// block: rawTx.block,
// type: rawTx.type,
// height: rawTx.height,
// entrypoint: rawTx.parameters?.entrypoint,
// parameters: deleteObjectSubLevel(rawTx.parameters?.value || '', [
// '@or_0',
// '@or_1',
// ]),
// amount: rawTx.volume || 0,
// };
case IndexerEnum.TZKT:
return {
indexer: IndexerEnum.TZKT,
Expand Down
24 changes: 12 additions & 12 deletions src/processes/web/api/contract/contract-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
OperationNotFoundError,
UnsupportedIndexerError,
} from '../../../../const/errors/indexer-error';
import { ClientError } from '../../../../const/errors/client-error';
// import { ClientError } from '../../../../const/errors/client-error';

export default { getTransactionListOfSC };

Expand All @@ -32,17 +32,17 @@ function getTransactionListOfSC(indexerPool: IndexerPool) {
'[contract/contract-controller] Requesting transactions made on this contract ',
);

if (
params.indexer === IndexerEnum.TZSTATS &&
params.parameter !== undefined
) {
throw new ClientError({
status: 400,
message:
'Query param "parameter" shouldn\'t be set when query param "indexer" equals "tzstats".\' +' +
'Either remove "parameter" to target Tzstats or remove "indexer" to automatically target TZKT',
});
}
// if (
// params.indexer === IndexerEnum.TZSTATS &&
// params.parameter !== undefined
// ) {
// throw new ClientError({
// status: 400,
// message:
// 'Query param "parameter" shouldn\'t be set when query param "indexer" equals "tzstats".\' +' +
// 'Either remove "parameter" to target Tzstats or remove "indexer" to automatically target TZKT',
// });
// }

let currentIndexer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from './publish-confirmed-transaction-event';
import { GatewayPool } from '../../../../services/gateway-pool';
import { DateTime } from 'luxon';
import { IndexerEnum } from '../../../../const/interfaces/indexer';
// import { IndexerEnum } from '../../../../const/interfaces/indexer';

/**
* Check the operations (of all the jobs that has status "submitted" and operation hash) has been confirmed
Expand Down Expand Up @@ -63,6 +63,9 @@ export async function checkOperationStatus(
await Promise.all(
jobs.map(async (job) => {
try {
// quick fix not used gatewayPool
if (!gatewayPool) logger.info('gatewayPool is not used');

if (
await indexerPool.checkIfOperationIsConfirmedByRandomIndexer(
tezosService,
Expand Down Expand Up @@ -163,20 +166,21 @@ export async function checkOperationStatus(
const currentDate = DateTime.now().toString();

if (currentDate > opExpiredDate) {
try {
await gatewayPool.removeOperationFromMempool(
job.operation_hash as string,
);
logger.info(
{ operation_hash: job.operation_hash },
'[lib/checkOperationStatus] Successfully removed the operation from the mempool with operation hash',
);
} catch (e) {
logger.info(
{ operation_hash: job.operation_hash },
"[lib/checkOperationStatus] Couldn't removed the operation from the mempool with operation hash",
);
}
// removeOperationFromMempool forbidden now TODO: inspect
// try {
// await gatewayPool.removeOperationFromMempool(
// job.operation_hash as string,
// );
// logger.info(
// { operation_hash: job.operation_hash },
// '[lib/checkOperationStatus] Successfully removed the operation from the mempool with operation hash',
// );
// } catch (e) {
// logger.info(
// { operation_hash: job.operation_hash },
// "[lib/checkOperationStatus] Couldn't removed the operation from the mempool with operation hash",
// );
// }

const updatedJob = await updateJobStatus(
postgreService.pool,
Expand All @@ -201,17 +205,17 @@ export async function checkOperationStatus(

if (err instanceof OperationFailedError) {
let errorMsg = 'runtime_error';
try {
const indexer = indexerPool.getSpecificIndexer(IndexerEnum.TZSTATS);
const operation = await indexer.getOperationByHash(
job.operation_hash!,
);
errorMsg = operation.errors[1].with.string;
} catch (e) {
logger.info(
'[lib/checkOperationStatus] Cannot find error msg for failed operation',
);
}
// try {
// const indexer = indexerPool.getSpecificIndexer(IndexerEnum.TZSTATS);
// const operation = await indexer.getOperationByHash(
// job.operation_hash!,
// );
// errorMsg = operation.errors[1].with.string;
// } catch (e) {
// logger.info(
// '[lib/checkOperationStatus] Cannot find error msg for failed operation',
// );
// }
const updatedJob = await updateJobStatusAndErrorMessage(
postgreService.pool,
JobStatus.ERROR,
Expand Down
24 changes: 12 additions & 12 deletions src/services/clients/indexer-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,18 @@ export class IndexerClient extends AbstractClient {
let queryParams = `limit=${limit}&offset=${offset}`;

switch (indexerName) {
case IndexerEnum.TZSTATS: {
if (params.parameter !== undefined)
throw new UnsupportedIndexerError(IndexerEnum.TZSTATS);

domainAndPath += `${contractAddress}/calls`;
const order = params.order ? `&order=${params.order}` : '';
const entrypoint = params.entrypoint
? `&entrypoint=${params.entrypoint}`
: '';
queryParams += `${order}${entrypoint}`;
break;
}
// case IndexerEnum.TZSTATS: {
// if (params.parameter !== undefined)
// throw new UnsupportedIndexerError(IndexerEnum.TZSTATS);

// domainAndPath += `${contractAddress}/calls`;
// const order = params.order ? `&order=${params.order}` : '';
// const entrypoint = params.entrypoint
// ? `&entrypoint=${params.entrypoint}`
// : '';
// queryParams += `${order}${entrypoint}`;
// break;
// }
case IndexerEnum.TZKT: {
const order = params.order ? `&sort.${params.order}=id` : '';
const entrypoint = params.entrypoint
Expand Down
4 changes: 2 additions & 2 deletions test/__fixtures__/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const serverConfig = {
};

export const tezosNodeUrl =
process.env.TEZOS_NODE_TEST || 'https://rpc.ghost.tzstats.com/';
process.env.TEZOS_NODE_TEST || 'https://ghostnet.tezos.marigold.dev/';

export const tezosNodeUrls = (
process.env.TEZOS_NODE_TEST_URLS ||
'https://ghostnet.tezos.marigold.dev/,https://rpc.ghost.tzstats.com/'
'https://ghostnet.tezos.marigold.dev/,https://ghostnet.smartpy.io/,https://ghostnet.ecadinfra.com /'
).split(',');

export const amqpConfig: AmqpConfig = {
Expand Down
32 changes: 16 additions & 16 deletions test/integration/lib/jobs/estimate-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ describe('[lib/jobs/estimate-operation]', () => {
amount: 0,
counter: 10240873,
destination: flexibleTokenContract,
gasEstimation: 2706,
gasLimit: 2807,
gasEstimation: 1879,
gasLimit: 1980,
kind: 'transaction',
minimalFee: 490,
minimalFee: 407,
parameters: {
entrypoint: 'transfer',
value: {
Expand All @@ -85,16 +85,16 @@ describe('[lib/jobs/estimate-operation]', () => {
source: revealedAccount.address,
storageAndAllocationFee: 0,
storageLimit: 0,
suggestedFee: 590,
suggestedFee: 507,
},
{
amount: 0,
counter: 10240874,
destination: flexibleTokenContract,
gasEstimation: 1215,
gasLimit: 1315,
gasEstimation: 315,
gasLimit: 415,
kind: 'transaction',
minimalFee: 340,
minimalFee: 250,
parameters: {
entrypoint: 'lock',
value: {
Expand All @@ -110,7 +110,7 @@ describe('[lib/jobs/estimate-operation]', () => {
source: revealedAccount.address,
storageAndAllocationFee: 0,
storageLimit: 0,
suggestedFee: 440,
suggestedFee: 350,
},
];

Expand Down Expand Up @@ -271,15 +271,15 @@ describe('[lib/jobs/estimate-operation]', () => {
);
expect(estimations[0]).toEqual({
counter: 10240927,
gasEstimation: 1000,
gasLimit: 1100,
gasEstimation: 175,
gasLimit: 276,
kind: 'reveal',
minimalFee: 274,
minimalFee: 192,
public_key: activatedAccount.publicKey,
source: activatedAccount.address,
storageAndAllocationFee: 0,
storageLimit: 0,
suggestedFee: 374,
suggestedFee: 292,
});
});

Expand All @@ -294,14 +294,14 @@ describe('[lib/jobs/estimate-operation]', () => {
{
...estimationResults[0],
amount: 10,
minimalFee: 493,
suggestedFee: 593,
minimalFee: 410,
suggestedFee: 510,
},
{
...estimationResults[1],
amount: 100,
minimalFee: 343,
suggestedFee: 443,
minimalFee: 253,
suggestedFee: 353,
},
]);
}, 8000);
Expand Down
4 changes: 2 additions & 2 deletions test/integration/lib/jobs/forge-reveal-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ describe('[lib/jobs/forge-operation]', () => {

expect(operation).toEqual([
{
fee: 374,
fee: 291,
source: activatedAccount.address,
storage_limit: 0,
gas_limit: 1100,
gas_limit: 270,
branch: operation[0].branch,
counter: operation[0].counter,
job_id: job.id,
Expand Down
Loading

0 comments on commit 023b5e6

Please sign in to comment.