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: ...@@ -286,7 +286,6 @@ class CompiledContract:
# Did read give us json, or should we compile it? # Did read give us json, or should we compile it?
if self.json is None: if self.json is None:
self.compile() self.compile()
self.writetextfile()
def dockerargs(self): def dockerargs(self):
return [ return [
...@@ -313,7 +312,14 @@ class CompiledContract: ...@@ -313,7 +312,14 @@ class CompiledContract:
# Make a copy with a fixed name # Make a copy with a fixed name
# Mostly so people can use symlinks to the source files # Mostly so people can use symlinks to the source files
# which won't work when we call docker. # 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: with open('contract.sol', 'w') as outfile:
outfile.write(infile.read()) outfile.write(infile.read())
try: try:
...@@ -324,14 +330,17 @@ class CompiledContract: ...@@ -324,14 +330,17 @@ class CompiledContract:
txt = solc.stdout txt = solc.stdout
output = txt.decode('utf-8') output = txt.decode('utf-8')
self.json = json.loads(output) self.json = json.loads(output)
self.writetextfile()
def readtextfile(self): def readtextfile(self):
filename = self.name + '.compiled.json' for filename in ( '{}.compiled.json'.format(self.name), self.name ):
try: if os.path.exists( filename ):
with open(filename, 'rt', encoding='utf-8') as infile: with open(filename, 'rt', encoding='utf-8') as infile:
output = infile.read() output = infile.read()
except FileNotFoundError: break
return if output is None:
print("File not found.", file=sys.stderr)
raise FileNotFound
if len(output) < 2: if len(output) < 2:
print("The JSON file is too small ({} bytes read from {}).".format(len(output), filename), file=sys.stderr) print("The JSON file is too small ({} bytes read from {}).".format(len(output), filename), file=sys.stderr)
raise NameError raise NameError
...@@ -372,7 +381,12 @@ class CompiledContract: ...@@ -372,7 +381,12 @@ class CompiledContract:
def abi(self): def abi(self):
# Old method which also works, but our own class has a nicer __str__: # Old method which also works, but our own class has a nicer __str__:
# return json.loads(self.json['contracts'][where]['abi']) # 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): def instance(self, *args, **kwargs):
addr = kwargs.get('address') 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