Skip to content

Commit

Permalink
Improve comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Silas Davis committed Feb 23, 2017
1 parent 1dbb906 commit 87baace
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
6 changes: 6 additions & 0 deletions manager/eris-mint/evm/snative.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ func SNativeContracts() map[string]*SNativeContractDescription {

contractMap := make(map[string]*SNativeContractDescription, len(contracts))
for _, contract := range contracts {
if _, ok := contractMap[contract.Name]; ok {
// If this happens we have a pseudo compile time error that will be caught
// on native.go init()
panic(fmt.Errorf("Duplicate contract with name %s defined. " +
"Contract names must be unique.", contract.Name))
}
contractMap[contract.Name] = contract
}
return contractMap
Expand Down
38 changes: 32 additions & 6 deletions util/snatives/templates/solidity_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (

const contractTemplateText = `/**
[[.Comment]]
* @dev These functions can be accessed as if this contract were deployed at the address [[.Address]].
* @dev For readability you may wish to define the following constant to refer to the SNative contract:
* @dev address constant [[.Name]]ContractAddress = [[.Address]]
* @dev These functions can be accessed as if this contract were deployed at a special address ([[.Address]]).
* @dev This special address is defined as the last 20 bytes of the sha3 hash of the the contract name.
* @dev To instantiate the contract use:
* @dev [[.Name]] [[.InstanceName]] = [[.Name]](address(sha3("[[.Name]]")));
*/
contract [[.Name]] {[[range .Functions]]
[[.SolidityIndent 1]]
Expand Down Expand Up @@ -69,11 +70,30 @@ type solidityFunction struct {
*vm.SNativeFunctionDescription
}

//
// Contract
//

// Create a templated solidityContract from an SNative contract description
func NewSolidityContract(contract *vm.SNativeContractDescription) *solidityContract {
return &solidityContract{contract}
}

func (contract *solidityContract) Comment() string {
return comment(contract.SNativeContractDescription.Comment)
}

// Get a version of the contract name to be used for an instance of the contract
func (contract *solidityContract) InstanceName() string {
// Hopefully the contract name is UpperCamelCase. If it's not, oh well, this
// is meant to be illustrative rather than cast iron compilable
instanceName := strings.ToLower(contract.Name[:1]) + contract.Name[1:]
if instanceName == contract.Name {
return "contractInstance"
}
return instanceName
}

func (contract *solidityContract) Address() string {
return fmt.Sprintf("0x%x",
contract.SNativeContractDescription.Address())
Expand All @@ -98,6 +118,10 @@ func (contract *solidityContract) Functions() []*solidityFunction {
return solidityFunctions
}

//
// Function
//

// Create a templated solidityFunction from an SNative function description
func NewSolidityFunction(function *vm.SNativeFunctionDescription) *solidityFunction {
return &solidityFunction{function}
Expand Down Expand Up @@ -133,9 +157,11 @@ func (function *solidityFunction) solidity(indentLevel uint) (string, error) {
return buf.String(), nil
}

func (contract *solidityContract) Comment() string {
return comment(contract.SNativeContractDescription.Comment)
}

//
// Contract
//


func comment(comment string) string {
commentLines := make([]string, 0, 5)
Expand Down

0 comments on commit 87baace

Please sign in to comment.