// +---------------------------------------------------------------------- namespace App\Services; use App\Models\MemberModel; use BitWasp\Bitcoin\Address\AddressCreator; use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress; use BitWasp\Bitcoin\Crypto\Random\Random; use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory; use BitWasp\Bitcoin\Network\NetworkInterface; /** * USDT链管理-服务类 * Class UsdtWalletService * @package App\Services */ class UsdtWalletService extends BaseService { protected $config = []; /** * 构造函数 * UsdtWalletService constructor. */ public function __construct() { $this->config = ConfigService::make()->getConfigByGroup(2); if (empty($this->config)) { return false; } } /** * 静态入口 * @return UsdtWalletService|null */ public static function make() { return parent::make(); // TODO: Change the autogenerated stub } /** * 获取 */ public function getLink() { } /** * 创建转入TRC2.0转账交易 * api: https://services.tokenview.com/vipapi/onchainwallet/{币种简称小写}?apikey={apikey} */ public function transferTrc20() { // } /** * 获取钱包地址 * @param string $type * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure */ public function getWalletAddress() { $random = new Random(); $privateKeyFactory = new PrivateKeyFactory(); $privateKey = $privateKeyFactory->generateCompressed($random); $publicKey = $privateKey->getPublicKey(); // p2pkh 格式的地址 $addressService = new PayToPubKeyHashAddress($publicKey->getPubKeyHash()); // 将生成的钱包保存到数据库中 $network = null; $wif = $privateKey->toWif($network); $address = $addressService->getAddress(); return ['wif'=> $wif, 'address'=> $address]; } /** * 获取HASH钱包地址 * @param $address 钱包地址 * @return \BitWasp\Buffertools\BufferInterface * @throws \BitWasp\Bitcoin\Exceptions\UnrecognizedAddressException */ public function getHashAddress($address) { $data = (new AddressCreator())->fromString($address)->getHash(); return isset($data['buffer'])? $data['buffer'] : ''; } }