@rsksmart/rif-storage-pinning
Version:
Application for providing your storage space to other to use in exchange of RIF Tokens
201 lines (200 loc) • 6.79 kB
TypeScript
/**
* Basic logger interface used around the application.
*/
import type { BigNumber } from 'bignumber.js';
import type { Eth } from 'web3-eth';
import type { ClientOptions as IpfsOptions } from 'ipfs-http-client/src/lib/core';
import type { Libp2pOptions } from 'libp2p';
import type { EventsEmitterCreationOptions, NewBlockEmitterOptions } from '@rsksmart/web3-events';
import type { ProviderManager } from './providers';
import * as storageEvents from '@rsksmart/rif-marketplace-storage/types/web3-v1-contracts/StorageManager';
import * as stakingEvents from '@rsksmart/rif-marketplace-storage/types/web3-v1-contracts/Staking';
export declare enum Providers {
IPFS = "ipfs"
}
export interface Provider {
pin(hash: string, expectedSize: BigNumber, peerId?: string): Promise<void>;
unpin(hash: string): void;
}
/**
* Basic logger interface used around the application.
*/
export interface Logger {
critical(message: string | Error | Record<string, unknown>, ...meta: any[]): never;
error(message: string | Error | Record<string, unknown>, ...meta: any[]): void;
warn(message: string | Record<string, unknown>, ...meta: any[]): void;
info(message: string | Record<string, unknown>, ...meta: any[]): void;
verbose(message: string | Record<string, unknown>, ...meta: any[]): void;
debug(message: string | Record<string, unknown>, ...meta: any[]): void;
extend?: (name: string) => Logger;
}
export declare enum CommunicationTransport {
Cache = "cache",
Libp2p = "libp2p"
}
export declare enum Strategy {
Blockchain = "blockchain",
Marketplace = "marketplace"
}
export interface JobManagerOptions {
retries?: number;
backoffTime?: number;
exponentialBackoff?: boolean;
}
export interface Config {
uiUrl?: string;
comms?: {
transport?: CommunicationTransport;
libp2p?: Libp2pOptions;
countOfMessagesPersistedPerAgreement?: number;
};
directAddress?: {
ttl?: string;
};
strategy?: Strategy;
blockchain?: {
provider?: string;
contractAddress?: string;
eventsEmitter?: EventsEmitterCreationOptions;
newBlockEmitter?: NewBlockEmitterOptions;
};
marketplace?: {
offer?: string;
agreement?: string;
reorg?: string;
provider?: string;
};
ipfs?: {
clientOptions?: IpfsOptions;
sizeFetchTimeout?: number | string;
};
jobs?: JobManagerOptions;
log?: {
level?: string;
filter?: string;
path?: string;
};
}
export declare enum JobState {
RUNNING = "running",
BACKOFF = "backoff",
CREATED = "created",
ERRORED = "errored",
FINISHED = "finished"
}
export declare type ErrorHandler = (fn: (...args: any[]) => Promise<void>, logger: Logger) => (...args: any[]) => Promise<void>;
export interface AppOptions {
appResetCallback: () => void;
forcePrecache?: boolean;
errorHandler?: ErrorHandler;
contractAddress?: string;
strategy?: Strategy;
}
/**
* Events interfaces.
*/
export interface MarketplaceEvent {
event: string;
payload: Record<string, any>;
}
export declare type BlockchainAgreementEvents = storageEvents.AgreementFundsDeposited | storageEvents.AgreementFundsPayout | storageEvents.AgreementFundsWithdrawn | storageEvents.AgreementStopped;
export declare type BlockchainAgreementEventsWithNewAgreement = BlockchainAgreementEvents | storageEvents.NewAgreement;
export declare type BlockchainOfferEvents = storageEvents.BillingPlanSet | storageEvents.MessageEmitted | storageEvents.TotalCapacitySet;
export declare type BlockchainStakeEvents = stakingEvents.Staked | stakingEvents.Unstaked;
export declare type BlockchainEventsWithProvider = BlockchainOfferEvents | storageEvents.NewAgreement;
export declare type BlockchainEvent = BlockchainOfferEvents | BlockchainAgreementEventsWithNewAgreement | BlockchainStakeEvents;
export declare type StorageEvents = BlockchainEvent | MarketplaceEvent;
/**
* Interfaces for Processor.
*/
export declare type Processor<T> = (event: T) => Promise<void>;
export declare type BaseEventProcessorOptions = {
manager?: ProviderManager;
};
export declare type BlockchainEventProcessorOptions = {
eth: Eth;
} & BaseEventProcessorOptions;
export declare type EventProcessorOptions = BaseEventProcessorOptions | BlockchainEventProcessorOptions;
export declare type GetProcessorOptions = {
errorHandler?: ErrorHandler;
errorLogger?: Logger;
};
/**
* Interface for object with event handler functions
*/
export declare type HandlersObject<T extends StorageEvents, O extends EventProcessorOptions> = {
[key: string]: (event: T, options: O) => Promise<void>;
};
/**
* Interface for more complex handling of events.
*/
export interface EventsHandler<T extends StorageEvents, O extends EventProcessorOptions> {
events: string[];
process: (event: T, options: O) => Promise<void>;
}
/****************************************************************************************
* CLI
*/
export declare type CliInitDbOptions = {
migrate?: boolean;
};
export interface InitCommandOption {
db?: CliInitDbOptions;
baseConfig?: boolean;
serviceRequired?: boolean;
}
/****************************************************************************************
* Communications
*/
export declare enum MessageCodesEnum {
I_GENERAL = "I_GEN",
I_AGREEMENT_NEW = "I_AGR_NEW",
I_AGREEMENT_STOPPED = "I_AGR_STOP",
I_AGREEMENT_EXPIRED = "I_AGR_EXP",
I_HASH_START = "I_HASH_START",
I_HASH_PINNED = "I_HASH_STOP",
I_MULTIADDR_ANNOUNCEMENT = "I_ADDR_ANNOUNCE",
I_RESEND_LATEST_MESSAGES = "I_RESEND",
W_GENERAL = "W_GEN",
W_HASH_RETRY = "W_HASH_RETRY",
E_GENERAL = "E_GEN",
E_HASH_NOT_FOUND = "E_HASH_404",
E_AGREEMENT_SIZE_LIMIT_EXCEEDED = "E_AGR_SIZE_OVERFLOW"
}
interface BasePayload {
agreementReference: string;
}
export interface RetryPayload extends BasePayload {
error: string;
retryNumber: number;
totalRetries: number;
}
export interface HashInfoPayload extends BasePayload {
hash: string;
}
export declare type AgreementInfoPayload = BasePayload;
export interface AgreementSizeExceededPayload extends BasePayload {
hash: string;
size: number;
expectedSize: number;
}
export interface MultiaddrAnnouncementPayload {
agreementReference: string;
peerId: string;
}
export interface ResendMessagesPayload {
requestId: string;
agreementReference: string;
code?: string;
}
export interface CommsMessage<Payload> {
timestamp: number;
version: number;
code: string;
payload: Payload;
}
export interface CommsTransport {
broadcast(message: CommsMessage<any>): Promise<void>;
stop(): void;
}
export {};