Skip to content

Commit

Permalink
linter fixes and linter dep upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Aug 10, 2023
1 parent 4f16c8f commit 675e61b
Show file tree
Hide file tree
Showing 57 changed files with 9,158 additions and 18,644 deletions.
27,031 changes: 8,765 additions & 18,266 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"eslint-formatter-codeframe": "^7.32.1",
"eslint-plugin-implicit-dependencies": "^1.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1"
"eslint-plugin-prettier": "^5.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const main = async () => {
allowUnverifiedSessions: true,
},
bindAddrs: {
ip4: initMa
ip4: initMa,
},
} as any
const portal = await PortalNetwork.create({
Expand Down
30 changes: 15 additions & 15 deletions packages/cli/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class eth {
this.getBlockTransactionCountByHash = middleware(
this.getBlockTransactionCountByHash.bind(this),
1,
[[validators.hex, validators.blockHash]]
[[validators.hex, validators.blockHash]],
)

this.getUncleCountByBlockNumber = middleware(this.getUncleCountByBlockNumber.bind(this), 1, [
Expand All @@ -63,14 +63,14 @@ export class eth {
fromBlock: validators.optional(validators.blockOption),
toBlock: validators.optional(validators.blockOption),
address: validators.optional(
validators.either(validators.array(validators.address), validators.address)
validators.either(validators.array(validators.address), validators.address),
),
topics: validators.optional(
validators.array(
validators.optional(
validators.either(validators.hex, validators.array(validators.hex))
)
)
validators.either(validators.hex, validators.array(validators.hex)),
),
),
),
blockHash: validators.optional(validators.blockHash),
}),
Expand All @@ -96,18 +96,18 @@ export class eth {
async getBlockByHash(params: [string, boolean]): Promise<Block> {
const [blockHash, includeTransactions] = params
this._client.logger(
`eth_getBlockByHash request received. blockHash: ${blockHash} includeTransactions: ${includeTransactions}`
`eth_getBlockByHash request received. blockHash: ${blockHash} includeTransactions: ${includeTransactions}`,
)
await this._history.ETH.getBlockByHash(blockHash, includeTransactions)
const headerWithProof = await this._history.findContentLocally(
fromHexString(getContentKey(0, fromHexString(blockHash)))
fromHexString(getContentKey(0, fromHexString(blockHash))),
)
if (!headerWithProof) {
throw new Error('Block not found')
}
const header = BlockHeaderWithProof.deserialize(headerWithProof).header
const body = await this._history.findContentLocally(
fromHexString(getContentKey(1, fromHexString(blockHash)))
fromHexString(getContentKey(1, fromHexString(blockHash))),
)
if (!body) {
throw new Error('Block not found')
Expand All @@ -126,11 +126,11 @@ export class eth {
async getBlockByNumber(params: [string, boolean]): Promise<Block> {
const [blockNumber, includeTransactions] = params
this.logger(
`eth_getBlockByNumber request received. blockNumber: ${blockNumber} includeTransactions: ${includeTransactions}`
`eth_getBlockByNumber request received. blockNumber: ${blockNumber} includeTransactions: ${includeTransactions}`,
)
const block = await this._history.ETH.getBlockByNumber(
parseInt(blockNumber),
includeTransactions
includeTransactions,
)
if (block === undefined) throw new Error('block not found')
this.logger(block)
Expand Down Expand Up @@ -258,16 +258,16 @@ export class eth {
(await this.getBlockByNumber([
bigIntToHex(BigInt(i) + from.header.number),
true,
])) as Block
)
])) as Block,
),
) //@ts-ignore
const logs = await getLogs(await blocks, addrs, formattedTopics)
return await Promise.all(
logs.map(
(
{ log, block, tx, txIndex, logIndex } //@ts-ignore
) => jsonRpcLog(log, block, tx, txIndex, logIndex)
)
{ log, block, tx, txIndex, logIndex }, //@ts-ignore
) => jsonRpcLog(log, block, tx, txIndex, logIndex),
),
)
} catch (error: any) {
throw {
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/rpc/modules/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class portal {
const [enrs] = params
const encodedENRs = enrs.map((enr) => ENR.decodeTxt(enr))
const shortEnrs = Object.fromEntries(
encodedENRs.map((enr, idx) => [idx, enr.nodeId.slice(0, 15) + '...'])
encodedENRs.map((enr, idx) => [idx, enr.nodeId.slice(0, 15) + '...']),
)
this.logger(`portal_historyAddEnrs request received for ${shortEnrs}`)
const added: number[] = []
Expand Down Expand Up @@ -270,7 +270,7 @@ export class portal {
await this._client.sendPortalNetworkResponse(
{ nodeId: enr.nodeId, socketAddr: enr.getLocationMultiaddr('udp')! },
BigInt(requestId),
Buffer.from(pongMsg)
Buffer.from(pongMsg),
)
} catch {
return false
Expand Down Expand Up @@ -335,7 +335,7 @@ export class portal {
socketAddr: enr.getLocationMultiaddr('udp')!,
},
BigInt(requestId),
Uint8Array.from(encodedPayload)
Uint8Array.from(encodedPayload),
)

return enrs.length > 0 ? 1 : 0
Expand Down Expand Up @@ -387,7 +387,7 @@ export class portal {
clearTimeout(timeout)
resolve(value)
}
}
},
)
})
this.logger.extend('findContent')(`request returned ${content.length} bytes`)
Expand All @@ -414,7 +414,7 @@ export class portal {
this._client.sendPortalNetworkResponse(
{ nodeId, socketAddr: enr?.getLocationMultiaddr('udp')! },
enr!.seq,
Buffer.concat([Buffer.from([MessageCodes.CONTENT]), Buffer.from(payload)])
Buffer.concat([Buffer.from([MessageCodes.CONTENT]), Buffer.from(payload)]),
)
return '0x' + enr!.seq.toString(16)
}
Expand All @@ -440,7 +440,7 @@ export class portal {
await this._history.store(
contentKey.contentType,
contentKey.blockHash,
fromHexString(contentValueHex)
fromHexString(contentValueHex),
)
const res = await this._history.sendOffer(enr.nodeId, [fromHexString(contentKeyHex)])
return res
Expand Down Expand Up @@ -480,7 +480,7 @@ export class portal {
socketAddr: _enr.getLocationMultiaddr('udp')!,
},
myEnr.seq,
Buffer.from(encodedPayload)
Buffer.from(encodedPayload),
)

return '0x' + myEnr.seq.toString(16)
Expand All @@ -496,7 +496,7 @@ export class portal {
await this._history.store(
contentKey[0] as ContentType,
toHexString(contentKey.slice(1)),
content
content,
)
return true
} catch {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/rpc/modules/ultralight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ultralight {

const [blockHash, rlpHex] = params
const protocol = this._client.protocols.get(
ProtocolId.HistoryNetwork
ProtocolId.HistoryNetwork,
) as never as HistoryProtocol
try {
addRLPSerializedBlock(rlpHex, blockHash, protocol)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/rpc/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class RPCManager {
*/
static getMethodNames(mod: Object): string[] {
const methodNames = Object.getOwnPropertyNames((mod as any).prototype).filter(
(methodName: string) => methodName !== 'constructor'
(methodName: string) => methodName !== 'constructor',
)
return methodNames
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/rpc/schema/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const portalSchema = {
},
get ipAddr() {
const ipAddr: RegExp = new RegExp(
'((^\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\\s*$)|(^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\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|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$))',
)
return (params: any[], index: number) => {
if (typeof params[index] !== 'string') {
Expand Down Expand Up @@ -100,7 +100,7 @@ export const portalSchema = {
},
get socketAddr() {
const socketAddr: RegExp = new RegExp(
'/([0-9]{1,3}(?:\\.[0-9]{1,3}){3}|(?=[^\\/]{1,254}(?![^\\/]))(?:(?=[a-zA-Z0-9-]{1,63}\\.)(?:xn--+)?[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*\\.)+[a-zA-Z]{2,63}):([0-9]{1,5})$'
'/([0-9]{1,3}(?:\\.[0-9]{1,3}){3}|(?=[^\\/]{1,254}(?![^\\/]))(?:(?=[a-zA-Z0-9-]{1,63}\\.)(?:xn--+)?[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*\\.)+[a-zA-Z]{2,63}):([0-9]{1,5})$',
)
return (params: any[], index: number) => {
if (typeof params[index] !== 'string') {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/rpc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ export const jsonRpcTx = (tx: TypedTransaction, block?: Block, txIndex?: number)
export const jsonRpcBlock = async (
block: Block,
// chain: Chain,
includeTransactions: boolean
includeTransactions: boolean,
): Promise<JsonRpcBlock> => {
const json = block.toJSON()
const header = json!.header!
const transactions = block.transactions.map((tx, txIndex) =>
includeTransactions ? jsonRpcTx(tx, block, txIndex) : bytesToHex(tx.hash())
includeTransactions ? jsonRpcTx(tx, block, txIndex) : bytesToHex(tx.hash()),
)
// const td = await chain.getTd(block.hash(), block.header.number)
return {
Expand Down Expand Up @@ -170,7 +170,7 @@ export const jsonRpcLog = async (
block?: Block,
tx?: TypedTransaction,
txIndex?: number,
logIndex?: number
logIndex?: number,
): Promise<JsonRpcLog> => ({
removed: false, // TODO implement
logIndex: logIndex !== undefined ? intToHex(logIndex) : null,
Expand All @@ -194,7 +194,7 @@ export const jsonRpcReceipt = async (
tx: TypedTransaction,
txIndex: number,
logIndex: number,
contractAddress?: Address
contractAddress?: Address,
): Promise<JsonRpcReceipt> => ({
transactionHash: bytesToHex(tx.hash()),
transactionIndex: intToHex(txIndex),
Expand All @@ -207,7 +207,7 @@ export const jsonRpcReceipt = async (
gasUsed: bigIntToHex(gasUsed),
contractAddress: contractAddress?.toString() ?? null,
logs: await Promise.all(
receipt.logs.map((l: Log, i: number) => jsonRpcLog(l, block, tx, txIndex, logIndex + i))
receipt.logs.map((l: Log, i: number) => jsonRpcLog(l, block, tx, txIndex, logIndex + i)),
),
logsBloom: bytesToHex(receipt.bitvector),
root:
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ export const jsonRpcTx = (tx: TypedTransaction, block?: Block, txIndex?: number)
export const jsonRpcBlock = async (
block: Block,
// chain: Chain,
includeTransactions: boolean
includeTransactions: boolean,
): Promise<JsonRpcBlock> => {
const json = block.toJSON()
const header = json!.header!
const transactions = block.transactions.map((tx, txIndex) =>
includeTransactions ? jsonRpcTx(tx, block, txIndex) : bytesToHex(tx.hash())
includeTransactions ? jsonRpcTx(tx, block, txIndex) : bytesToHex(tx.hash()),
)
// const td = await chain.getTd(block.hash(), block.header.number)
return {
Expand Down Expand Up @@ -212,7 +212,7 @@ export const jsonRpcLog = async (
block?: Block,
tx?: TypedTransaction,
txIndex?: number,
logIndex?: number
logIndex?: number,
): Promise<JsonRpcLog> => ({
removed: false, // TODO implement
logIndex: logIndex !== undefined ? intToHex(logIndex) : null,
Expand All @@ -236,7 +236,7 @@ export const jsonRpcReceipt = async (
tx: TypedTransaction,
txIndex: number,
logIndex: number,
contractAddress?: Address
contractAddress?: Address,
): Promise<JsonRpcReceipt> => ({
transactionHash: bytesToHex(tx.hash()),
transactionIndex: intToHex(txIndex),
Expand All @@ -249,7 +249,7 @@ export const jsonRpcReceipt = async (
gasUsed: bigIntToHex(gasUsed),
contractAddress: contractAddress?.toString() ?? null,
logs: await Promise.all(
receipt.logs.map((l: Log, i: number) => jsonRpcLog(l, block, tx, txIndex, logIndex + i))
receipt.logs.map((l: Log, i: number) => jsonRpcLog(l, block, tx, txIndex, logIndex + i)),
),
logsBloom: bytesToHex(receipt.bitvector),
root:
Expand Down
16 changes: 8 additions & 8 deletions packages/portalnetwork/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent

config.peerId = await peerIdFromKeys(
fromHexString(prevPublicKey),
fromHexString(prevPrivateKey)
fromHexString(prevPrivateKey),
)

config.enr = SignableENR.decodeTxt(prevEnrString, createKeypairFromPeerId(config.peerId))
Expand Down Expand Up @@ -172,7 +172,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
this.logger,
opts.dbSize,
opts.supportedProtocols,
opts.db
opts.db,
) as DBManager
opts.supportedProtocols = opts.supportedProtocols ?? []
for (const protocol of opts.supportedProtocols) {
Expand Down Expand Up @@ -244,7 +244,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
// Start kbucket refresh on 30 second interval
this.refreshListeners.set(
protocol.protocolId,
setInterval(() => protocol.bucketRefresh(), 30000)
setInterval(() => protocol.bucketRefresh(), 30000),
)
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
const protocol = this.protocols.get(toHexString(message.protocol) as ProtocolId)
if (!protocol) {
this.logger(
`Received TALKREQ message on unsupported protocol ${toHexString(message.protocol)}`
`Received TALKREQ message on unsupported protocol ${toHexString(message.protocol)}`,
)
await this.sendPortalNetworkResponse(src, message.id, new Uint8Array())

Expand All @@ -340,7 +340,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
src: INodeAddress,
srcId: NodeId,
msg: ITalkReqMessage,
packetBuffer: Buffer
packetBuffer: Buffer,
) => {
await this.sendPortalNetworkResponse(src, msg.id, new Uint8Array())
await this.uTP.handleUtpPacket(packetBuffer, srcId)
Expand All @@ -357,7 +357,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
enr: ENR | string,
payload: Uint8Array,
protocolId: ProtocolId,
utpMessage?: boolean
utpMessage?: boolean,
): Promise<Uint8Array> => {
const messageProtocol = utpMessage ? ProtocolId.UTPNetwork : protocolId
try {
Expand All @@ -384,7 +384,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
const res = await this.discv5.sendTalkReq(
nodeAddr,
Buffer.from(payload),
fromHexString(messageProtocol)
fromHexString(messageProtocol),
)
return res
} catch (err: any) {
Expand All @@ -399,7 +399,7 @@ export class PortalNetwork extends (EventEmitter as { new (): PortalNetworkEvent
public sendPortalNetworkResponse = async (
src: INodeAddress,
requestId: bigint,
payload: Uint8Array
payload: Uint8Array,
) => {
this.discv5.sendTalkResp(src, requestId, payload)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/portalnetwork/src/client/dbManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class DBManager {
logger: Debugger,
currentSize: () => Promise<number>,
sublevels: ProtocolId[] = [],
db?: AbstractLevel<string>
db?: AbstractLevel<string>,
) {
//@ts-ignore Because level doesn't know how to get along with itself
this.db = db ?? new MemoryLevel()
Expand Down
6 changes: 3 additions & 3 deletions packages/portalnetwork/src/client/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ export class UltralightProvider extends ethers.providers.StaticJsonRpcProvider {
public static create = async (
fallbackProviderUrl: string | ethers.providers.JsonRpcProvider,
network = 1,
opts: Partial<PortalNetworkOpts>
opts: Partial<PortalNetworkOpts>,
) => {
const portal = await PortalNetwork.create(opts)
return new UltralightProvider(fallbackProviderUrl, network, portal)
}
constructor(
fallbackProvider: string | ethers.providers.JsonRpcProvider,
network = 1,
portal: PortalNetwork
portal: PortalNetwork,
) {
super(
typeof fallbackProvider === 'string' ? fallbackProvider : fallbackProvider.connection,
network
network,
)
this.fallbackProvider =
typeof fallbackProvider === 'string'
Expand Down
Loading

0 comments on commit 675e61b

Please sign in to comment.