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

chore(README): update README and rename env variable to match others, add to Swagger #96

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ The service can be configured using environment variables. The following environ
- `GATEWAY_HOST`: the gateway used to evaluate Smartcontract state.
- `LOG_LEVEL`: the log level to display (using [Winston] log levels - e.g. `info`, `debug`)
- `LOG_FORMAT`: the log format to use when printing logs (e.g. `json`, `simple`)
- `PREFETCH_CONTRACTS`: boolean to enable/disable prefetching of contracts on startup. Defaults to `true`.
- `PREFETCH_CONTRACT_IDS`: comma separated list of contract IDs to prefetch on startup
- `ARNS_CONTRACT_TX_ID`: the ArNS contract transaction ID. Defaults to `bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U` and when `PREFETCH_CONTRACTS` is `true`, will be prefetched on startup.
- `BOOTSTRAP_CACHE`: loads warp cache from S3 on startup. Defaults to `false`.
- `BLOCKLISTED_CONTRACT_IDS`: comma separated list of contract IDs to block evaluation. These contracts will return `403` when requested.

You can `cp .env.sample .env` and modify them locally.

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
GATEWAY_PORT: ${GATEWAY_PORT:-1984}
GATEWAY_PROTOCOL: ${GATEWAY_PROTOCOL:-http}
PREFETCH_CONTRACTS: ${PREFETCH_CONTRACTS:-false}
BLOCKLISTED_CONTRACTS: ${BLOCKLISTED_CONTRACTS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
BLOCKLISTED_CONTRACT_IDS: ${BLOCKLISTED_CONTRACT_IDS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
ports:
- '3000:3000'

Expand All @@ -34,7 +34,7 @@ services:
GATEWAY_HOST: ${GATEWAY_HOST:-arlocal}
GATEWAY_PORT: ${GATEWAY_PORT:-1984}
GATEWAY_PROTOCOL: ${GATEWAY_PROTOCOL:-http}
BLOCKLISTED_CONTRACTS: ${BLOCKLISTED_CONTRACTS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
BLOCKLISTED_CONTRACT_IDS: ${BLOCKLISTED_CONTRACT_IDS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ}
depends_on:
- arlocal
- arns-service
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { EvaluationOptions } from 'warp-contracts';

export const PREFETCH_CONTRACTS = process.env.PREFETCH_CONTRACTS === 'true';
export const BOOTSTRAP_CACHE = process.env.BOOTSTRAP_CACHE === 'true';
export const BLOCKLISTED_CONTRACTS = process.env.BLOCKLISTED_CONTRACTS
? process.env.BLOCKLISTED_CONTRACTS.split(',')
export const BLOCKLISTED_CONTRACT_IDS = process.env.BLOCKLISTED_CONTRACT_IDS
? process.env.BLOCKLISTED_CONTRACT_IDS.split(',')
: ['fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ'];
export const ARWEAVE_TX_ID_REGEX = '([a-zA-Z0-9-_s+]{43})';
export const ARNS_NAME_REGEX = '([a-zA-Z0-9-s+]{1,51})';
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/blocklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Next } from 'koa';
import { BLOCKLISTED_CONTRACTS } from '../constants';
import { BLOCKLISTED_CONTRACT_IDS } from '../constants';
import { KoaContext } from '../types';
import logger from '../logger';
import { blockListedContractCount } from '../metrics';

export async function blocklistMiddleware(ctx: KoaContext, next: Next) {
const { contractTxId } = ctx.params;
if (BLOCKLISTED_CONTRACTS.includes(contractTxId)) {
if (BLOCKLISTED_CONTRACT_IDS.includes(contractTxId)) {
blockListedContractCount
.labels({
contractTxId,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../api/graphql';
import { isValidContractType, validateStateAndOwnership } from '../api/warp';
import {
BLOCKLISTED_CONTRACTS,
BLOCKLISTED_CONTRACT_IDS,
DEFAULT_STATE_EVALUATION_TIMEOUT_MS,
allowedContractTypes,
} from '../constants';
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function walletContractHandler(ctx: KoaContext) {
await Promise.allSettled(
[...deployedOrOwned].map(async (id: string) => {
// do not evaluate any blocklisted contracts
if (BLOCKLISTED_CONTRACTS.includes(id)) {
if (BLOCKLISTED_CONTRACT_IDS.includes(id)) {
logger.debug('Skipping blocklisted contract.', {
contractTxId: id,
});
Expand Down
11 changes: 6 additions & 5 deletions tests/integration/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
this.timeout(10_000);

ids = [
process.env.DEPLOYED_ANT_CONTRACT_TX_ID!,

Check warning on line 50 in tests/integration/routes.test.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Forbidden non-null assertion
process.env.DEPLOYED_REGISTRY_CONTRACT_TX_ID!,
];
id = process.env.DEPLOYED_REGISTRY_CONTRACT_TX_ID!;
Expand Down Expand Up @@ -131,7 +131,7 @@
describe('/contract', () => {
describe('/:contractTxId', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}`,
);
Expand Down Expand Up @@ -237,7 +237,7 @@
});
describe('/:contractTxId/price', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}/price`,
);
Expand All @@ -262,7 +262,7 @@

describe('/:contractTxId/interactions', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}/interactions`,
);
Expand Down Expand Up @@ -418,7 +418,8 @@
'reserved',
]) {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId =
process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/contract/${blocklistedContractTxId}/${field}`,
);
Expand Down Expand Up @@ -693,7 +694,7 @@

describe('/:address/contracts/:contractTxId', () => {
it('should not evaluate blocklisted contracts', async () => {
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACTS;
const blocklistedContractTxId = process.env.BLOCKLISTED_CONTRACT_IDS;
const { status, data, statusText } = await axios.get(
`/v1/wallet/${walletAddress}/contract/${blocklistedContractTxId}`,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export async function mochaGlobalSetup() {
process.env.DEPLOYED_ANT_CONTRACT_TX_ID = antContractTxId;

// blocklisted contract
process.env.BLOCKLISTED_CONTRACTS =
process.env.BLOCKLISTED_CONTRACTS ||
process.env.BLOCKLISTED_CONTRACT_IDS =
process.env.BLOCKLISTED_CONTRACT_IDS ||
'fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ';
console.log(
`Successfully setup ArLocal and deployed contracts.\nRegistry: ${contractTxId}\nANT: ${antContractTxId}`,
Expand Down
Loading