Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boolean flag to enable/disable sending L2 txs from watcher peer #354

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/mobymask-v2-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
relayMultiaddr = ''
pubSubTopic = 'mobymask'
peerIdFile = ''
enableL2Txs = false

[server.p2p.peer.l2TxConfig]
privateKey = ''
Expand Down
10 changes: 6 additions & 4 deletions packages/mobymask-v2-watcher/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import fs from 'fs';
import path from 'path';
import assert from 'assert';
import 'reflect-metadata';
import debug from 'debug';
import { ethers } from 'ethers';
Expand All @@ -23,11 +24,12 @@ export const main = async (): Promise<any> => {
await serverCmd.initIndexer(Indexer);

let p2pMessageHandler = parseLibp2pMessage;
const { l2TxConfig } = serverCmd.config.server.p2p.peer;
const { enableL2Txs, l2TxsConfig } = serverCmd.config.server.p2p.peer;

if (l2TxConfig) {
const wallet = new ethers.Wallet(l2TxConfig.privateKey, serverCmd.ethProvider);
p2pMessageHandler = createMessageToL2Handler(wallet, l2TxConfig);
if (enableL2Txs) {
assert(l2TxsConfig);
const wallet = new ethers.Wallet(l2TxsConfig.privateKey, serverCmd.ethProvider);
p2pMessageHandler = createMessageToL2Handler(wallet, l2TxsConfig);
}

const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString();
Expand Down
7 changes: 5 additions & 2 deletions packages/util/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface RelayConfig {
}

// L2 tx config
interface L2TxConfig {
interface L2TxsConfig {
// Address of contract for which txs are sent
contractAddress: string;

Expand Down Expand Up @@ -113,8 +113,11 @@ export interface PeerConfig {
// Participate in exchange of debug info over floodsub
enableDebugInfo?: boolean;

// Enable sending txs to L2 chain for every message received in P2P network
enableL2Txs: boolean;

// Config for sending txs to L2
l2TxConfig?: L2TxConfig;
l2TxsConfig?: L2TxsConfig;
}

// P2P config
Expand Down