Exemple #1
0
    def get_storage(self,
                    address: str,
                    count: int = 10,
                    startFrom: str = "0",
                    block: int = None):
        """
        Get the first "count" number of an address. count default = 10
        """

        # We take the argument as a string to let int() infer whether it's a decimal or hex with minimum effort
        startFromInt = int(startFrom, 0)

        if address is None:
            cprint("Missing Argument 'address'?", "red")
            return 0

        if block is None:
            block = w3.eth.blockNumber

        cprint("Slot <number>\n = <hex value> (<decimal value>)\n", "cyan")

        address = Web3.toChecksumAddress(address)
        for i in range(0, count):
            hex_text = None
            # print(Web3.isAddress(Web3.toHex(w3.eth.getStorageAt(address, i))), Web3.toHex(w3.eth.getStorageAt(address, i))) #TODO: detect address

            try:  # TODO: make this smarter, detect the variable and show proper represantation of it .
                hex_text = Web3.toText(
                    w3.eth.getStorageAt(address,
                                        startFromInt + i,
                                        block_identifier=block))
            except:
                try:
                    hex_text = Web3.toInt(
                        w3.eth.getStorageAt(address,
                                            startFromInt + i,
                                            block_identifier=block))
                except:
                    hex_text = None

            cprint(
                "Slot {0:#032x}\n = {1} ({2})".format(
                    startFromInt + i,
                    Web3.toHex(
                        w3.eth.getStorageAt(address,
                                            startFromInt + i,
                                            block_identifier=block)),
                    hex_text,
                ),
                "green",
            )
Exemple #2
0
    def get_code(self, address: str, block: int = None):
        """
        Get code of the smart contract at address
        """

        if address is None:
            cprint("Missing Argument 'address'?", "red")
            return 0

        if block is None:
            block = w3.eth.blockNumber

        address = Web3.toChecksumAddress(address)
        cprint(
            "Code of {} = \n {}".format(
                address,
                Web3.toHex(w3.eth.getCode(address, block_identifier=block))),
            "yellow",
        )
Exemple #3
0
    def get_balance(self, address: str, block: int = None):  #  -> int:
        """
        Get Balance of an account
        """

        if address is None:
            cprint("Missing Argument 'address'?", "red")
            return 0

        if block is None:
            block = w3.eth.blockNumber

        address = Web3.toChecksumAddress(address)
        balance = w3.eth.getBalance(address, block_identifier=block)
        cprint(
            "Balance of {} is : {} wei ({} Eth)".format(
                address, balance, Web3.fromWei(balance, "ether")),
            "green",
        )
Exemple #4
0
    def get_storage(self, address: str, count: int = 10, block: int = None):
        """
        Get the first "count" number of an address. count default = 10
        """

        if address is None:
            cprint("Missing Argument 'address'?", "red")
            return 0

        if block is None:
            block = w3.eth.blockNumber

        address = Web3.toChecksumAddress(address)
        for i in range(0, count):
            hex_text = None
            # print(Web3.isAddress(Web3.toHex(w3.eth.getStorageAt(address, i))), Web3.toHex(w3.eth.getStorageAt(address, i))) #TODO: detect address

            try:  # TODO: make this smarter, detect the variable and show proper represantation of it .
                hex_text = Web3.toText(
                    w3.eth.getStorageAt(address, i, block_identifier=block))
            except:
                try:
                    hex_text = Web3.toInt(
                        w3.eth.getStorageAt(address, i,
                                            block_identifier=block))
                except:
                    hex_text = None

            cprint(
                "Storage {} = {} ({})".format(
                    i,
                    Web3.toHex(
                        w3.eth.getStorageAt(address, i,
                                            block_identifier=block)),
                    hex_text,
                ),
                "green",
            )
Exemple #5
0
import socket
import typing
import requests
from nubia import command, argument
from termcolor import cprint

from legions.context import context
from legions.version import __version__
from legions.network.web3 import Web3
from legions.utils.helper_functions import getChainName

INFURA_URL = "https://mainnet.infura.io/v3/c3914c0859de473b9edcd6f723b4ea69"
PEER_SAMPLE = "enode://000331f91e4343a7145be69f1d455b470d9ba90bdb6d74fe671b28af481361c931b632f03c03dde5ec4c34f2289064ccd4775f758fb95e9496a1bd5a619ae0fe@lfbn-lyo-1-210-35.w86-202.abo.wanadoo.fr:30303"
# TODO ^ a real verbose node for this!

w3 = Web3()
w3.connect(INFURA_URL)

LEGION_TEST_PASS = (
    "Legion2019"  # TODO: there should be a better (recoverable) way to do this.
)
LEGION_TEST_PRV = "0x28d96497361cfc7cde5f253232d1ea300333891792d5922991d98683e1fb05c6"  # 0x9541ba003233f53afc11be1834f1fd26fb7c2060

Protocols = ["http", "rpc", "ipc", "ws"]
host = None


@command(aliases=["sethost"])
@argument("host", description="Address of the RPC Node", aliases=["u"])
def sethost(host: str):
    """