func (h *Handler) TransferTokens(
	tkn, account, destination string, amount, gasPrice uint64) error {
	logger := h.logger.Add("method", "TransferTokens", "destination",
		destination, "amount", amount, "gasPrice", gasPrice)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	if amount == 0 {
		logger.Error(ErrTokenAmountTooSmall.Error())
		return ErrTokenAmountTooSmall
	}

	if destination != data.ContractPSC && destination != data.ContractPTC {
		logger.Error(ErrBadDestination.Error())
		return ErrBadDestination
	}

	err := h.findByPrimaryKey(
		logger, ErrAccountNotFound, &data.Account{}, account)
	if err != nil {
		return err
	}

	jobType := data.JobPreAccountAddBalanceApprove
	if destination == data.ContractPTC {
		jobType = data.JobPreAccountReturnBalance
	}

	jobData := &data.JobBalanceData{
		Amount:   amount,
		GasPrice: gasPrice,
	}

	err = job.AddWithData(h.queue, nil, jobType,
		data.JobAccount, account, data.JobUser, jobData)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	return nil
}
func (h *Handler) TransferTokens(
	tkn, account, destination string, amount, gasPrice uint64) error {
	logger := h.logger.Add("method", "TransferTokens", "destination",
		destination, "amount", amount, "gasPrice", gasPrice)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	if amount == 0 {
		logger.Error(ErrTokenAmountTooSmall.Error())
		return ErrTokenAmountTooSmall
	}

	if destination != data.ContractPSC && destination != data.ContractPTC {
		logger.Error(ErrBadDestination.Error())
		return ErrBadDestination
	}

	err := h.findByPrimaryKey(
		logger, ErrAccountNotFound, &data.Account{}, account)
	if err != nil {
		return err
	}

	jobType := data.JobPreAccountAddBalanceApprove
	if destination == data.ContractPTC {
		jobType = data.JobPreAccountReturnBalance
	}

	jobData := &data.JobBalanceData{
		Amount:   amount,
		GasPrice: gasPrice,
	}

	err = job.AddWithData(h.queue, nil, jobType,
		data.JobAccount, account, data.JobUser, jobData)
	if err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	return nil
}
func ( h * Handler ) TransferTokens ( tkn , account , destination string , amount , gasPrice uint64 ) error { logger := h . logger . Add ( " " , " " , " " , destination , " " , amount , " " , gasPrice ) if ! h . token . Check ( tkn ) { logger . Warn ( " " ) return ErrAccessDenied } if amount == 0 { logger . Error ( ErrTokenAmountTooSmall . Error ( ) ) return ErrTokenAmountTooSmall } if destination != data . ContractPSC && destination != data . ContractPTC { logger . Error ( ErrBadDestination . Error ( ) ) return ErrBadDestination } err := h . findByPrimaryKey ( logger , ErrAccountNotFound , & data . Account { } , account ) if err != nil { return err } jobType := data . JobPreAccountAddBalanceApprove if destination == data . ContractPTC { jobType = data . JobPreAccountReturnBalance } jobData := & data . JobBalanceData { Amount : amount , GasPrice : gasPrice , } err = job . AddWithData ( h . queue , nil , jobType , data . JobAccount , account , data . JobUser , jobData ) if err != nil { logger . Error ( err . Error ( ) ) return ErrInternal } return nil }
// TransferTokens initiates JobPreAccountAddBalanceApprove
// or JobPreAccountReturnBalance job depending on the direction of the transfer.
TransferTokens initiates JobPreAccountAddBalanceApprove or JobPreAccountReturnBalance job depending on the direction of the transfer .