1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace qiniu\services\blockchain\bsc;
- use Exception;
- class Kit
- {
- protected $client;
- protected $credential;
- protected $transactor;
- function __construct($client, $credential)
- {
- $this->client = $client;
- $this->credential = $credential;
- $this->transactor = new Transactor($client, $credential);
- }
- function getSender()
- {
- return $this->credential->getAddress();
- }
- function balanceOf($addr)
- {
- return $this->client->getBalance($addr);
- }
- function transfer($to, $value)
- {
- $tx = [
- 'to' => $to,
- 'value' => $value
- ];
- return $this->transactor->transact($tx);
- }
- //abi, bytecode, args...
- function deployContract()
- {
- $args = func_get_args();
- if (count($args) < 2) {
- throw new Exception('no enough deploy parameters');
- }
- $abi = array_shift($args);
- $bytecode = array_shift($args);
- $contract = new SmartContract($this->client, $this->credential, $abi);
- $contract->bytecode($bytecode);
- return $contract->instantiate(...$args);
- }
- function waitForConfirmation($txid, $timeout = 300)
- {
- return $this->client->waitForConfirmation($txid, $timeout);
- }
- function bep20($addr)
- {
- return new Bep20($this->client, $this->credential, $addr);
- }
- function bep721($addr)
- {
- return new Bep721($this->client, $this->credential, $addr);
- }
- }
|