chore: no eslint warnings policy
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
"build": "yarn run clean && yarn build:cjs && yarn build:mjs && yarn mjs:burn:in:hell && yarn build:types && yarn bundle",
|
||||
"format": "prettier --write 'src/**/*.ts'",
|
||||
"clean": "rimraf ./lib",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"lint": "eslint . --ext .ts --max-warnings=0",
|
||||
"lint:fix": "eslint . --ext .ts --fix",
|
||||
"prettier:format": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
||||
"prepublishOnly": "yarn lint",
|
||||
|
||||
2
src/cache/SortKeyCache.ts
vendored
2
src/cache/SortKeyCache.ts
vendored
@@ -47,7 +47,7 @@ export interface SortKeyCache<V> {
|
||||
* used mostly for debugging, allows to dump the current content cache
|
||||
* It's slow.
|
||||
*/
|
||||
dump(): Promise<any>;
|
||||
dump(): Promise<any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
/**
|
||||
* Return all cached keys.
|
||||
|
||||
13
src/cache/WarpCache.ts
vendored
13
src/cache/WarpCache.ts
vendored
@@ -4,10 +4,11 @@
|
||||
* - like contract's source code cache.
|
||||
* See {@link MemCache} for example implementation.
|
||||
*
|
||||
* @typeParam K - type of the cache key, defaults to `string`
|
||||
* @typeParam V - type of the cache value, default to `any`.
|
||||
* @typeParam K - type of the cache key.
|
||||
* @typeParam V - type of the cache value.
|
||||
*/
|
||||
export interface WarpCache<K = string, V = any> {
|
||||
|
||||
export interface WarpCache<K, V> {
|
||||
/**
|
||||
* gets value by its key
|
||||
*/
|
||||
@@ -21,15 +22,15 @@ export interface WarpCache<K = string, V = any> {
|
||||
/**
|
||||
* puts new value under specified key
|
||||
*/
|
||||
put(key: K, value: V);
|
||||
put(key: K, value: V): void;
|
||||
|
||||
/**
|
||||
* clears the whole cache
|
||||
*/
|
||||
clearAll();
|
||||
clearAll(): void;
|
||||
|
||||
/**
|
||||
* remove entry in cache for given key
|
||||
*/
|
||||
remove(key: K);
|
||||
remove(key: K): void;
|
||||
}
|
||||
|
||||
24
src/cache/impl/LevelDbCache.ts
vendored
24
src/cache/impl/LevelDbCache.ts
vendored
@@ -14,7 +14,8 @@ import { LoggerFactory } from '../../logging/LoggerFactory';
|
||||
*
|
||||
* In order to reduce the cache size, the oldest entries are automatically pruned.
|
||||
*/
|
||||
export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
|
||||
export class LevelDbCache<V> implements SortKeyCache<V> {
|
||||
private readonly logger = LoggerFactory.INST.create('LevelDbCache');
|
||||
|
||||
/**
|
||||
@@ -22,10 +23,10 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
* and there doesn't seem to be any public interface/abstract type for all Level implementations
|
||||
* (the AbstractLevel is not exported from the package...)
|
||||
*/
|
||||
private _db: MemoryLevel;
|
||||
private _db: MemoryLevel<string, V>;
|
||||
|
||||
// Lazy initialization upon first access
|
||||
private get db(): MemoryLevel {
|
||||
private get db(): MemoryLevel<string, V> {
|
||||
if (!this._db) {
|
||||
if (this.cacheOptions.inMemory) {
|
||||
this._db = new MemoryLevel({ valueEncoding: 'json' });
|
||||
@@ -35,7 +36,7 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
}
|
||||
const dbLocation = this.cacheOptions.dbLocation;
|
||||
this.logger.info(`Using location ${dbLocation}`);
|
||||
this._db = new Level<string, any>(dbLocation, { valueEncoding: 'json' });
|
||||
this._db = new Level<string, V>(dbLocation, { valueEncoding: 'json' });
|
||||
}
|
||||
}
|
||||
return this._db;
|
||||
@@ -43,8 +44,9 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
|
||||
constructor(private readonly cacheOptions: CacheOptions) {}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async get(cacheKey: CacheKey, returnDeepCopy?: boolean): Promise<SortKeyCacheResult<V> | null> {
|
||||
const contractCache = this.db.sublevel<string, any>(cacheKey.key, { valueEncoding: 'json' });
|
||||
const contractCache = this.db.sublevel<string, V>(cacheKey.key, { valueEncoding: 'json' });
|
||||
// manually opening to fix https://github.com/Level/level/issues/221
|
||||
await contractCache.open();
|
||||
try {
|
||||
@@ -54,6 +56,7 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
sortKey: cacheKey.sortKey,
|
||||
cachedValue: result
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (e: any) {
|
||||
if (e.code == 'LEVEL_NOT_FOUND') {
|
||||
return null;
|
||||
@@ -64,7 +67,7 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
}
|
||||
|
||||
async getLast(key: string): Promise<SortKeyCacheResult<V> | null> {
|
||||
const contractCache = this.db.sublevel<string, any>(key, { valueEncoding: 'json' });
|
||||
const contractCache = this.db.sublevel<string, V>(key, { valueEncoding: 'json' });
|
||||
// manually opening to fix https://github.com/Level/level/issues/221
|
||||
await contractCache.open();
|
||||
const keys = await contractCache.keys({ reverse: true, limit: 1 }).all();
|
||||
@@ -79,7 +82,7 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
}
|
||||
|
||||
async getLessOrEqual(key: string, sortKey: string): Promise<SortKeyCacheResult<V> | null> {
|
||||
const contractCache = this.db.sublevel<string, any>(key, { valueEncoding: 'json' });
|
||||
const contractCache = this.db.sublevel<string, V>(key, { valueEncoding: 'json' });
|
||||
// manually opening to fix https://github.com/Level/level/issues/221
|
||||
await contractCache.open();
|
||||
const keys = await contractCache.keys({ reverse: true, lte: sortKey, limit: 1 }).all();
|
||||
@@ -94,14 +97,14 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
}
|
||||
|
||||
async put(stateCacheKey: CacheKey, value: V): Promise<void> {
|
||||
const contractCache = this.db.sublevel<string, any>(stateCacheKey.key, { valueEncoding: 'json' });
|
||||
const contractCache = this.db.sublevel<string, V>(stateCacheKey.key, { valueEncoding: 'json' });
|
||||
// manually opening to fix https://github.com/Level/level/issues/221
|
||||
await contractCache.open();
|
||||
await contractCache.put(stateCacheKey.sortKey, value);
|
||||
}
|
||||
|
||||
async delete(key: string): Promise<void> {
|
||||
const contractCache = this.db.sublevel<string, any>(key, { valueEncoding: 'json' });
|
||||
const contractCache = this.db.sublevel<string, V>(key, { valueEncoding: 'json' });
|
||||
await contractCache.open();
|
||||
await contractCache.clear();
|
||||
}
|
||||
@@ -126,6 +129,7 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async dump(): Promise<any> {
|
||||
const result = await this.db.iterator().all();
|
||||
return result;
|
||||
@@ -188,7 +192,7 @@ export class LevelDbCache<V = any> implements SortKeyCache<V> {
|
||||
|
||||
const contracts = await this.keys();
|
||||
for (let i = 0; i < contracts.length; i++) {
|
||||
const contractCache = this.db.sublevel<string, any>(contracts[i], { valueEncoding: 'json' });
|
||||
const contractCache = this.db.sublevel<string, V>(contracts[i], { valueEncoding: 'json' });
|
||||
|
||||
// manually opening to fix https://github.com/Level/level/issues/221
|
||||
await contractCache.open();
|
||||
|
||||
2
src/cache/impl/MemCache.ts
vendored
2
src/cache/impl/MemCache.ts
vendored
@@ -3,7 +3,7 @@ import { WarpCache } from '../../cache/WarpCache';
|
||||
/**
|
||||
* A simple, in-memory cache, with keys being transaction ids (e.g. contract transaction id).
|
||||
*/
|
||||
export class MemCache<V = any> implements WarpCache<string, V> {
|
||||
export class MemCache<V> implements WarpCache<string, V> {
|
||||
private readonly storage: { [key: string]: V } = {};
|
||||
|
||||
clearAll() {
|
||||
|
||||
@@ -41,6 +41,7 @@ export type WriteInteractionOptions = WarpOptions & ArweaveOptions & CommonOptio
|
||||
* Interface describing state for all Evolve-compatible contracts.
|
||||
*/
|
||||
export interface EvolveState {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- compatibility with smartweave
|
||||
settings: any[] | unknown | null;
|
||||
/**
|
||||
* whether contract is allowed to evolve.
|
||||
@@ -210,6 +211,7 @@ export interface Contract<State = unknown> {
|
||||
* @param params - by default only query param with `contractId` is set by SDK, any additional ones can be passed
|
||||
* in the `params` object
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- params can be anything
|
||||
syncState(externalUrl: string, params?: any): Promise<Contract>;
|
||||
|
||||
/**
|
||||
@@ -228,7 +230,7 @@ export interface Contract<State = unknown> {
|
||||
|
||||
isRoot(): boolean;
|
||||
|
||||
getStorageValues(keys: string[]): Promise<SortKeyCacheResult<Map<string, any>>>;
|
||||
getStorageValues(keys: string[]): Promise<SortKeyCacheResult<Map<string, unknown>>>;
|
||||
|
||||
getUncommittedState(contractTxId: string): EvalStateResult<unknown>;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
private signature: Signature;
|
||||
private warpFetchWrapper: WarpFetchWrapper;
|
||||
|
||||
private _children: HandlerBasedContract<any>[] = [];
|
||||
private _children: HandlerBasedContract<unknown>[] = [];
|
||||
|
||||
private _uncommittedStates = new Map<string, EvalStateResult<unknown>>();
|
||||
|
||||
@@ -64,7 +64,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
constructor(
|
||||
private readonly _contractTxId: string,
|
||||
protected readonly warp: Warp,
|
||||
private readonly _parentContract: Contract<any> = null,
|
||||
private readonly _parentContract: Contract<unknown> = null,
|
||||
private readonly _innerCallData: InnerCallData = null
|
||||
) {
|
||||
this.waitForConfirmation = this.waitForConfirmation.bind(this);
|
||||
@@ -804,6 +804,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- params can be anything
|
||||
async syncState(externalUrl: string, params?: any): Promise<Contract> {
|
||||
const { stateEvaluator } = this.warp;
|
||||
const response = await this.warpFetchWrapper
|
||||
@@ -829,7 +830,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
}
|
||||
|
||||
async evolve(newSrcTxId: string, options?: WriteInteractionOptions): Promise<WriteInteractionResponse | null> {
|
||||
return await this.writeInteraction<any>({ function: 'evolve', value: newSrcTxId }, options);
|
||||
return await this.writeInteraction({ function: 'evolve', value: newSrcTxId }, options);
|
||||
}
|
||||
|
||||
get rootSortKey(): string {
|
||||
@@ -845,7 +846,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
return this._parentContract == null;
|
||||
}
|
||||
|
||||
async getStorageValues(keys: string[]): Promise<SortKeyCacheResult<Map<string, any>>> {
|
||||
async getStorageValues(keys: string[]): Promise<SortKeyCacheResult<Map<string, unknown>>> {
|
||||
const lastCached = await this.warp.stateEvaluator.getCache().getLast(this.txId());
|
||||
if (lastCached == null) {
|
||||
return {
|
||||
@@ -855,7 +856,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
}
|
||||
|
||||
const storage = this.warp.kvStorageFactory(this.txId());
|
||||
const result: Map<string, any> = new Map();
|
||||
const result: Map<string, unknown> = new Map();
|
||||
try {
|
||||
await storage.open();
|
||||
for (const key of keys) {
|
||||
|
||||
@@ -21,6 +21,6 @@ export class PstContractImpl extends HandlerBasedContract<PstState> implements P
|
||||
}
|
||||
|
||||
async transfer(transfer: TransferInput, options?: WriteInteractionOptions): Promise<WriteInteractionResponse | null> {
|
||||
return await this.writeInteraction<any>({ function: 'transfer', ...transfer }, options);
|
||||
return await this.writeInteraction({ function: 'transfer', ...transfer }, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ export class ContractCallRecord {
|
||||
this.id = isomorphicRandomUUID();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
addInteractionData(interactionData: InteractionData<any>): InteractionCall {
|
||||
const { interaction, interactionTx } = interactionData;
|
||||
|
||||
@@ -72,6 +73,7 @@ export class InteractionInput {
|
||||
export class InteractionOutput {
|
||||
constructor(
|
||||
public readonly cacheHit: boolean,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public readonly outputState: any,
|
||||
public readonly executionTime: number,
|
||||
public readonly valid: boolean,
|
||||
|
||||
@@ -13,7 +13,7 @@ export type ContractSource = {
|
||||
srcBinary: Buffer | null;
|
||||
srcWasmLang: string | null;
|
||||
contractType: ContractType;
|
||||
srcTx: any;
|
||||
srcTx: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
metadata?: ContractMetadata;
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ export class SrcCache {
|
||||
srcBinary: Buffer | null;
|
||||
srcWasmLang: string | null;
|
||||
|
||||
constructor(value: ContractDefinition<any>) {
|
||||
constructor(value: ContractDefinition<unknown>) {
|
||||
this.src = value.src;
|
||||
this.srcBinary = value.srcBinary;
|
||||
this.srcWasmLang = value.srcWasmLang;
|
||||
@@ -38,8 +38,8 @@ export class ContractCache<State> {
|
||||
contractType: ContractType;
|
||||
metadata?: ContractMetadata;
|
||||
manifest?: EvaluationManifest;
|
||||
contractTx: any;
|
||||
srcTx: any;
|
||||
contractTx: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
srcTx: any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
testnet: string | null;
|
||||
|
||||
constructor(value: ContractDefinition<State>) {
|
||||
|
||||
@@ -35,7 +35,7 @@ import { LevelDbCache } from '../cache/impl/LevelDbCache';
|
||||
import { Transaction } from '../utils/types/arweave-types';
|
||||
|
||||
export type WarpEnvironment = 'local' | 'testnet' | 'mainnet' | 'custom';
|
||||
export type KVStorageFactory = (contractTxId: string) => SortKeyCache<any>;
|
||||
export type KVStorageFactory = (contractTxId: string) => SortKeyCache<unknown>;
|
||||
|
||||
/**
|
||||
* The Warp "motherboard" ;-).
|
||||
@@ -128,7 +128,7 @@ export class Warp {
|
||||
return this;
|
||||
}
|
||||
|
||||
useContractCache(definition: SortKeyCache<ContractDefinition<any>>, src: SortKeyCache<SrcCache>): Warp {
|
||||
useContractCache(definition: SortKeyCache<ContractDefinition<unknown>>, src: SortKeyCache<SrcCache>): Warp {
|
||||
this.definitionLoader.setSrcCache(src);
|
||||
this.definitionLoader.setCache(definition);
|
||||
return this;
|
||||
|
||||
@@ -14,6 +14,7 @@ import { WarpEnvironment, Warp } from './Warp';
|
||||
import { CacheOptions, GatewayOptions } from './WarpFactory';
|
||||
import { SortKeyCache } from '../cache/SortKeyCache';
|
||||
import { LevelDbCache } from '../cache/impl/LevelDbCache';
|
||||
import { ContractCache, SrcCache } from './ContractDefinition';
|
||||
|
||||
export class WarpBuilder {
|
||||
private _definitionLoader?: DefinitionLoader;
|
||||
@@ -64,13 +65,13 @@ export class WarpBuilder {
|
||||
)
|
||||
);
|
||||
|
||||
const contractsCache = new LevelDbCache({
|
||||
const contractsCache = new LevelDbCache<ContractCache<unknown>>({
|
||||
...cacheOptions,
|
||||
dbLocation: `${cacheOptions.dbLocation}/contracts`
|
||||
});
|
||||
|
||||
// Separate cache for sources to minimize duplicates
|
||||
const sourceCache = new LevelDbCache({
|
||||
const sourceCache = new LevelDbCache<SrcCache>({
|
||||
...cacheOptions,
|
||||
dbLocation: `${cacheOptions.dbLocation}/source`
|
||||
});
|
||||
|
||||
@@ -12,12 +12,12 @@ export interface DefinitionLoader extends GwTypeAware {
|
||||
|
||||
loadContractSource(srcTxId: string): Promise<ContractSource>;
|
||||
|
||||
setCache(cache: SortKeyCache<ContractCache<any>>): void;
|
||||
setCache(cache: SortKeyCache<ContractCache<unknown>>): void;
|
||||
|
||||
// Cache for storing common source code or binaries
|
||||
setSrcCache(cacheSrc?: SortKeyCache<SrcCache>): void;
|
||||
|
||||
getCache(): SortKeyCache<ContractCache<any>>;
|
||||
getCache(): SortKeyCache<ContractCache<unknown>>;
|
||||
|
||||
getSrcCache(): SortKeyCache<SrcCache>;
|
||||
}
|
||||
|
||||
@@ -68,13 +68,14 @@ export interface StateEvaluator {
|
||||
/**
|
||||
* allows to syncState with an external state source (like Warp Distributed Execution Network)
|
||||
*/
|
||||
syncState(contractTxId: string, sortKey: string, state: any, validity: any): Promise<void>;
|
||||
syncState(contractTxId: string, sortKey: string, state: unknown, validity: Record<string, boolean>): Promise<void>;
|
||||
|
||||
internalWriteState<State>(
|
||||
contractTxId: string,
|
||||
sortKey: string
|
||||
): Promise<SortKeyCacheResult<EvalStateResult<State>> | null>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
dumpCache(): Promise<any>;
|
||||
|
||||
hasContractCached(contractTxId: string): Promise<boolean>;
|
||||
|
||||
@@ -187,11 +187,17 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
|
||||
await this.cache.put(new CacheKey(contractTxId, transaction.sortKey), stateToCache);
|
||||
}
|
||||
|
||||
async syncState(contractTxId: string, sortKey: string, state: any, validity: any): Promise<void> {
|
||||
async syncState(
|
||||
contractTxId: string,
|
||||
sortKey: string,
|
||||
state: unknown,
|
||||
validity: Record<string, boolean>
|
||||
): Promise<void> {
|
||||
const stateToCache = new EvalStateResult(state, validity, {});
|
||||
await this.cache.put(new CacheKey(contractTxId, sortKey), stateToCache);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async dumpCache(): Promise<any> {
|
||||
return await this.cache.dump();
|
||||
}
|
||||
|
||||
@@ -143,15 +143,17 @@ export class ContractDefinitionLoader implements DefinitionLoader {
|
||||
return 'arweave';
|
||||
}
|
||||
|
||||
setCache(cache: SortKeyCache<ContractDefinition<any>>): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
setCache(cache: SortKeyCache<ContractDefinition<unknown>>): void {
|
||||
throw new Error('No cache implemented for this loader');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
setSrcCache(cache: SortKeyCache<SrcCache>): void {
|
||||
throw new Error('No cache implemented for this loader');
|
||||
}
|
||||
|
||||
getCache(): SortKeyCache<ContractCache<any>> {
|
||||
getCache(): SortKeyCache<ContractCache<unknown>> {
|
||||
throw new Error('No cache implemented for this loader');
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
||||
baseState: EvalStateResult<State>,
|
||||
executionContext: ExecutionContext<State, HandlerApi<State>>
|
||||
): Promise<SortKeyCacheResult<EvalStateResult<State>>> {
|
||||
const { ignoreExceptions, stackTrace, internalWrites, cacheEveryNInteractions } =
|
||||
executionContext.evaluationOptions;
|
||||
const { ignoreExceptions, stackTrace, internalWrites } = executionContext.evaluationOptions;
|
||||
const { contract, contractDefinition, sortedInteractions, warp } = executionContext;
|
||||
|
||||
let currentState = baseState.state;
|
||||
@@ -321,6 +320,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
||||
arweave.utils.stringToBuffer(sortKey),
|
||||
arweave.utils.b64UrlToBuffer(vrf.proof)
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (e: any) {
|
||||
return false;
|
||||
}
|
||||
@@ -392,8 +392,14 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
||||
state: EvalStateResult<State>
|
||||
): Promise<void>;
|
||||
|
||||
abstract syncState(contractTxId: string, sortKey: string, state: any, validity: any): Promise<void>;
|
||||
abstract syncState(
|
||||
contractTxId: string,
|
||||
sortKey: string,
|
||||
state: unknown,
|
||||
validity: Record<string, boolean>
|
||||
): Promise<void>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
abstract dumpCache(): Promise<any>;
|
||||
|
||||
abstract internalWriteState<State>(
|
||||
|
||||
@@ -65,7 +65,7 @@ export class HandlerExecutorFactory implements ExecutorFactory<HandlerApi<unknow
|
||||
|
||||
const extensionPlugins = warp.matchPlugins(`^smartweave-extension-`);
|
||||
extensionPlugins.forEach((ex) => {
|
||||
const extension = warp.loadPlugin<any, void>(ex);
|
||||
const extension = warp.loadPlugin<unknown, void>(ex);
|
||||
extension.process(swGlobal.extensions);
|
||||
});
|
||||
|
||||
@@ -299,5 +299,5 @@ export interface IvmPluginInput {
|
||||
evaluationOptions: EvaluationOptions;
|
||||
arweave: Arweave;
|
||||
swGlobal: SmartWeaveGlobal;
|
||||
contractDefinition: ContractDefinition<any>;
|
||||
contractDefinition: ContractDefinition<unknown>;
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ export class TagsParser {
|
||||
}
|
||||
|
||||
decodeTags(tx: Transaction): GQLTagInterface[] {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const tags = tx.get('tags') as any;
|
||||
const result: GQLTagInterface[] = [];
|
||||
|
||||
@@ -98,6 +99,7 @@ export class TagsParser {
|
||||
}
|
||||
|
||||
getTag(tx: Transaction, name: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const tags = tx.get('tags') as any;
|
||||
|
||||
for (const tag of tags) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import { DefinitionLoader } from '../DefinitionLoader';
|
||||
import { WasmSrc } from './wasm/WasmSrc';
|
||||
import { WarpEnvironment } from '../../Warp';
|
||||
import { TagsParser } from './TagsParser';
|
||||
import { CacheKey, SortKeyCache } from '../../../cache/SortKeyCache';
|
||||
import { CacheKey, SortKeyCache, SortKeyCacheResult } from '../../../cache/SortKeyCache';
|
||||
import { Transaction } from '../../../utils/types/arweave-types';
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
|
||||
constructor(
|
||||
private readonly baseUrl: string,
|
||||
arweave: Arweave,
|
||||
private definitionCache: SortKeyCache<ContractCache<any>>,
|
||||
private definitionCache: SortKeyCache<ContractCache<unknown>>,
|
||||
private srcCache: SortKeyCache<SrcCache>,
|
||||
private readonly env: WarpEnvironment
|
||||
) {
|
||||
@@ -43,11 +43,13 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
|
||||
}
|
||||
|
||||
async load<State>(contractTxId: string, evolvedSrcTxId?: string): Promise<ContractDefinition<State>> {
|
||||
const result = await this.getFromCache(contractTxId, evolvedSrcTxId);
|
||||
const result = await this.getFromCache<State>(contractTxId, evolvedSrcTxId);
|
||||
if (result) {
|
||||
this.rLogger.debug('WarpGatewayContractDefinitionLoader: Hit from cache!');
|
||||
// LevelDB serializes Buffer to an object with 'type' and 'data' fields
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
if (result.contractType == 'wasm' && (result.srcBinary as any).data) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
result.srcBinary = Buffer.from((result.srcBinary as any).data);
|
||||
}
|
||||
this.verifyEnv(result);
|
||||
@@ -80,6 +82,7 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
|
||||
);
|
||||
});
|
||||
if (result.srcBinary != null && !(result.srcBinary instanceof Buffer)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
result.srcBinary = Buffer.from((result.srcBinary as any).data);
|
||||
}
|
||||
if (result.srcBinary) {
|
||||
@@ -110,7 +113,7 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
|
||||
return 'warp';
|
||||
}
|
||||
|
||||
setCache(cache: SortKeyCache<ContractCache<any>>): void {
|
||||
setCache(cache: SortKeyCache<ContractCache<unknown>>): void {
|
||||
this.definitionCache = cache;
|
||||
}
|
||||
|
||||
@@ -118,7 +121,7 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
|
||||
this.srcCache = cacheSrc;
|
||||
}
|
||||
|
||||
getCache(): SortKeyCache<ContractCache<any>> {
|
||||
getCache(): SortKeyCache<ContractCache<unknown>> {
|
||||
return this.definitionCache;
|
||||
}
|
||||
|
||||
@@ -136,8 +139,8 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
|
||||
}
|
||||
|
||||
// Gets ContractDefinition and ContractSource from two caches and returns a combined structure
|
||||
private async getFromCache(contractTxId: string, srcTxId?: string): Promise<ContractDefinition<any> | null> {
|
||||
const contract = await this.definitionCache.get(new CacheKey(contractTxId, 'cd'));
|
||||
private async getFromCache<State>(contractTxId: string, srcTxId?: string): Promise<ContractDefinition<State> | null> {
|
||||
const contract = await this.definitionCache.get(new CacheKey(contractTxId, 'cd')) as SortKeyCacheResult<ContractCache<State>>;
|
||||
if (!contract) {
|
||||
return null;
|
||||
}
|
||||
@@ -150,7 +153,11 @@ export class WarpGatewayContractDefinitionLoader implements DefinitionLoader {
|
||||
}
|
||||
|
||||
// Divides ContractDefinition into entries in two caches to avoid duplicates
|
||||
private async putToCache(contractTxId: string, value: ContractDefinition<any>, srcTxId?: string): Promise<void> {
|
||||
private async putToCache<State>(
|
||||
contractTxId: string,
|
||||
value: ContractDefinition<State>,
|
||||
srcTxId?: string
|
||||
): Promise<void> {
|
||||
const src = new SrcCache(value);
|
||||
const contract = new ContractCache(value);
|
||||
await this.definitionCache.put({ key: contractTxId, sortKey: 'cd' }, contract);
|
||||
|
||||
@@ -91,7 +91,7 @@ export abstract class AbstractContractHandler<State> implements HandlerApi<State
|
||||
}
|
||||
|
||||
protected assignViewContractState<Input>(executionContext: ExecutionContext<State>) {
|
||||
this.swGlobal.contracts.viewContractState = async <View>(contractTxId: string, input: any) => {
|
||||
this.swGlobal.contracts.viewContractState = async <View>(contractTxId: string, input: Input) => {
|
||||
this.logger.debug('swGlobal.viewContractState call:', {
|
||||
from: this.contractDefinition.txId,
|
||||
to: contractTxId,
|
||||
@@ -102,11 +102,11 @@ export abstract class AbstractContractHandler<State> implements HandlerApi<State
|
||||
callType: 'view'
|
||||
});
|
||||
|
||||
return await childContract.viewStateForTx(input, this.swGlobal._activeTx);
|
||||
return await childContract.viewStateForTx<Input, View>(input, this.swGlobal._activeTx);
|
||||
};
|
||||
}
|
||||
|
||||
protected assignReadContractState<Input>(executionContext: ExecutionContext<State>, interactionTx: GQLNodeInterface) {
|
||||
protected assignReadContractState(executionContext: ExecutionContext<State>, interactionTx: GQLNodeInterface) {
|
||||
this.swGlobal.contracts.readContractState = async (contractTxId: string, returnValidity?: boolean) => {
|
||||
this.logger.debug('swGlobal.readContractState call:', {
|
||||
from: this.contractDefinition.txId,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { knownWarpPlugins, knownWarpPluginsPartial } from '../../../../core/WarpPlugin';
|
||||
import { ContractDefinition } from '../../../../core/ContractDefinition';
|
||||
import { ExecutionContext } from '../../../../core/ExecutionContext';
|
||||
import { EvalStateResult } from '../../../../core/modules/StateEvaluator';
|
||||
@@ -33,7 +32,7 @@ export class JsHandlerApi<State> extends AbstractContractHandler<State> {
|
||||
this.swGlobal._activeTx = interactionTx;
|
||||
this.swGlobal.caller = interaction.caller; // either contract tx id (for internal writes) or transaction.owner
|
||||
|
||||
this.assignReadContractState<Input>(executionContext, interactionTx);
|
||||
this.assignReadContractState(executionContext, interactionTx);
|
||||
this.assignViewContractState<Input>(executionContext);
|
||||
this.assignWrite(executionContext);
|
||||
this.assignRefreshState(executionContext);
|
||||
@@ -86,6 +85,7 @@ export class JsHandlerApi<State> extends AbstractContractHandler<State> {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
initState(state: State): void {
|
||||
// nth to do in this impl...
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ export class WasmHandlerApi<State> extends AbstractContractHandler<State> {
|
||||
this.swGlobal.gasLimit = executionContext.evaluationOptions.gasLimit;
|
||||
this.swGlobal.gasUsed = 0;
|
||||
|
||||
this.assignReadContractState<Input>(executionContext, interactionTx);
|
||||
this.assignViewContractState(executionContext);
|
||||
this.assignReadContractState(executionContext, interactionTx);
|
||||
this.assignViewContractState<Input>(executionContext);
|
||||
this.assignWrite(executionContext);
|
||||
|
||||
await this.swGlobal.kv.open();
|
||||
|
||||
@@ -5,11 +5,11 @@ import { TagsParser } from '../core/modules/impl/TagsParser';
|
||||
import { SigningFunction } from '../contract/Signature';
|
||||
import { BlockData, CreateTransactionInterface, Transaction } from '../utils/types/arweave-types';
|
||||
|
||||
export async function createInteractionTx(
|
||||
export async function createInteractionTx<Input>(
|
||||
arweave: Arweave,
|
||||
signer: SigningFunction,
|
||||
contractId: string,
|
||||
input: any,
|
||||
input: Input,
|
||||
tags: { name: string; value: string }[],
|
||||
target = '',
|
||||
winstonQty = '0',
|
||||
|
||||
@@ -2,17 +2,16 @@ export const enum SmartWeaveErrorType {
|
||||
CONTRACT_NOT_FOUND = 'CONTRACT_NOT_FOUND'
|
||||
}
|
||||
|
||||
export class SmartWeaveError extends Error {
|
||||
public readonly type: SmartWeaveErrorType;
|
||||
public readonly otherInfo: any;
|
||||
|
||||
constructor(
|
||||
type: SmartWeaveErrorType,
|
||||
optional: {
|
||||
type SmartWeaveErrorInfo = {
|
||||
message?: string;
|
||||
requestedTxId?: string;
|
||||
} = {}
|
||||
) {
|
||||
};
|
||||
|
||||
export class SmartWeaveError extends Error {
|
||||
public readonly type: SmartWeaveErrorType;
|
||||
public readonly otherInfo: SmartWeaveErrorInfo;
|
||||
|
||||
constructor(type: SmartWeaveErrorType, optional: SmartWeaveErrorInfo = {}) {
|
||||
if (optional.message) {
|
||||
super(optional.message);
|
||||
} else {
|
||||
|
||||
@@ -3,8 +3,10 @@ import { WarpLogger } from './WarpLogger';
|
||||
import { ConsoleLoggerFactory } from './web/ConsoleLoggerFactory';
|
||||
|
||||
export interface ILoggerFactory {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
setOptions(newOptions: any, moduleName?: string): void;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
getOptions(moduleName?: string): any;
|
||||
|
||||
logLevel(level: LogLevel, moduleName?: string): void;
|
||||
@@ -19,10 +21,12 @@ export class LoggerFactory implements ILoggerFactory {
|
||||
// not instantiable from outside
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
setOptions(newOptions: any, moduleName?: string): void {
|
||||
LoggerFactory.INST.setOptions(newOptions, moduleName);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
getOptions(moduleName?: string): any {
|
||||
return LoggerFactory.INST.getOptions(moduleName);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ export class Evolve implements ExecutionContextModifier {
|
||||
}
|
||||
}
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any -- dispatching of any type is done by this function */
|
||||
function evalSettings(state: any): Map<string, any> {
|
||||
// default - empty
|
||||
let settings = new Map<string, any>();
|
||||
@@ -112,6 +113,7 @@ function evalSettings(state: any): Map<string, any> {
|
||||
|
||||
return settings;
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||
|
||||
function isIterable(obj: unknown): boolean {
|
||||
// checks for null and undefined
|
||||
|
||||
@@ -29,6 +29,7 @@ export class ArweaveWrapper {
|
||||
return await this.doFetchInfo<NetworkInfoInterface>(`${this.baseUrl}/info`);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async gql(query: string, variables: GqlReqVariables): Promise<Partial<AxiosResponse<any>>> {
|
||||
try {
|
||||
const data = JSON.stringify({
|
||||
|
||||
@@ -36,6 +36,7 @@ export interface Proof {
|
||||
}
|
||||
|
||||
class BaseObject {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[key: string]: any;
|
||||
|
||||
public get(field: string): string;
|
||||
@@ -163,6 +164,7 @@ export class Transaction extends BaseObject implements TransactionInterface {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public async prepareChunks(data: Uint8Array) {
|
||||
throw new Error('Should not be called, use arweave-js version.');
|
||||
}
|
||||
@@ -194,6 +196,7 @@ export class Tag extends BaseObject {
|
||||
readonly name: string;
|
||||
readonly value: string;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public constructor(name: string, value: string, decode = false) {
|
||||
super();
|
||||
this.name = name;
|
||||
|
||||
@@ -67,4 +67,5 @@ export function readJSON(path: string): JWKInterface {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
main().catch((e) => console.error(e));
|
||||
|
||||
Reference in New Issue
Block a user