|
|
@ -92,7 +92,7 @@ func (sol *Solidity) Version() string { |
|
|
|
return sol.version |
|
|
|
return sol.version |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (sol *Solidity) Compile(source string) (contract *Contract, err error) { |
|
|
|
func (sol *Solidity) Compile(source string) (contracts map[string]*Contract, err error) { |
|
|
|
|
|
|
|
|
|
|
|
if len(source) == 0 { |
|
|
|
if len(source) == 0 { |
|
|
|
err = fmt.Errorf("empty source") |
|
|
|
err = fmt.Errorf("empty source") |
|
|
@ -123,11 +123,10 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) { |
|
|
|
err = fmt.Errorf("solc error: missing code output") |
|
|
|
err = fmt.Errorf("solc error: missing code output") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if len(matches) > 1 { |
|
|
|
|
|
|
|
err = fmt.Errorf("multi-contract sources are not supported") |
|
|
|
contracts = make(map[string]*Contract) |
|
|
|
return |
|
|
|
for _, path := range matches { |
|
|
|
} |
|
|
|
_, file := filepath.Split(path) |
|
|
|
_, file := filepath.Split(matches[0]) |
|
|
|
|
|
|
|
base := strings.Split(file, ".")[0] |
|
|
|
base := strings.Split(file, ".")[0] |
|
|
|
|
|
|
|
|
|
|
|
codeFile := filepath.Join(wd, base+".binary") |
|
|
|
codeFile := filepath.Join(wd, base+".binary") |
|
|
@ -135,12 +134,13 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) { |
|
|
|
userDocFile := filepath.Join(wd, base+".docuser") |
|
|
|
userDocFile := filepath.Join(wd, base+".docuser") |
|
|
|
developerDocFile := filepath.Join(wd, base+".docdev") |
|
|
|
developerDocFile := filepath.Join(wd, base+".docdev") |
|
|
|
|
|
|
|
|
|
|
|
code, err := ioutil.ReadFile(codeFile) |
|
|
|
var code, abiDefinitionJson, userDocJson, developerDocJson []byte |
|
|
|
|
|
|
|
code, err = ioutil.ReadFile(codeFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("error reading compiler output for code: %v", err) |
|
|
|
err = fmt.Errorf("error reading compiler output for code: %v", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
abiDefinitionJson, err := ioutil.ReadFile(abiDefinitionFile) |
|
|
|
abiDefinitionJson, err = ioutil.ReadFile(abiDefinitionFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("error reading compiler output for abiDefinition: %v", err) |
|
|
|
err = fmt.Errorf("error reading compiler output for abiDefinition: %v", err) |
|
|
|
return |
|
|
|
return |
|
|
@ -148,7 +148,7 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) { |
|
|
|
var abiDefinition interface{} |
|
|
|
var abiDefinition interface{} |
|
|
|
err = json.Unmarshal(abiDefinitionJson, &abiDefinition) |
|
|
|
err = json.Unmarshal(abiDefinitionJson, &abiDefinition) |
|
|
|
|
|
|
|
|
|
|
|
userDocJson, err := ioutil.ReadFile(userDocFile) |
|
|
|
userDocJson, err = ioutil.ReadFile(userDocFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("error reading compiler output for userDoc: %v", err) |
|
|
|
err = fmt.Errorf("error reading compiler output for userDoc: %v", err) |
|
|
|
return |
|
|
|
return |
|
|
@ -156,7 +156,7 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) { |
|
|
|
var userDoc interface{} |
|
|
|
var userDoc interface{} |
|
|
|
err = json.Unmarshal(userDocJson, &userDoc) |
|
|
|
err = json.Unmarshal(userDocJson, &userDoc) |
|
|
|
|
|
|
|
|
|
|
|
developerDocJson, err := ioutil.ReadFile(developerDocFile) |
|
|
|
developerDocJson, err = ioutil.ReadFile(developerDocFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("error reading compiler output for developerDoc: %v", err) |
|
|
|
err = fmt.Errorf("error reading compiler output for developerDoc: %v", err) |
|
|
|
return |
|
|
|
return |
|
|
@ -164,7 +164,7 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) { |
|
|
|
var developerDoc interface{} |
|
|
|
var developerDoc interface{} |
|
|
|
err = json.Unmarshal(developerDocJson, &developerDoc) |
|
|
|
err = json.Unmarshal(developerDocJson, &developerDoc) |
|
|
|
|
|
|
|
|
|
|
|
contract = &Contract{ |
|
|
|
contract := &Contract{ |
|
|
|
Code: "0x" + string(code), |
|
|
|
Code: "0x" + string(code), |
|
|
|
Info: ContractInfo{ |
|
|
|
Info: ContractInfo{ |
|
|
|
Source: source, |
|
|
|
Source: source, |
|
|
@ -177,6 +177,9 @@ func (sol *Solidity) Compile(source string) (contract *Contract, err error) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contracts[base] = contract |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|