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

Commit

Permalink
[backend] add logs to backend getNotes
Browse files Browse the repository at this point in the history
  • Loading branch information
YBadiss committed Apr 5, 2024
1 parent b344b2b commit 22a1611
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { config } from "../env";

export interface NetworkConfig {
NETWORK_NAME: string;
INFRA_RPC_URL: string;
AVERAGE_BLOCKTIME: number;
MAIN_CONTRACT_ADDRESS: string;
Expand All @@ -16,13 +17,15 @@ export interface NetworkConfigs {

const networks: NetworkConfigs = {
BASE_MAINNET: {
NETWORK_NAME: "Base Mainnet",
INFRA_RPC_URL: "<OVERRIDE ME>",
AVERAGE_BLOCKTIME: 2000,
MAIN_CONTRACT_ADDRESS: "0xde31FB31adeB0a97E34aCf7EF4e21Ad585F667f7",
NFT_CONTRACT_ADDRESS: "0x8885DC14732AE2ADd64d8C6581E722F0A88aA3Da",
SFT_CONTRACT_ADDRESS: "0x77840A1815f4F62a4cCCA3aBA3566fB8ff0b10D0",
},
ETHEREUM_SEPOLIA: {
NETWORK_NAME: "Ethereum Sepolia",
INFRA_RPC_URL: "<OVERRIDE ME>",
AVERAGE_BLOCKTIME: 12000,
MAIN_CONTRACT_ADDRESS: "0x3b5946b3bd79c2B211E49c3149872f1d66223AE7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ export class NoteService {
): Promise<Note[]> => {
const lookBackDays =
paramLookBackDays || parseInt(this.config.LOOKBACK_DAYS);
console.log(`Getting notes awaiting rating by ${byAddress} over the last ${lookBackDays} days`);
const notes = await this.reader.getNotes(predicate, lookBackDays);
// factchainer can't rate their own note
const othersNotes = notes.filter(
(note) => note.creatorAddress.toLowerCase() != byAddress.toLowerCase(),
);
console.log(`Getting ratings for ${othersNotes.length} notes`);
// factchainer can rate the same note only once
// and can't rate finalised notes
const awaitingRatingBy = await Promise.all(
Expand Down
7 changes: 4 additions & 3 deletions fc-community-backend/apps/api/src/factchain-core/web2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class DBConnector implements NoteReader {
config.NOTE_FINALISER_PKEY,
this._provider,
);

this._fcCommunity = new ethers.Contract(
this._network.MAIN_CONTRACT_ADDRESS,
FC_COMMUNITY_JSON_ABI,
Expand All @@ -53,21 +54,21 @@ export class DBConnector implements NoteReader {
from: number,
to: number,
): Promise<FactchainEvent[]> => {
console.log(`Getting events of type ${eventName} from ${from} to ${to} for network ${this._network.NETWORK_NAME}`);
const client = this.getClient();
try {
const db = client.db("fc-community");
const collection = db.collection("events");
const cursor = collection.find({
networkName: this._network.INFRA_RPC_URL.includes("sepolia")
? "Ethereum Sepolia"
: "Base Mainnet",
networkName: this._network.NETWORK_NAME,
eventName: eventName,
blockTimestamp: {
$gte: from,
$lte: to,
},
});
const documents = await cursor.toArray();
console.log(`Retrieved ${documents.length()} events of type ${eventName} for network ${this._network.NETWORK_NAME}`);
const events: FactchainEvent[] = documents.map((document) => ({
networkName: document.networkName,
contractAddress: document.contractAddress,
Expand Down
3 changes: 3 additions & 0 deletions fc-community-backend/apps/shared/src/networks/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { config } from "../env";

export interface NetworkConfig {
NETWORK_NAME: string;
INFRA_RPC_URL: string;
AVERAGE_BLOCKTIME: number;
MAIN_CONTRACT_ADDRESS: string;
Expand All @@ -16,13 +17,15 @@ export interface NetworkConfigs {

const networks: NetworkConfigs = {
BASE_MAINNET: {
NETWORK_NAME: "Base Mainnet",
INFRA_RPC_URL: "<OVERRIDE ME>",
AVERAGE_BLOCKTIME: 2000,
MAIN_CONTRACT_ADDRESS: "0xde31FB31adeB0a97E34aCf7EF4e21Ad585F667f7",
NFT_CONTRACT_ADDRESS: "0x8885DC14732AE2ADd64d8C6581E722F0A88aA3Da",
SFT_CONTRACT_ADDRESS: "0x77840A1815f4F62a4cCCA3aBA3566fB8ff0b10D0",
},
ETHEREUM_SEPOLIA: {
NETWORK_NAME: "Ethereum Sepolia",
INFRA_RPC_URL: "<OVERRIDE ME>",
AVERAGE_BLOCKTIME: 12000,
MAIN_CONTRACT_ADDRESS: "0x3b5946b3bd79c2B211E49c3149872f1d66223AE7",
Expand Down
2 changes: 2 additions & 0 deletions fc-community-backend/apps/shared/src/noteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ export class NoteService {
): Promise<Note[]> => {
const lookBackDays =
paramLookBackDays || parseInt(this.config.LOOKBACK_DAYS);
console.log(`Getting notes awaiting rating by ${byAddress} over the last ${lookBackDays} days`);
const notes = await this.reader.getNotes(predicate, lookBackDays);
// factchainer can't rate their own note
const othersNotes = notes.filter(
(note) => note.creatorAddress.toLowerCase() != byAddress.toLowerCase(),
);
console.log(`Getting ratings for ${othersNotes.length} notes`);
// factchainer can rate the same note only once
// and can't rate finalised notes
const awaitingRatingBy = await Promise.all(
Expand Down
6 changes: 3 additions & 3 deletions fc-community-backend/apps/shared/src/web2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ export class DBConnector implements NoteReader {
from: number,
to: number,
): Promise<FactchainEvent[]> => {
console.log(`Getting events of type ${eventName} from ${from} to ${to} for network ${this._network.NETWORK_NAME}`);
const client = this.getClient();
try {
const db = client.db("fc-community");
const collection = db.collection("events");
const cursor = collection.find({
networkName: this._network.INFRA_RPC_URL.includes("sepolia")
? "Ethereum Sepolia"
: "Base Mainnet",
networkName: this._network.NETWORK_NAME,
eventName: eventName,
blockTimestamp: {
$gte: from,
$lte: to,
},
});
const documents = await cursor.toArray();
console.log(`Retrieved ${documents.length()} events of type ${eventName} for network ${this._network.NETWORK_NAME}`);
const events: FactchainEvent[] = documents.map((document) => ({
networkName: document.networkName,
contractAddress: document.contractAddress,
Expand Down

0 comments on commit 22a1611

Please sign in to comment.