You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
183
hyhproject/home2/controller/Tmp.php
Executable file
183
hyhproject/home2/controller/Tmp.php
Executable file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
namespace wstmart\home\controller;
|
||||
Vendor('web3.vendor.autoload');
|
||||
use \PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
use Web3\Web3;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 默认控制器
|
||||
*/
|
||||
class Tmp extends Base{
|
||||
/**
|
||||
* web3
|
||||
*
|
||||
* @var \Web3\Web3
|
||||
*/
|
||||
protected $web3;
|
||||
|
||||
/**
|
||||
* testRinkebyHost
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testRinkebyHost = 'http://localhost';
|
||||
|
||||
/**
|
||||
* testHost
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testHost = 'http://localhost:8545';
|
||||
|
||||
/**
|
||||
* coinbase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $coinbase;
|
||||
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(){
|
||||
//Loader::import('web3.src.Web3');
|
||||
|
||||
$web3 = new Web3($this->testHost);
|
||||
$this->web3 = $web3;
|
||||
$personal = $web3->personal;
|
||||
// $personal->batch(true);
|
||||
// $personal->listAccounts();
|
||||
// $personal->newAccount('123456');
|
||||
|
||||
// $personal->provider->execute(function ($err, $data) {
|
||||
// if ($err !== null) {
|
||||
// // do something
|
||||
// return;
|
||||
// }
|
||||
// // do something
|
||||
// });
|
||||
//dump($personal);
|
||||
$web3->eth->coinbase(function ($err, $coinbase) {
|
||||
if ($err !== null) {
|
||||
dump($this->fail($err->getMessage()));
|
||||
}
|
||||
$this->coinbase = $coinbase;
|
||||
});
|
||||
|
||||
$eth = $web3->eth;
|
||||
$eth->accounts(function ($err, $accounts) use ($eth) {
|
||||
if ($err !== null) {
|
||||
echo 'Error: ' . $err->getMessage();
|
||||
return;
|
||||
}
|
||||
dump($accounts);
|
||||
});
|
||||
// $personal->unlockAccount($this->coinbase, '123456', function ($err, $unlocked) {
|
||||
// if ($err !== null) {
|
||||
// echo 'Error: ' . $err->getMessage();
|
||||
// return;
|
||||
// }
|
||||
// if ($unlocked) {
|
||||
// echo 'New account is unlocked!' . PHP_EOL;
|
||||
// } else {
|
||||
// echo 'New account isn\'t unlocked' . PHP_EOL;
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
|
||||
$web3->eth->getBalance( $this->coinbase , function ($err, $balance) {
|
||||
if ($err !== null) {
|
||||
echo 'Error: ' . $err->getMessage();
|
||||
return;
|
||||
}
|
||||
echo 'Balance: ' . $balance->toString() . PHP_EOL;
|
||||
});
|
||||
|
||||
|
||||
|
||||
$newAccount = '';
|
||||
|
||||
|
||||
$web3->personal->newAccount('123456', function ($err, $account) use (&$newAccount) {
|
||||
dump($err);
|
||||
if ($err !== null) {
|
||||
echo 'Error: ' . $err->getMessage();
|
||||
return;
|
||||
}
|
||||
$newAccount = $account;
|
||||
echo 'New account: ' . $account . PHP_EOL;
|
||||
});
|
||||
|
||||
dump($this->coinbase);
|
||||
// $web3->eth->getWork(function ($err, $coinbase) {
|
||||
// if ($err !== null) {
|
||||
// dump($this->fail($err->getMessage()));
|
||||
// }
|
||||
// dump($coinbase);
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// $web3->clientVersion(function ($err, $version) {
|
||||
// if ($err !== null) {
|
||||
// // do something
|
||||
// return;
|
||||
// }
|
||||
// dump($version);die;
|
||||
// if (isset($client)) {
|
||||
// echo 'Client version: ' . $version;
|
||||
// }
|
||||
// });
|
||||
die;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$web3 = new Web3('http://localhost:8545');
|
||||
//$getPersonal = $web3->getEth;
|
||||
|
||||
$personal = $web3->personal;
|
||||
|
||||
$newAccount = '';
|
||||
|
||||
echo 'Personal Create Account and Unlock Account' . PHP_EOL;
|
||||
|
||||
// create account
|
||||
$personal->newAccount('123456', function ($err, $account) use (&$newAccount) {
|
||||
if ($err !== null) {
|
||||
echo 'Error: ' . $err->getMessage();
|
||||
return;
|
||||
}
|
||||
$newAccount = $account;
|
||||
echo 'New account: ' . $account . PHP_EOL;
|
||||
});
|
||||
|
||||
$personal->unlockAccount($newAccount, '123456', function ($err, $unlocked) {
|
||||
if ($err !== null) {
|
||||
echo 'Error: ' . $err->getMessage();
|
||||
return;
|
||||
}
|
||||
if ($unlocked) {
|
||||
echo 'New account is unlocked!' . PHP_EOL;
|
||||
} else {
|
||||
echo 'New account isn\'t unlocked' . PHP_EOL;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// get balance
|
||||
$web3->eth->getBalance($newAccount, function ($err, $balance) {
|
||||
if ($err !== null) {
|
||||
echo 'Error: ' . $err->getMessage();
|
||||
return;
|
||||
}
|
||||
echo 'Balance: ' . $balance->toString() . PHP_EOL;
|
||||
});
|
||||
|
||||
die;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user