123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Contract;
- use App\Models\MemberClan;
- use App\Servers\ContractServer;
- use BitWasp\Bitcoin\Bitcoin;
- use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
- use BitWasp\Bitcoin\Crypto\Random\Random;
- use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory;
- use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39Mnemonic;
- use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39SeedGenerator;
- use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;
- use Illuminate\Console\Command;
- use Web3p\EthereumUtil\Util;
- class TestCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'test:a';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $random = new Random();
- // 生成随机数(initial entropy)
- $entropy = $random->bytes(Bip39Mnemonic::MIN_ENTROPY_BYTE_LEN);
- $bip39 = MnemonicFactory::bip39();
- // 通过随机数生成助记词
- $mnemonic = $bip39->entropyToMnemonic($entropy);
- echo "mnemonic: " . $mnemonic.PHP_EOL.PHP_EOL;// 助记词
- $seedGenerator = new Bip39SeedGenerator();
- // 通过助记词生成种子,传入可选加密串'hello'
- $seed = $seedGenerator->getSeed($mnemonic);
- echo "seed: " . $seed->getHex() . PHP_EOL;
- $hdFactory = new HierarchicalKeyFactory();
- $master = $hdFactory->fromEntropy($seed);
- $hardened = $master->derivePath("44'/60'/0'/0/0");
- echo 'WIF: ' . $hardened->getPrivateKey()->toWif();
- echo PHP_EOL;
- $address = new PayToPubKeyHashAddress($hardened->getPublicKey()->getPubKeyHash());
- echo 'address: ' . $address->getAddress();
- echo PHP_EOL;
- echo " - m/44'/60'/0'/0/0 " .PHP_EOL;
- echo " public key: " . $hardened->getPublicKey()->getHex().PHP_EOL;
- echo " private key: " . $hardened->getPrivateKey()->getHex().PHP_EOL;// 可以导入到imtoken使用的私钥
- $util = new Util();
- echo " address: " . $util->publicKeyToAddress($util->privateKeyToPublicKey($hardened->getPrivateKey()->getHex())) . PHP_EOL;// 私钥导入imtoken后一样的地址
- dd(1221);
- // ContractServer::creatServer()->verifyContractCommon();
- // dd(12);
- // $ids=Member::where('id','>',1)->pluck('id')->toArray();
- // MemberServer::creatServer()->verificationLevel($ids);
- $contract=Contract::where('id',33)->first();
- $memberTeam=MemberClan::where('m_id',$contract->{'m_id'})->select(['id','m_id','p_ids','one_m_id','two_m_id'])->first();
- $pIds=array_reverse(array_filter(explode(',',$memberTeam->{'p_ids'})));
- dd($contract,$pIds);
- ContractServer::creatServer()->teamProportion($contract,$pIds);
- dd(1221);
- // $data=Address::generate();
- // dd($data);
- // for ($i=0;$i<=23;++$i){
- // $address='0x848da9d7fcbfe80afc47b4383f178184589acfa9';
- // $p_member= Member::orderBy('id','desc')->select(['id', 'address'])->first();
- // $ret = MemberServer::creatServer()->register($i.$address, $p_member->{'id'}, '', '');
- // }
- // $ret=BanRPC::creatServer()->getTransactionReceipt('0xc47a91e730e44c1beb80182f69c117b74dfdf9e6b2fdbb81def8bc704cd0cb5b');
- // dd($ret);
- }
- }
|