示例#1
0
class proxies():
    def __init__(self, key):
        self.key = key
        self.api = Proxies(api_key=key)

    '''
    def gas_price(self):
        return self.api.gas_price()
    '''

    def get_block(self, number):
        block_number = self.api.get_block_by_number(block_number=number)
        return pd.DataFrame.from_dict(block_number, orient='index')

    def tx_count(self, number):
        tx_count = self.api.get_block_transaction_count_by_number(
            block_number=number)
        tx_count = [int(tx_count, 16)]
        return pd.DataFrame(tx_count, ['block_transaction_count_by_number'])

    '''
    def get_code(self, address):
 Error: Exception has occurred: AttributeError. 'Proxies' object has no attribute 'get_code'
        return self.api.get_code(address = address)
    '''

    def get_recent_block(self):
        block = self.api.get_most_recent_block()
        block = [int(block, 16)]
        return pd.DataFrame(block, columns=['most recent block'])

    '''
    def value(self):
   Error: no attribute
        return self.api.get_storage_at('0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd', 0x0)
    '''

    def Transactions(self, number, index):
        return self.api.get_transaction_by_blocknumber_index(
            block_number=number, index=index)

    def transaction_hash(self, TX_HASH):
        transaction = self.api.get_transaction_by_hash(tx_hash=TX_HASH)
        return transaction

    def transaction_count(self, address):
        count = self.api.get_transaction_count(address=address)
        count = [int(count, 16)]
        return count

    def transaction_receipt(self, TX_HASH):
        receipt = self.api.get_transaction_receipt(tx_hash=TX_HASH)
        return receipt

    def uncle(self, number, index):
        uncel = self.api.get_uncle_by_blocknumber_index(block_number=number,
                                                        index=index)
        return uncel
class Proxies_usage:
    def __init__(self, key):
        self.api_key = key
        self.api = Proxies(api_key=key)

    #### get information about a block by block number (and save the result in a JSON file)
    def block_info_by_number(self, block_number):
        block = self.api.get_block_by_number(block_number)
        with open("./block_info_by_number.json", "w") as json_file:
            json.dump(block, json_file)

    #### get the number of transactions in a block matching the given block number
    def block_trans_count_by_number(self, block_number):
        tx_count = self.api.get_block_transaction_count_by_number(
            block_number=block_number)
        return int(tx_count, 16)

    #### get the number of most recent block
    def most_recent_block(self):
        block = self.api.get_most_recent_block()
        return int(block, 16)

    #### get information about a transaction by block number and transaction index position (and save to a csv file)
    def trans_info_by_number_index(self, block_number, index):
        transaction = self.api.get_transaction_by_blocknumber_index(
            block_number=block_number, index=index)
        transaction = pd.DataFrame(transaction, index=[0])
        transaction.to_csv("./transaction_info_by_number_index.csv",
                           index=False)

    #### get the informationa bout a transaction by transaction hash (and save to a csv file)
    def trans_info_by_hash(self, hash):
        transaction = self.api.get_transaction_by_hash(tx_hash=hash)
        transaction = pd.DataFrame(transaction, index=[0])
        transaction.to_csv("./transaction_info_by_hash.csv", index=False)

    #### get the number of transactions sent from an address
    def trans_count_from_addr(self, address):
        count = self.api.get_transaction_count(address)
        return int(count, 16)

    #### get (display) the receipt of a transaction by transaction hash
    def trans_receipt_by_hash(self, hash):
        receipt = self.api.get_transaction_receipt(hash)
        receipt = pd.DataFrame.from_dict(receipt, orient="index")
        display(receipt)

    #### get information about a uncle by block number
    def uncle_by_number_index(self, block_number, index="0x0"):
        uncles = self.api.get_uncle_by_blocknumber_index(
            block_number=block_number, index=index)
        return uncles["uncles"]
示例#3
0
from etherscan.proxies import Proxies
import json

with open('../../api_key.json', mode='r') as key_file:
    key = json.loads(key_file.read())['key']

api = Proxies(api_key=key)
count = api.get_transaction_count('0x6E2446aCfcec11CC4a60f36aFA061a9ba81aF7e0')
print(int(count, 16))
示例#4
0
 def test_get_transaction_count(self):
     api = Proxies(api_key=API_KEY)
     tx_count = int(api.get_transaction_count(TX_ADDRESS), 16)
     print(tx_count)
     p = re.compile('^[0-9]*$')
     self.assertTrue(p.match(str(tx_count)))
示例#5
0
class Proxy(EtherscanAPI):
    def __init__(self):
        super().__init__()
        self.api = Proxies(api_key=self.key)
        self._create_data_folder(DATA_DIR)

    # def gas_price(self):
    #     price = self.api.gas_price()
    #     return price

    def _save_json(self, data, filename, save):
        if save:
            filepath = os.path.join(DATA_DIR, filename)
            with open(filepath, 'w') as json_file:
                json.dump(data, json_file, indent=4)

    def get_most_recent_block(self, save=False):
        block = self.api.get_most_recent_block()
        filename = f'most-recent-block.json'
        self._save_json(block, filename, save)
        return block

    def get_block_by_number(self, block_num, save=False):
        block = self.api.get_block_by_number(block_num)
        filename = f'block-{block_num}-data.json'
        self._save_json(block, filename, save)
        return block

    def get_uncle_by_blocknumber_index(self, block_num, index, save=False):
        uncles = self.api.get_uncle_by_blocknumber_index(
            block_number=block_num, index=index)
        filename = f'block-{block_num}-{index}-uncles-data.json'
        self._save_json(uncles, filename, save)
        return uncles

    def get_block_transaction_count_by_number(self, block_num, save=False):
        tx_count = self.api.get_block_transaction_count_by_number(
            block_number=block_num)
        return int(tx_count, 16)

    def get_transaction_by_hash(self, tx_hash, save=False):
        transaction = self.api.get_transaction_by_hash(tx_hash=tx_hash)
        filename = f'transaction-data-of-hash-{tx_hash}.json'
        self._save_json(transaction, filename, save)
        return transaction

    def get_transaction_by_blocknumber_index(self,
                                             block_num,
                                             index,
                                             save=False):
        transaction = self.api.get_transaction_by_blocknumber_index(
            block_number=block_num, index=index)
        filename = f'transaction-data-of-block-{block_num}.json'
        self._save_json(transaction, filename, save)
        return transaction

    def get_transaction_count(self, address, save=False):
        count = self.api.get_transaction_count(address)
        return int(count, 16)

    def get_transaction_receipt(self, tx_hash, save=False):
        receipt = self.api.get_transaction_receipt(tx_hash)
        filename = f'transaction-recepit-of-hash-{tx_hash}.json'
        self._save_json(receipt, filename, save)
        return receipt