Change database structure

pull/2/head
Bernhard Mueller 7 years ago
parent 2ce3dc050c
commit 4919d1211b
  1. 20
      contractstorage.py
  2. 8
      ethcontract.py
  3. 4
      mythril

@ -1,5 +1,5 @@
from rpc.client import EthJsonRpc
from ethcontract import ETHCode, AddressesByCodeHash, CodeHashByAddress
from ethcontract import ETHCode, InstanceList
from ethereum import utils
import hashlib
import re
@ -13,8 +13,7 @@ class ContractStorage(persistent.Persistent):
def __init__(self):
self.contracts = BTree()
self.address_to_hash_map = BTree()
self.hash_to_addresses_map = BTree()
self.instance_lists= BTree()
self.last_block = 0
def initialize(self, rpchost, rpcport):
@ -57,17 +56,10 @@ class ContractStorage(persistent.Persistent):
self.contracts[contract_hash]
except KeyError:
self.contracts[contract_hash] = code
m = InstanceList()
self.instance_lists[contract_hash] = m
m = CodeHashByAddress(contract_hash, contract_balance)
self.address_to_hash_map[contract_address] = m
try:
self.hash_to_addresses_map[contract_hash]
except KeyError:
m = AddressesByCodeHash()
self.hash_to_addresses_map[contract_hash] = m
self.hash_to_addresses_map[contract_hash].add(contract_address, contract_balance)
self.instance_lists[contract_hash].add(contract_address, contract_balance)
transaction.commit()
@ -103,6 +95,6 @@ class ContractStorage(persistent.Persistent):
m.update(self.contracts[k].code.encode('UTF-8'))
contract_hash = m.digest()
m = self.hash_to_addresses_map[contract_hash]
m = self.instance_lists[contract_hash]
callback_func(m.addresses)

@ -43,13 +43,7 @@ class ETHCode(persistent.Persistent):
return eval(str_eval)
class CodeHashByAddress(persistent.Persistent):
def __init__(self, code_hash, balance = 0):
self.code_hash = code_hash
self.balance = balance
class AddressesByCodeHash(persistent.Persistent):
class InstanceList(persistent.Persistent):
def __init__(self):
self.addresses = []

@ -16,8 +16,8 @@ import os
def searchCallback(addresses):
print("Match found in contract deployed at: ")
print(addresses.join("\n"))
print("MATCHED CONTRACT DEPLOYED AT: ")
print("\n".join(addresses))
def exitWithError(message):
print(message)

Loading…
Cancel
Save