refactor getter
@@ -37,17 +37,14 @@ func (c *Contract) IsAlias() bool {
// GetByNameAndNetwork get contract array for account and network
func (c *Contracts) GetByNameAndNetwork(name string, network string) *Contract {
- contracts := make(Contracts, 0)
-
for _, contract := range *c {
if contract.Network == network && contract.Name == name {
- contracts = append(contracts, contract)
+ return &contract
}
}
// if we don't find contract by name and network create a new contract
// and replace only name and source with existing
- if len(contracts) == 0 {
cName := c.GetByName(name)
if cName == nil {
return nil
@@ -60,9 +57,6 @@ func (c *Contracts) GetByNameAndNetwork(name string, network string) *Contract {
}
}
- return &contracts[0]
-}
-
// GetByName get contract by name
func (c *Contracts) GetByName(name string) *Contract {
for _, contract := range *c {
