How to use the @requestnetwork/utils.getCurrentTimestampInSecond function in @requestnetwork/utils

To help you get started, we’ve selected a few @requestnetwork/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / requestNetwork / packages / request-logic / src / actions / create.ts View on Github external
if (
    requestParameters.payee &&
    requestParameters.payee.type !== IdentityTypes.TYPE.ETHEREUM_ADDRESS
  ) {
    throw new Error('payee.type not supported');
  }

  if (
    requestParameters.payer &&
    requestParameters.payer.type !== IdentityTypes.TYPE.ETHEREUM_ADDRESS
  ) {
    throw new Error('payer.type not supported');
  }

  if (!requestParameters.timestamp) {
    requestParameters.timestamp = Utils.getCurrentTimestampInSecond();
  }

  // convert expectedAmount to string to have a consistent numbering
  requestParameters.expectedAmount = requestParameters.expectedAmount.toString();
  const version = Version.currentVersion;

  const unsignedAction: RequestLogicTypes.IUnsignedAction = {
    name: RequestLogicTypes.ACTION_NAME.CREATE,
    parameters: requestParameters,
    version,
  };

  const signerRole: RequestLogicTypes.ROLE = Action.getRoleInUnsignedAction(
    signerIdentity,
    unsignedAction,
  );
github RequestNetwork / requestNetwork / packages / data-access / src / data-access.ts View on Github external
public async synchronizeNewDataIds(): Promise {
    this.checkInitialized();
    const synchronizationFrom = this.lastSyncStorageTimestamp;
    const synchronizationTo = Utils.getCurrentTimestampInSecond();

    // Read new data from storage
    const newDataWithMeta = await this.storage.getData({
      from: synchronizationFrom,
      to: synchronizationTo,
    });

    // check if the data returned by getNewDataId are correct
    // if yes, the dataIds are indexed with LocationByTopic
    await this.pushLocationsWithTopics(newDataWithMeta);

    // The last synced timestamp is the latest one returned by storage
    this.lastSyncStorageTimestamp = newDataWithMeta.meta.lastTimestamp;
  }
github RequestNetwork / requestNetwork / packages / data-access / src / data-access.ts View on Github external
public async initialize(): Promise {
    if (this.isInitialized) {
      throw new Error('already initialized');
    }
    await this.transactionIndex.initialize();

    // initialize storage
    await this.storage.initialize();

    // if transaction index already has data, then sync from the last available timestamp
    const lastSynced = await this.transactionIndex.getLastTransactionTimestamp();
    const now = Utils.getCurrentTimestampInSecond();

    // initialize the dataId topic with the previous block
    const allDataWithMeta = await this.storage.getData(
      lastSynced
        ? {
            from: lastSynced,
            to: now,
          }
        : undefined,
    );

    // The last synced timestamp is the latest one returned by storage
    this.lastSyncStorageTimestamp = allDataWithMeta.meta.lastTimestamp;

    // check if the data returned by getDataId are correct
    // if yes, the dataIds are indexed with LocationByTopic
github RequestNetwork / requestNetwork / packages / prototype-estimator / src / mock-storage.ts View on Github external
public async append(content: string): Promise {
    if (!content) {
      throw Error('Error: no content provided');
    }
    const hash = Utils.crypto.normalizeKeccak256Hash(content);

    const timestamp = Utils.getCurrentTimestampInSecond();
    this.data[hash] = { content, timestamp };

    return {
      meta: {
        storageType: StorageTypes.StorageSystemType.IN_MEMORY_MOCK,
        timestamp,
      },
      result: {
        dataId: hash,
      },
    };
  }
github RequestNetwork / requestNetwork / packages / request-client.js / src / mock-storage.ts View on Github external
public async append(content: string): Promise {
    if (!content) {
      throw Error('Error: no content provided');
    }
    const hash = Utils.crypto.normalizeKeccak256Hash(content);

    const nowTimestampInSec = Utils.getCurrentTimestampInSecond();

    this.data[hash] = { content, timestamp: nowTimestampInSec };

    return {
      meta: {
        storageType: StorageTypes.StorageSystemType.IN_MEMORY_MOCK,
        timestamp: nowTimestampInSec,
      },
      result: {
        dataId: hash,
      },
    };
  }
github RequestNetwork / requestNetwork / packages / usage-examples / src / mock / mock-storage.ts View on Github external
public async append(content: string): Promise {
    if (!content) {
      throw Error('Error: no content provided');
    }
    const hash = Utils.crypto.normalizeKeccak256Hash(content);

    const nowTimestampInSec = Utils.getCurrentTimestampInSecond();

    this.data[hash] = { content, timestamp: nowTimestampInSec };

    return {
      meta: {
        storageType: StorageTypes.StorageSystemType.IN_MEMORY_MOCK,
        timestamp: nowTimestampInSec,
      },
      result: {
        dataId: hash,
      },
    };
  }
github RequestNetwork / requestNetwork / packages / prototype-estimator / src / mock-storage.ts View on Github external
public async getData(): Promise {
    const results = Object.values(this.data).map(data => String(data.content));
    const dataIds = Object.keys(this.data);

    const nowTimestampInSec = Utils.getCurrentTimestampInSecond();

    return {
      meta: {
        lastTimestamp: nowTimestampInSec,
        metaData: new Array(results.length).fill({
          storageType: StorageTypes.StorageSystemType.IN_MEMORY_MOCK,
        }),
      },
      result: {
        data: results,
        dataIds,
      },
    };
  }
}
github RequestNetwork / requestNetwork / packages / request-client.js / src / mock-storage.ts View on Github external
public async getData(): Promise {
    const dataIds = Object.keys(this.data);
    const results = Object.values(this.data).map(elem => elem.content);
    const metaData = Object.values(this.data).map(elem => {
      return {
        storageType: StorageTypes.StorageSystemType.IN_MEMORY_MOCK,
        timestamp: elem.timestamp,
      };
    });

    const nowTimestampInSec = Utils.getCurrentTimestampInSecond();

    return {
      meta: {
        lastTimestamp: nowTimestampInSec,
        metaData,
      },
      result: {
        data: results,
        dataIds,
      },
    };
  }
}