xmrmemes/app/Rules/ValidateAddress.php
2021-07-15 23:35:54 -07:00

45 lines
1.1 KiB
PHP

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use MoneroIntegrations\MoneroPhp\walletRPC;
class ValidateAddress implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$walletRPC = new walletRPC('127.0.0.1', config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
$open_wallet = $walletRPC->open_wallet(config('app.xmr_wallet_name'), '');
$validate_address = $walletRPC->validate_address($value);
return $validate_address['valid'];
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The Monero address is not valid.';
}
}