Skip to content
Snippets Groups Projects
Commit 25c7403c authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

soportar JSON que solamente tiene un ABI

parent bd7bc6e7
No related branches found
No related tags found
No related merge requests found
......@@ -286,7 +286,6 @@ class CompiledContract:
# Did read give us json, or should we compile it?
if self.json is None:
self.compile()
self.writetextfile()
def dockerargs(self):
return [
......@@ -313,7 +312,14 @@ class CompiledContract:
# Make a copy with a fixed name
# Mostly so people can use symlinks to the source files
# which won't work when we call docker.
with open('{}.sol'.format(self.name), 'r') as infile:
candidate_sol = '{}.sol'.format(self.name)
if os.path.exists(self.name):
filename = self.name
elif os.path.exists(candidate_sol):
filename = candidate_sol
else:
filename = self.name
with open(filename, 'r') as infile:
with open('contract.sol', 'w') as outfile:
outfile.write(infile.read())
try:
......@@ -324,14 +330,17 @@ class CompiledContract:
txt = solc.stdout
output = txt.decode('utf-8')
self.json = json.loads(output)
self.writetextfile()
def readtextfile(self):
filename = self.name + '.compiled.json'
try:
with open(filename, 'rt', encoding='utf-8') as infile:
output = infile.read()
except FileNotFoundError:
return
for filename in ( '{}.compiled.json'.format(self.name), self.name ):
if os.path.exists( filename ):
with open(filename, 'rt', encoding='utf-8') as infile:
output = infile.read()
break
if output is None:
print("File not found.", file=sys.stderr)
raise FileNotFound
if len(output) < 2:
print("The JSON file is too small ({} bytes read from {}).".format(len(output), filename), file=sys.stderr)
raise NameError
......@@ -372,7 +381,12 @@ class CompiledContract:
def abi(self):
# Old method which also works, but our own class has a nicer __str__:
# return json.loads(self.json['contracts'][where]['abi'])
return Abi(json.loads(self._where()['abi']))
where = self._where()
if type(where) is str:
where = json.loads(where)
if (type(where) is dict) and 'abi' in where:
where = where['abi']
return Abi(where)
def instance(self, *args, **kwargs):
addr = kwargs.get('address')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment