Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
sort contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
heikoheiko committed Apr 26, 2015
1 parent 54554a5 commit 7519e7c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ethereum/_solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,36 @@ def contract_names(cls, code):
@classmethod
def compile(cls, code):
"returns binary of last contract in code"
contracts = cls.combined(code)
return contracts[cls.contract_names(code)[-1]]['binary'].decode('hex')
sorted_contracts = cls.combined(code)
return sorted_contracts[-1][1]['binary'].decode('hex')

@classmethod
def mk_full_signature(cls, code):
"returns signature of last contract in code"
contracts = cls.combined(code)
return contracts[cls.contract_names(code)[-1]]['json-abi']
sorted_contracts = cls.combined(code)
return sorted_contracts[-1][1]['json-abi']

@classmethod
def combined(cls, code):
p = subprocess.Popen(['solc', '--combined-json', 'json-abi,binary'],
p = subprocess.Popen(['solc', '--combined-json', 'json-abi,binary,sol-abi'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdoutdata, stderrdata = p.communicate(input=code)
if p.returncode:
raise CompileError('compilation failed')
# contracts = json.loads(stdoutdata)['contracts']
contracts = yaml.safe_load(stdoutdata)['contracts']

for contract_name, data in contracts.items():
data['json-abi'] = yaml.safe_load(data['json-abi'])
return contracts
data['sol-abi'] = yaml.safe_load(data['sol-abi'])

names = cls.contract_names(code)
assert len(names) == len(contracts)
sorted_contracts = []
for name in names:
sorted_contracts.append((name, contracts[name]))

return sorted_contracts


def get_solidity():
Expand Down

0 comments on commit 7519e7c

Please sign in to comment.