func (w *Worker) PreAccountReturnBalance(job *data.Job) error {
	logger := w.logger.Add("method", "PreAccountReturnBalance", "job", job)
	acc, err := w.relatedAccount(logger, job, data.JobPreAccountReturnBalance)
	if err != nil {
		return err
	}

	key, err := w.key(logger, acc.PrivateKey)
	if err != nil {
		return err
	}

	jobData, err := w.balanceData(logger, job)
	if err != nil {
		return err
	}

	auth := bind.NewKeyedTransactor(key)

	amount, err := w.ethBack.PSCBalanceOf(&bind.CallOpts{}, auth.From)
	if err != nil {
		logger.Error(err.Error())
		return ErrPSCReturnBalance
	}

	if amount < uint64(jobData.Amount) {
		return ErrInsufficientPSCBalance
	}

	ethAmount, err := w.ethBalance(logger, auth.From)
	if err != nil {
		return err
	}

	wantedEthBalance := w.gasConf.PSC.ReturnBalanceERC20 * jobData.GasPrice

	if wantedEthBalance > ethAmount.Uint64() {
		return ErrInsufficientEthBalance
	}

	auth.GasLimit = w.gasConf.PSC.ReturnBalanceERC20
	auth.GasPrice = new(big.Int).SetUint64(jobData.GasPrice)

	tx, err := w.ethBack.PSCReturnBalanceERC20(auth, uint64(jobData.Amount))
	if err != nil {
		logger.Add("GasLimit", auth.GasLimit,
			"GasPrice", auth.GasPrice).Error(err.Error())
		return ErrPSCRetrieveBalance
	}

	return w.saveEthTX(logger, job, tx, "PSCReturnBalanceERC20", job.RelatedType,
		job.RelatedID, data.HexFromBytes(w.pscAddr.Bytes()), acc.EthAddr)
}
func (w *Worker) PreAccountReturnBalance(job *data.Job) error {
	logger := w.logger.Add("method", "PreAccountReturnBalance", "job", job)
	acc, err := w.relatedAccount(logger, job, data.JobPreAccountReturnBalance)
	if err != nil {
		return err
	}

	key, err := w.key(logger, acc.PrivateKey)
	if err != nil {
		return err
	}

	jobData, err := w.balanceData(logger, job)
	if err != nil {
		return err
	}

	auth := bind.NewKeyedTransactor(key)

	amount, err := w.ethBack.PSCBalanceOf(&bind.CallOpts{}, auth.From)
	if err != nil {
		logger.Error(err.Error())
		return ErrPSCReturnBalance
	}

	if amount < uint64(jobData.Amount) {
		return ErrInsufficientPSCBalance
	}

	ethAmount, err := w.ethBalance(logger, auth.From)
	if err != nil {
		return err
	}

	wantedEthBalance := w.gasConf.PSC.ReturnBalanceERC20 * jobData.GasPrice

	if wantedEthBalance > ethAmount.Uint64() {
		return ErrInsufficientEthBalance
	}

	auth.GasLimit = w.gasConf.PSC.ReturnBalanceERC20
	auth.GasPrice = new(big.Int).SetUint64(jobData.GasPrice)

	tx, err := w.ethBack.PSCReturnBalanceERC20(auth, uint64(jobData.Amount))
	if err != nil {
		logger.Add("GasLimit", auth.GasLimit,
			"GasPrice", auth.GasPrice).Error(err.Error())
		return ErrPSCRetrieveBalance
	}

	return w.saveEthTX(logger, job, tx, "PSCReturnBalanceERC20", job.RelatedType,
		job.RelatedID, data.HexFromBytes(w.pscAddr.Bytes()), acc.EthAddr)
}
func ( w * Worker ) PreAccountReturnBalance ( job * data . Job ) error { logger := w . logger . Add ( " " , " " , " " , job ) acc , err := w . relatedAccount ( logger , job , data . JobPreAccountReturnBalance ) if err != nil { return err } key , err := w . key ( logger , acc . PrivateKey ) if err != nil { return err } jobData , err := w . balanceData ( logger , job ) if err != nil { return err } auth := bind . NewKeyedTransactor ( key ) amount , err := w . ethBack . PSCBalanceOf ( & bind . CallOpts { } , auth . From ) if err != nil { logger . Error ( err . Error ( ) ) return ErrPSCReturnBalance } if amount < uint64 ( jobData . Amount ) { return ErrInsufficientPSCBalance } ethAmount , err := w . ethBalance ( logger , auth . From ) if err != nil { return err } wantedEthBalance := w . gasConf . PSC . ReturnBalanceERC20 * jobData . GasPrice if wantedEthBalance > ethAmount . Uint64 ( ) { return ErrInsufficientEthBalance } auth . GasLimit = w . gasConf . PSC . ReturnBalanceERC20 auth . GasPrice = new ( big . Int ) . SetUint64 ( jobData . GasPrice ) tx , err := w . ethBack . PSCReturnBalanceERC20 ( auth , uint64 ( jobData . Amount ) ) if err != nil { logger . Add ( " " , auth . GasLimit , " " , auth . GasPrice ) . Error ( err . Error ( ) ) return ErrPSCRetrieveBalance } return w . saveEthTX ( logger , job , tx , " " , job . RelatedType , job . RelatedID , data . HexFromBytes ( w . pscAddr . Bytes ( ) ) , acc . EthAddr ) }
// PreAccountReturnBalance returns from psc to ptc.
PreAccountReturnBalance returns from psc to ptc .