Open MAHMOUDJOR opened 1 year ago
class WalletClient { public function __construct( protected TRC20Contract $contract ) { }
/**
* @param string $toAddress
* @param string $amount
* @return void
* @throws TRC20Exception
* @throws TronException
*/
public function sendMoney(string $toAddress, string $amount): array
{
return $this->contract->transfer($toAddress, $amount);
}
}
are u able to share ur full class?
are u able to share ur full class?
`<?php
namespace App\Tron\Wallet;
use App\Tron\Wallet\Response\TransferResponse; use IEXBase\TronAPI\Exception\TRC20Exception; use IEXBase\TronAPI\Exception\TronException; use IEXBase\TronAPI\TRC20Contract; use IEXBase\TronAPI\Tron;
/**
Класс который работает с кошельком BtCourse */ class WalletClient { public function __construct( public TRC20Contract $contract, public Tron $tron ) { }
/**
@throws TronException */ public function sendUSDT(string $toAddress, string $amount): array { $response = $this->contract->transfer($toAddress, $amount);
TransferResponse::check($response);
return $response; }
/**
/**
/**
`<?php
namespace App\Tron\Wallet\Response;
use Arr; use IEXBase\TronAPI\Exception\TronException;
class TransferResponse {
public const SIGERROR = 'SIGERROR';
public const BANDWITH_ERROR = 'BANDWITH_ERROR';
public const DUP_TRANSACTION_ERROR = 'DUP_TRANSACTION_ERROR';
public const TAPOS_ERROR = 'TAPOS_ERROR';
public const TOO_BIG_TRANSACTION_ERROR = 'TOO_BIG_TRANSACTION_ERROR';
public const TRANSACTION_EXPIRATION_ERROR = 'TRANSACTION_EXPIRATION_ERROR';
public const SERVER_BUSY = 'SERVER_BUSY';
public const NOT_ENOUGH_EFFECTIVE_CONNECTION = 'NOT_ENOUGH_EFFECTIVE_CONNECTION';
public const OTHER_ERROR = 'OTHER_ERROR';
public const CONTRACT_VALIDATE_ERROR = 'CONTRACT_VALIDATE_ERROR';
public const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
private static array $errorCodes = [
self::CONTRACT_VALIDATE_ERROR,
self::BANDWITH_ERROR,
self::OTHER_ERROR,
self::DUP_TRANSACTION_ERROR,
self::TOO_BIG_TRANSACTION_ERROR,
self::NOT_ENOUGH_EFFECTIVE_CONNECTION,
self::SERVER_BUSY,
self::SIGERROR,
self::TRANSACTION_EXPIRATION_ERROR,
self::TAPOS_ERROR
];
/**
* @param array $response
* @return void
* @throws TronException
*/
public static function check(array $response): void
{
if ((Arr::exists($response, 'code') && !in_array($response['code'], self::$errorCodes, true))) {
throw new TronException(self::UNKNOWN_ERROR);
}
if ((Arr::exists($response, 'code') && in_array($response['code'], self::$errorCodes, true))) {
throw new TronException($response['code']);
}
}
}`