Skip to content

Instantly share code, notes, and snippets.

@chrisjdavis
Last active November 14, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisjdavis/dec93a901b07bcd13488269d7148dac8 to your computer and use it in GitHub Desktop.
Save chrisjdavis/dec93a901b07bcd13488269d7148dac8 to your computer and use it in GitHub Desktop.
Full method, for context
public function create_account($vars, $type) {
$api = ( new \BlockMatrix\EosRpc\ChainFactory )->api();
$walapi = ( new \BlockMatrix\EosRpc\WalletFactory )->api();
$eos = ( new \BlockMatrix\EosRpc\EosRpc( $api, $walapi) );
$walapi->unlock( [self::WALLET_NAME, self::WALLET_PASS] );
$eos->setWalletInfo( self::WALLET_NAME, self::WALLET_PASS );
switch( $type ) {
case self::USER_TYPE_ACCOUNT :
$expiration = DateTime::date_create( DateTime::create( date(DATE_RFC822) )->modify('+60 seconds') )->format('c');
$expiration = str_replace( '+00:00', '', $expiration );
$user = User::get_by_id( $vars['user_id'] );
if( !$user->info->eos_active_public_key ) {
$this->create_keys( $user, self::USER_TYPE_ACCOUNT );
}
$account_n = $this->unique_string( $user->username );
$user->info->eos_account_name = $account_n;
$owner_public_key = $user->info->eos_owner_public_key;
$active_public_key = $user->info->eos_active_public_key;
$args = [
[
'account' => 'eosio',
'name' => 'newaccount',
'authorization' => [['actor' => 'eosio', 'permission' => 'active']],
'data' => [
'creator' => 'eosio',
'name' => $account_n,
'owner' => [
'threshold' => 1,
'keys' => [['key' => $owner_public_key, 'weight'=> 1]],
'accounts' => [],
'waits' => []
],
'active' => [
'threshold' => 1,
'keys' => [['key' => $active_public_key, 'weight' => 1]],
'accounts' => [],
'waits' => []
]
]
],
[
'account' => 'eosio',
'name' => 'buyrambytes',
'authorization' => [['actor' => 'eosio', 'permission' => 'active']],
'data' => [
'payer' => 'eosio',
'receiver' => $account_n,
'bytes' => 8192,
],
]
];
echo $eos->pushTransaction( $args, false );
exit();
$transaction_type = self::TRANSACTION_TYPE_USER_ACCOUNT_CREATE;
break;
case self::COMPANY_TYPE_ACCOUNT :
$transaction_type = self::TRANSACTION_TYPE_COMPANY_ACCOUNT_CREATE;
break;
}
$this->record_transaction( $eos_account, $transaction_type );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment