TestCommand.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Contract;
  4. use App\Models\MemberClan;
  5. use App\Servers\ContractServer;
  6. use BitWasp\Bitcoin\Bitcoin;
  7. use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
  8. use BitWasp\Bitcoin\Crypto\Random\Random;
  9. use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory;
  10. use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39Mnemonic;
  11. use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39SeedGenerator;
  12. use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;
  13. use Illuminate\Console\Command;
  14. use Web3p\EthereumUtil\Util;
  15. class TestCommand extends Command
  16. {
  17. /**
  18. * The name and signature of the console command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'test:a';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = 'Command description';
  29. /**
  30. * Create a new command instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct()
  35. {
  36. parent::__construct();
  37. }
  38. /**
  39. * Execute the console command.
  40. *
  41. * @return mixed
  42. */
  43. public function handle()
  44. {
  45. $random = new Random();
  46. // 生成随机数(initial entropy)
  47. $entropy = $random->bytes(Bip39Mnemonic::MIN_ENTROPY_BYTE_LEN);
  48. $bip39 = MnemonicFactory::bip39();
  49. // 通过随机数生成助记词
  50. $mnemonic = $bip39->entropyToMnemonic($entropy);
  51. echo "mnemonic: " . $mnemonic.PHP_EOL.PHP_EOL;// 助记词
  52. $seedGenerator = new Bip39SeedGenerator();
  53. // 通过助记词生成种子,传入可选加密串'hello'
  54. $seed = $seedGenerator->getSeed($mnemonic);
  55. echo "seed: " . $seed->getHex() . PHP_EOL;
  56. $hdFactory = new HierarchicalKeyFactory();
  57. $master = $hdFactory->fromEntropy($seed);
  58. $hardened = $master->derivePath("44'/60'/0'/0/0");
  59. echo 'WIF: ' . $hardened->getPrivateKey()->toWif();
  60. echo PHP_EOL;
  61. $address = new PayToPubKeyHashAddress($hardened->getPublicKey()->getPubKeyHash());
  62. echo 'address: ' . $address->getAddress();
  63. echo PHP_EOL;
  64. echo " - m/44'/60'/0'/0/0 " .PHP_EOL;
  65. echo " public key: " . $hardened->getPublicKey()->getHex().PHP_EOL;
  66. echo " private key: " . $hardened->getPrivateKey()->getHex().PHP_EOL;// 可以导入到imtoken使用的私钥
  67. $util = new Util();
  68. echo " address: " . $util->publicKeyToAddress($util->privateKeyToPublicKey($hardened->getPrivateKey()->getHex())) . PHP_EOL;// 私钥导入imtoken后一样的地址
  69. dd(1221);
  70. // ContractServer::creatServer()->verifyContractCommon();
  71. // dd(12);
  72. // $ids=Member::where('id','>',1)->pluck('id')->toArray();
  73. // MemberServer::creatServer()->verificationLevel($ids);
  74. $contract=Contract::where('id',33)->first();
  75. $memberTeam=MemberClan::where('m_id',$contract->{'m_id'})->select(['id','m_id','p_ids','one_m_id','two_m_id'])->first();
  76. $pIds=array_reverse(array_filter(explode(',',$memberTeam->{'p_ids'})));
  77. dd($contract,$pIds);
  78. ContractServer::creatServer()->teamProportion($contract,$pIds);
  79. dd(1221);
  80. // $data=Address::generate();
  81. // dd($data);
  82. // for ($i=0;$i<=23;++$i){
  83. // $address='0x848da9d7fcbfe80afc47b4383f178184589acfa9';
  84. // $p_member= Member::orderBy('id','desc')->select(['id', 'address'])->first();
  85. // $ret = MemberServer::creatServer()->register($i.$address, $p_member->{'id'}, '', '');
  86. // }
  87. // $ret=BanRPC::creatServer()->getTransactionReceipt('0xc47a91e730e44c1beb80182f69c117b74dfdf9e6b2fdbb81def8bc704cd0cb5b');
  88. // dd($ret);
  89. }
  90. }