github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/contracts/ethclient.go (about)

     1  package contracts
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/SmartMeshFoundation/Spectrum/ethclient"
     7  	"github.com/SmartMeshFoundation/Spectrum/log"
     8  	"github.com/SmartMeshFoundation/Spectrum/params"
     9  )
    10  
    11  var client *ethclient.Client
    12  
    13  func GetEthclientInstance() (*ethclient.Client, error) {
    14  	if client == nil {
    15  		var ec *ethclient.Client
    16  		var err error
    17  		for {
    18  			ec, err = ethclient.Dial(params.GetIPCPath())
    19  			if err != nil {
    20  				log.Warn("GetEthclientInstance_fail", "err", err)
    21  				time.Sleep(time.Millisecond * 100)
    22  			} else {
    23  				break
    24  			}
    25  		}
    26  
    27  		client = ec
    28  	}
    29  	return client, nil
    30  }