Skip to content
Snippets Groups Projects
Unverified Commit 1f421ff8 authored by Silas Davis's avatar Silas Davis
Browse files

Include magic SNative contract address in generated solidity code

parent af51be5a
No related branches found
No related tags found
No related merge requests found
......@@ -9,12 +9,21 @@ import (
// Dump SNative contracts
func main() {
for _, contract := range vm.SNativeContracts() {
contracts := vm.SNativeContracts()
// Index of next contract
i := 1
for _, contract := range contracts {
solidity, err := templates.NewSolidityContract(contract).Solidity()
if err != nil {
fmt.Printf("Error generating solidity for contract %s: %s\n",
contract.Name, err)
}
fmt.Println(solidity)
if i < len(contracts) {
// Two new lines between contracts as per Solidity style guide
// (the template gives us 1 trailing new line)
fmt.Println()
}
i++
}
}
......@@ -11,6 +11,7 @@ import (
const contractTemplateText = `/**
[[.Comment]]
* @dev These functions can be accessed as if this contract were deployed at the address [[.Address]]
*/
contract [[.Name]] {[[range .Functions]]
[[.SolidityIndent 1]]
......@@ -31,13 +32,13 @@ var functionTemplate *template.Template
func init() {
var err error
functionTemplate, err = template.New("SolidityFunctionTemplate").
Delims("[[", "]]").
Delims("[[", "]]").
Parse(functionTemplateText)
if err != nil {
panic(fmt.Errorf("Couldn't parse SNative function template: %s", err))
}
contractTemplate, err = template.New("SolidityContractTemplate").
Delims("[[", "]]").
Delims("[[", "]]").
Parse(contractTemplateText)
if err != nil {
panic(fmt.Errorf("Couldn't parse SNative contract template: %s", err))
......@@ -57,6 +58,11 @@ func NewSolidityContract(contract *vm.SNativeContractDescription) *solidityContr
return &solidityContract{contract}
}
func (contract *solidityContract) Address() string {
return fmt.Sprintf("0x%x",
contract.SNativeContractDescription.Address().Postfix(20))
}
// Generate Solidity code for this SNative contract
func (contract *solidityContract) Solidity() (string, error) {
buf := new(bytes.Buffer)
......
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