-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor rpc logic into separate class
feat: add rpc_url and faas_url as config file options feat: create and start campaign with fuzz run command feat: print url with faas frontend report link
- Loading branch information
1 parent
da61537
commit d7dcd18
Showing
3 changed files
with
115 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from pathlib import Path | ||
import json | ||
import os | ||
import logging | ||
import click | ||
import requests | ||
|
||
LOGGER = logging.getLogger("mythx-cli") | ||
|
||
headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
time_limit_seconds = 3000 | ||
|
||
|
||
class RPCClient(): | ||
def __init__(self, rpc_url: str): | ||
self.rpc_url = rpc_url | ||
|
||
|
||
def rpc_call(self, method: str, params: str): | ||
payload = "{\"jsonrpc\":\"2.0\",\"method\":\"" + method + "\",\"params\":" + params + ",\"id\":1}" | ||
response = (requests.request("POST", self.rpc_url, headers=headers, data=payload)).json() | ||
return response["result"] | ||
|
||
|
||
def get_block(self, latest: bool = False, block_number: int = -1): | ||
block_value = "latest" if latest else str(block_number) | ||
if not latest: | ||
block_value = hex(block_number) | ||
|
||
block = self.rpc_call("eth_getBlockByNumber", "[\"" + block_value + "\", true]") | ||
if block is None: | ||
return None | ||
else: | ||
return block | ||
|
||
|
||
def get_all_blocks(self): | ||
latest_block = self.get_block(latest=True) | ||
if not latest_block: | ||
return [] | ||
|
||
blocks = [] | ||
for i in range(0, int(latest_block["number"], 16) + 1, 1): | ||
blocks.append(self.get_block(block_number=i)) | ||
return blocks | ||
|
||
|
||
def get_seed_state(self, address: str, other_addresses: [str], number_of_cores: int): | ||
blocks = self.get_all_blocks() | ||
processed_transactions = [] | ||
for block in blocks: | ||
for transaction in block["transactions"]: | ||
for key, value in dict(transaction).items(): | ||
if value is None: | ||
transaction[key] = "" | ||
processed_transactions.append(transaction) | ||
setup = dict({ | ||
"address-under-test": address, | ||
"steps": processed_transactions, | ||
"other-addresses-under-test": other_addresses}) | ||
return dict( | ||
{ | ||
"time-limit-secs": time_limit_seconds, | ||
"analysis-setup": setup, | ||
"discovery-probability-threshold": 0.0, | ||
"assertion-checking-mode": 1, | ||
"emit-mythx-report": True, | ||
"num-cores": number_of_cores | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters