Add timestamp to mobymask p2p messages (#340)

* Add timestamps to mobymask logs

* Fix getCurrentTime method calls

---------

Co-authored-by: Dhruv Srivastava <dhruvdhs.ds@gmail.com>
This commit is contained in:
Nabarun Gogoi 2023-03-17 15:08:15 +05:30 committed by GitHub
parent c44eff36b4
commit d221704baa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -83,7 +83,7 @@ export async function sendMessageToL2 (
}
export function parseLibp2pMessage (log: debug.Debugger, peerId: string, data: any): void {
log('Received a message on mobymask P2P network from peer:', peerId);
log(`[${getCurrentTime()}] Received a message on mobymask P2P network from peer:`, peerId);
const { kind, message } = data;
switch (kind) {
@ -107,6 +107,11 @@ export function parseLibp2pMessage (log: debug.Debugger, peerId: string, data: a
log('------------------------------------------');
}
export const getCurrentTime = (): string => {
const now = new Date();
return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
};
function _parseInvocation (log: debug.Debugger, msg: any): void {
log('Signed invocations:');
log(JSON.stringify(msg, null, 2));

View File

@ -10,7 +10,7 @@ import {
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1319854183
} from '@cerc-io/peer';
import { sendMessageToL2 } from './libp2p-utils';
import { getCurrentTime, sendMessageToL2 } from './libp2p-utils';
import { readPeerId } from '@cerc-io/cli';
import { ethers } from 'ethers';
@ -57,7 +57,7 @@ export const main = async (): Promise<any> => {
const wallet = new ethers.Wallet(argv.privateKey, ethProvider);
peer.subscribeTopic(peerConfig.pubSubTopic, (peerId, data) => {
log('Received a message on mobymask P2P network from peer:', peerId);
log(`[${getCurrentTime()}] Received a message on mobymask P2P network from peer:`, peerId);
// TODO: throttle message handler
sendMessageToL2(wallet, argv, data);