Пожалуйста, обратите внимание, что пользователь заблокирован
Начните принимать криптовалюты в качестве способа оплаты через проверенный скрипт, данный PHP сайт устанавливается на сервер(клир или онион)
Децентрализован - никаких сторонних сервисов, никакой регистрации, никакой процедуры KYC
Единовременный платёж и никаких комиссий Fee
Используйте свои собственные узлы - при желании используйте свои собственные узлы для мониторинга блокчейна и создания платёжных адресов
Получайте выплаты в самых популярных криптовалютах
Документация: https://boxcoin.dev/docs
Замените оригинальный functions.php
Децентрализован - никаких сторонних сервисов, никакой регистрации, никакой процедуры KYC
Единовременный платёж и никаких комиссий Fee
Используйте свои собственные узлы - при желании используйте свои собственные узлы для мониторинга блокчейна и создания платёжных адресов
Получайте выплаты в самых популярных криптовалютах
- Bitcoin (BTC)
- Ethereum (ETH)
- Dogecoin (Doge)
- Tether (USDT)
- USD Coin (USDC)
- Shiba Inu (SHIB)
- Chainlink (LINK)
- Basic Attention Token (BAT)
- Algorand (ALG)
- ERC-20 Tokens (ERC-20)
- Tether (TRX)
- XRP (XRP)
- BNB (BSC)
- Binance USD (BUSD)
- USD Coin ETH (USDC)
- Shiba Inu ETH (SHIB)
- Chainlink ETH (LINK)
- Litecoin (LTC)
- Bitcoin Cash (BCH)
- BEP-20 Tokens (BEP-20)
Документация: https://boxcoin.dev/docs
Замените оригинальный functions.php
PHP:
<?php
/*
* ==========================================================
* FUNCTIONS.PHP
* ==========================================================
*
* Admin and client side functions.
* You can not use Boxcoin to create a SAAS or Boxcoin-like business. For more details, visit https://boxcoin.dev/terms-of-service (see 5. Intellectual Property and Content Ownership).
* © 2022-2023 boxcoin.dev. All rights reserved.
*
*/
define('BXC_VERSION', '1.1.9');
if (!defined('BXC_CLOUD')) define('BXC_CLOUD', file_exists(__DIR__ . '/cloud'));
require(__DIR__ . '/config.php');
global $BXC_LOGIN;
global $BXC_LANGUAGE;
global $BXC_TRANSLATIONS;
global $BXC_TRANSLATIONS_2;
global $BXC_APPS;
$BXC_APPS = ['wordpress', 'exchange'];
for ($i = 0; $i < count($BXC_APPS); $i++) {
$file = __DIR__ . '/apps/' . $BXC_APPS[$i] . '/functions.php';
if (file_exists($file)) {
require_once($file);
}
}
/*
* -----------------------------------------------------------
* TRANSACTIONS
* -----------------------------------------------------------
*
* 1. Get transactions
* 2. Get a single transaction
* 3. Create a transaction
* 4. Generate a random cryptcurrency amount
* 5. Delete pending transactions older than 48h
* 6. Check the transactions of an address
* 7. Check a single transaction
* 8. Check pending transactions
* 9. Finalize a confirmed transaction
* 10 Update a transaction
* 11. Send the webhook for a specific transaction
* 12. Download transactions in CSV format
* 13. Generate an invoice
* 14. Update a transaction
* 15. Decrypt a transaction securely
* 16. Generate a payment link for a transaction
* 17. Get the transaction description array
* 18. Refunds a transaction
*
*/
function bxc_transactions_get_all($pagination = 0, $search = false, $status = false, $cryptocurrency = false, $date_range = false) {
$where = '';
if ($search) {
$search = bxc_db_escape(trim($search));
$where = '(' . (is_numeric($search) ? 'amount LIKE "%' . $search . '%" OR amount_fiat LIKE "%' . $search . '%" OR ' : '') . 'title LIKE "%' . $search . '%" OR description LIKE "%' . $search . '%" OR cryptocurrency LIKE "%' . $search . '%" OR currency LIKE "%' . $search . '%" OR `from` LIKE "%' . $search . '%" OR `to` LIKE "%' . $search . '%" OR hash LIKE "%' . $search . '%" OR external_reference LIKE "%' . $search . '%")';
}
if ($status) {
$where .= ($where ? ' AND ' : '') . ' status = "' . bxc_db_escape($status) . '"';
}
if ($cryptocurrency) {
$where .= ($where ? ' AND ' : '') . ' cryptocurrency = "' . bxc_db_escape($cryptocurrency) . '"';
}
if ($date_range && $date_range[0]) {
$where .= ($where ? ' AND ' : '') . ' creation_time >= "' . bxc_db_escape($date_range[0]) . '" AND creation_time <= "' . bxc_db_escape($date_range[1]) . '"';
}
$transactions = bxc_db_get('SELECT * FROM bxc_transactions' . ($where ? ' WHERE ' . $where : '') . ' ORDER BY id DESC' . ($pagination != -1 ? ' LIMIT ' . intval(bxc_db_escape($pagination, true)) * 100 . ',100' : ''), false);
return $transactions;
}
function bxc_transactions_get($transaction_id) {
return bxc_db_get('SELECT * FROM bxc_transactions WHERE id = ' . bxc_db_escape($transaction_id, true));
}
function bxc_transactions_create($amount, $cryptocurrency_code, $currency_code = false, $external_reference = '', $title = '', $description = '', $url = false, $billing = '', $vat = false) {
$query_parts = ['INSERT INTO bxc_transactions(title, description, `from`, `to`, hash, amount, amount_fiat, cryptocurrency, currency, external_reference, creation_time, status, webhook, billing, vat, vat_details) VALUES ("' . bxc_db_escape($title) . '", "' . ($description ? bxc_db_json_escape([base64_decode($description)]) : '') . '", "",', ', "' . bxc_db_escape($currency_code) . '", "' . bxc_db_escape($external_reference) . '", "' . gmdate('Y-m-d H:i:s') . '", "P", 0, "' . bxc_db_escape($billing) . '", "' . bxc_isset($vat, 'amount', 0) . '", "' . ($vat && !empty($vat['amount']) ? bxc_db_json_escape($vat) : '') . '")'];
$hash = '';
$address = false;
if (!$currency_code) $currency_code = bxc_settings_get('currency', 'USD');
if (in_array($cryptocurrency_code, ['stripe', 'verifone', 'paypal'])) {
$transaction_id = bxc_db_query($query_parts[0] . '"", "", "", "' . bxc_db_escape($amount, true) . '", "' . bxc_db_escape($cryptocurrency_code) . '"' . $query_parts[1], true);
return [$transaction_id, $cryptocurrency_code, $cryptocurrency_code == 'verifone' ? bxc_verifone_create_checkout($amount, $url, $transaction_id, $title, $currency_code) : ($cryptocurrency_code == 'stripe' ? bxc_stripe_payment(floatval($amount) * 100, $url, $transaction_id, $currency_code) : bxc_paypal_get_checkout_url($transaction_id, $url, $amount, $currency_code, $title))];
}
if ($cryptocurrency_code === 'btc_ln' && bxc_settings_get('ln-node-active')) {
require_once(__DIR__ . '/bitcoin.php');
$amount_cryptocurrency = $amount_cryptocurrency_string = bxc_crypto_get_cryptocurrency_value($amount, 'btc', $currency_code);
$invoice = bxc_btc_ln_create_invoice($amount_cryptocurrency);
$address = bxc_isset($invoice, 'payment_request');
if ($address) {
$hash = $invoice['r_hash'];
} else {
if (bxc_settings_get('notifications-ln')) {
bxc_email_notification(bxc_m('Lightning Network error', bxc_settings_get('language-admin')), json_encode($invoice));
}
return ['error', 'btc-ln'];
}
}
if (!$address) {
$decimals = bxc_crypto_get_decimals($cryptocurrency_code);
$custom_token = bxc_isset(bxc_get_custom_tokens(), $cryptocurrency_code);
$address = $custom_token ? $custom_token['address'] : bxc_crypto_get_address($cryptocurrency_code);
$amount_cryptocurrency = $currency_code == 'crypto' ? [$amount, ''] : ($custom_token ? false : explode('.', strval(bxc_crypto_get_cryptocurrency_value($amount, $cryptocurrency_code, $currency_code))));
if (bxc_crypto_whitelist_invalid($address, true, $cryptocurrency_code)) return 'whitelist-invalid';
if ($amount_cryptocurrency && !isset($amount_cryptocurrency[1])) array_push($amount_cryptocurrency, '');
if ($custom_token) {
$amount_cryptocurrency = explode('.', $amount * (1 / (floatval($custom_token['rate']) * ($currency_code == 'USD' ? 1 : bxc_usd_rates($currency_code)))));
if (!isset($amount_cryptocurrency[1])) array_push($amount_cryptocurrency, '');
$decimals = $custom_token['decimals'];
}
;
if (strlen($amount_cryptocurrency[1]) > $decimals) $amount_cryptocurrency[1] = substr($amount_cryptocurrency[1], 0, $decimals);
$amount_cryptocurrency_string = $amount_cryptocurrency[0] . ($amount_cryptocurrency[1] ? '.' . $amount_cryptocurrency[1] : '');
if ($address == bxc_settings_get_address($cryptocurrency_code)) {
$temp = bxc_db_get('SELECT amount FROM bxc_transactions WHERE cryptocurrency = "' . bxc_db_escape($cryptocurrency_code) . '"', false);
$existing_amounts = [];
$i = 0;
for ($i = 0; $i < count($temp); $i++) {
array_push($existing_amounts, $temp[$i]['amount']);
}
while (in_array($amount_cryptocurrency_string, $existing_amounts) && $i < 1000) {
$amount_cryptocurrency_string = bxc_transactions_random_amount($amount_cryptocurrency, $decimals);
$i++;
}
}
}
$transaction_id = bxc_db_query($query_parts[0] . '"' . $address . '", "' . $hash . '", "' . $amount_cryptocurrency_string . '", "' . bxc_db_escape($amount, true) . '", "' . bxc_db_escape($cryptocurrency_code) . '"' . $query_parts[1], true);
$url = bxc_is_demo(true);
if ($url) {
$amount_cryptocurrency_string = $url['amount'];
$transaction_id = $url['id'];
}
if (in_array($cryptocurrency_code, ['usdt', 'usdc', 'busd']) && bxc_is_address_generation($cryptocurrency_code)) {
$amount_cryptocurrency_string_split = explode('.', $amount_cryptocurrency_string);
if (count($amount_cryptocurrency_string_split) > 1 && strlen($amount_cryptocurrency_string_split[1]) > 2) {
$amount_cryptocurrency_string = $amount_cryptocurrency_string_split[0] . '.' . substr($amount_cryptocurrency_string_split[1], 0, 2);
}
}
return [$transaction_id, $amount_cryptocurrency_string, $address, bxc_settings_get_confirmations($cryptocurrency_code, $amount), bxc_encryption(bxc_transactions_get($transaction_id))];
}
function bxc_transactions_random_amount($amount, $decimals) {
$amount = bxc_decimal_number(floatval($amount[0] . ($amount[1] && $amount[1] != '0' ? '.' . $amount[1] : '')) * floatval('1.000' . rand(99, 9999)));
if (strpos($amount, '.')) {
$amount = explode('.', $amount);
while (strlen($amount[1]) > $decimals) {
$amount[1] = substr($amount[1], 0, $decimals);
}
$amount = $amount[0] . ($amount[1] && $amount[1] != '0' ? '.' . $amount[1] : '');
}
return $amount;
}
function bxc_transactions_delete_pending() {
$query = 'FROM bxc_transactions WHERE status = "P" AND creation_time < "' . gmdate('Y-m-d H:i:s', time() - intval(bxc_settings_get('delete-pending-interval', 48)) * 3600) . '"';
$transactions = bxc_db_get('SELECT `to`, `cryptocurrency` ' . $query, false);
$response = bxc_db_query('DELETE ' . $query);
if ($response === true) {
$addresses = [];
for ($i = 0; $i < count($transactions); $i++) {
$to = $transactions[$i]['to'];
$slug = $transactions[$i]['cryptocurrency'] . '-manual-addresses';
if (!isset($addresses[$slug])) {
$addresses[$slug] = json_decode(bxc_settings_db($slug, false, '{}'), true);
}
if (isset($addresses[$slug][$to])) {
unset($addresses[$slug][$to]);
bxc_settings_db($slug, $addresses[$slug]);
}
}
}
return $response;
}
function bxc_transactions_check($transaction_id) {
$boxcoin_transaction = bxc_transactions_get($transaction_id);
if (!$boxcoin_transaction) return bxc_error('Transaction ' . $transaction_id . ' not found.', 'bxc_transactions_check', true);
$refresh_interval = intval(bxc_settings_get('refresh-interval', 60)) * 60;
$time = time();
$transaction_creation_time = strtotime($boxcoin_transaction['creation_time'] . ' UTC');
if ((($transaction_creation_time + $refresh_interval) <= $time) && !bxc_is_demo()) {
return 'expired';
}
if ($boxcoin_transaction) {
$cryptocurrency_code = $boxcoin_transaction['cryptocurrency'];
if ($cryptocurrency_code === 'btc_ln') {
require_once(__DIR__ . '/bitcoin.php');
$invoice = bxc_btc_ln_get_invoice($boxcoin_transaction['hash']);
return $invoice && bxc_isset($invoice, 'state') === 'SETTLED' ? bxc_transactions_check_single(bxc_encryption($boxcoin_transaction)) : $invoice;
} else {
$to = $boxcoin_transaction['to'];
$address_generation = $to != bxc_settings_get_address($cryptocurrency_code) && !bxc_is_demo();
if (bxc_crypto_whitelist_invalid($to, true, $cryptocurrency_code)) return false;
$transactions = bxc_blockchain($cryptocurrency_code, 'transactions', false, $to);
$accept_underpayments = bxc_settings_get('accept-underpayments');
if (is_array($transactions)) {
for ($i = 0; $i < count($transactions); $i++) {
$transaction = $transactions[$i];
$transaction_time = bxc_isset($transaction, 'time');
$transaction_hash = bxc_isset($transaction, 'hash');
if ((!$transaction_hash || (bxc_is_demo() || !bxc_db_get('SELECT id FROM bxc_transactions WHERE hash = "' . bxc_db_escape($transaction['hash']) . '" LIMIT 1'))) && (empty($transaction['address']) || strtolower($transaction['address']) != strtolower($to)) && (!$transaction_time || $transaction_time > $transaction_creation_time) && ($address_generation || $accept_underpayments || $boxcoin_transaction['amount'] == $transaction['value'] || strpos($transaction['value'], $boxcoin_transaction['amount']) === 0)) {
if ($address_generation && empty($transaction_time)) {
$transaction = bxc_blockchain($cryptocurrency_code, 'transaction', $transaction_hash, $transaction['address']);
if (bxc_isset($transaction, 'time') < $transaction_creation_time) return false;
}
return bxc_encryption(array_merge($boxcoin_transaction, ['hash' => $transaction_hash, 'id' => $transaction_id, 'cryptocurrency' => $cryptocurrency_code, 'to' => $to]));
}
}
} else {
return ['error', $transactions];
}
}
}
return false;
}
function bxc_transactions_check_single($transaction) {
$transaction = bxc_transactions_decrypt($transaction);
$cryptocurrency_code = $transaction['cryptocurrency'];
$invoice = bxc_isset($transaction, 'billing') && bxc_settings_get('invoice-active') ? bxc_transactions_invoice($transaction['id']) : false;
if ($cryptocurrency_code === 'btc_ln') {
$response = bxc_transactions_complete($transaction, $transaction['amount'], '');
return ['confirmed' => true, 'invoice' => $invoice, 'redirect' => bxc_isset($response, 'redirect'), 'source' => bxc_isset($response, 'source')];
} else {
$minimum_confirmations = bxc_settings_get_confirmations($cryptocurrency_code, $transaction['amount']);
$transaction_blockchain = bxc_blockchain($cryptocurrency_code, 'transaction', $transaction['hash'], $transaction['to']);
if (!$transaction_blockchain) return 'transaction-not-found';
if (is_string($transaction_blockchain)) return bxc_error($transaction_blockchain, 'bxc_transactions_check_single', true);
$confirmations = bxc_isset($transaction_blockchain, 'confirmations');
if (!$confirmations && $transaction_blockchain['block_height']) $confirmations = bxc_blockchain($cryptocurrency_code, 'blocks_count') - $transaction_blockchain['block_height'] + 1;
$confirmed = $confirmations >= $minimum_confirmations;
$response = $confirmed ? bxc_transactions_complete($transaction, $transaction_blockchain['value'], $transaction_blockchain['address']) : [];
return ['confirmed' => $confirmed, 'confirmations' => $confirmations ? $confirmations : 0, 'minimum_confirmations' => $minimum_confirmations, 'hash' => $transaction['hash'], 'invoice' => $invoice, 'underpayment' => bxc_isset($response, 'underpayment') ? $transaction_blockchain['value'] : false, 'redirect' => bxc_isset($response, 'redirect'), 'source' => bxc_isset($response, 'source')];
}
}
function bxc_transactions_check_pending() {
$transactions = bxc_db_get('SELECT * FROM bxc_transactions WHERE status = "P" AND creation_time > "' . gmdate('Y-m-d H:i:s', time() - 172800) . '"', false);
$transactions_blockchains = [];
for ($i = 0; $i < count($transactions); $i++) {
$transaction = $transactions[$i];
$to = $transaction['to'];
$cryptocurrency_code = strtolower($transaction['cryptocurrency']);
if (bxc_crypto_whitelist_invalid($to, true, $cryptocurrency_code) || !bxc_crypto_is($cryptocurrency_code)) continue;
if (!isset($transactions_blockchains[$to])) {
$transactions_blockchains[$to] = bxc_blockchain($cryptocurrency_code, 'transactions', ['limit' => 99], $to);
}
$transactions_blockchain = $transactions_blockchains[$to];
$address_generation = $to != bxc_settings_get_address($cryptocurrency_code);
if (is_array($transactions_blockchain)) {
for ($y = 0; $y < count($transactions_blockchain); $y++) {
$transaction_blockchain = $transactions_blockchain[$y];
if ((empty($transaction_blockchain['time']) || $transaction_blockchain['time'] > strtotime($transaction['creation_time'] . ' UTC')) && ($address_generation || $transaction['amount'] == $transaction_blockchain['value'] || strpos($transaction_blockchain['value'], $transaction['amount']) === 0)) {
$transaction['hash'] = $transaction_blockchain['hash'];
$response = bxc_transactions_check_single($transaction);
if ($response && !empty($response['confirmed'])) {
bxc_transactions_update($transaction['id'], ['status' => 'C']);
}
}
}
}
}
}
function bxc_transactions_complete($transaction, $amount_blockchain, $address_from) {
$redirect = false;
$source = false;
$amount = $transaction['amount'];
$cryptocurrency_code = $transaction['cryptocurrency'];
$external_reference = $transaction['external_reference'];
$underpayment = floatval($amount_blockchain) < floatval($amount);
$node_transfer = false;
if ($underpayment) {
$note = $amount_blockchain . '/' . $amount . ' ' . strtoupper($cryptocurrency_code) . ' ' . bxc_('received') . '. ' . bxc_decimal_number(floatval($amount) - floatval($amount_blockchain)) . ' ' . strtoupper($cryptocurrency_code) . ' ' . bxc_('are missing.');
$description = bxc_transactions_get_description($transaction['id']);
if (!in_array($note, $description)) array_push($description, $note);
$underpayment = ', description = "' . bxc_db_json_escape($description) . '"';
if (bxc_settings_get('accept-underpayments')) {
$underpayment = false;
$amount = $amount_blockchain;
bxc_db_query('UPDATE bxc_transactions SET `amount` = "' . $amount_blockchain . '", amount_fiat = "' . bxc_crypto_get_fiat_value($amount_blockchain, $cryptocurrency_code, $transaction['currency']) . '" WHERE id = ' . bxc_db_escape($transaction['id'], true));
}
}
bxc_db_query('UPDATE bxc_transactions SET `from` = "' . bxc_db_escape($address_from) . '", hash = "' . bxc_db_escape($transaction['hash']) . '", status = "' . ($underpayment ? 'X' : 'C') . '"' . $underpayment . ' WHERE id = ' . bxc_db_escape($transaction['id'], true));
if (bxc_transactions_webhook_authorized($transaction) && (($cryptocurrency_code === 'btc' && bxc_settings_get('btc-node-address-generation') && bxc_settings_get('btc-node-url')) || bxc_is_eth_address_generation($cryptocurrency_code))) {
$ethereum = $cryptocurrency_code !== 'btc';
$prefix = $ethereum ? 'eth' : 'btc';
$addresses = json_decode(bxc_encryption(bxc_settings_db($prefix . '-addresses'), false), true);
for ($i = 0; $i < count($addresses); $i++) {
$private_key = bxc_isset($addresses[$i][0], 'private_key');
if ($private_key && $addresses[$i][0]['address'] == $transaction['to']) {
require_once(__DIR__ . ($ethereum ? '/web3.php' : '/bitcoin.php'));
$node_transfer = bxc_settings_get($prefix . '-node-transfer');
$to = $node_transfer ? bxc_settings_get($prefix . '-node-transfer-address') : bxc_settings_get($prefix . '-address');
if ($ethereum) {
bxc_eth_transfer($amount, $cryptocurrency_code, $to, $transaction['to'], $private_key);
} else {
bxc_btc_transfer($amount, $to, $transaction['to'], $private_key);
}
break;
}
}
}
bxc_crypto_convert($transaction['id'], $cryptocurrency_code, $amount_blockchain);
if (!$node_transfer) bxc_crypto_transfer($transaction['id'], $cryptocurrency_code, $amount_blockchain);
if (bxc_settings_get('notifications-sale')) {
$language = bxc_settings_get('language-admin');
bxc_email_notification(($underpayment ? '[' . bxc_m('Underpayment', $language) . '] ' : '') . bxc_m('New payment of', $language) . ' ' . $transaction['amount_fiat'] . ' ' . strtoupper($transaction['currency']), str_replace('{T}', $transaction['amount_fiat'] . ' ' . $transaction['currency'] . ' (' . $amount_blockchain . ' ' . strtoupper($cryptocurrency_code) . ')' . ($underpayment ? ' (<b>' . bxc_m('Underpayment', $language) . '</b>)' : ''), bxc_m('A new payment of {T} has been sent to your', $language)) . ' ' . ucfirst(bxc_crypto_name($transaction['cryptocurrency'])) . ' ' . bxc_m('address', $language) . ' <b>' . $transaction['to'] . '</b>. ' . bxc_m('Transaction ID' . ': ' . $transaction['id'], $language));
}
if (strpos($external_reference, 'shopify_') === 0) {
bxc_curl(bxc_settings_get('shopify-url') . '/admin/api/2023-01/orders/' . str_replace('shopify_', '', $external_reference) . '/transactions.json', json_encode(['transaction' => ['currency' => $transaction['currency'], 'amount' => $transaction['amount_fiat'], 'kind' => 'capture']]), ['X-Shopify-Access-Token: ' . trim(bxc_settings_get('shopify-token'))], 'POST');
}
if (!$underpayment) {
$external_reference = explode('|', bxc_encryption($external_reference, false));
$source = in_array('woo', $external_reference) ? 'woo' : (in_array('edd', $external_reference) ? 'edd' : false);
$redirect = $source == 'woo' ? $external_reference[1] : ($source ? bxc_settings_db('wp_edd_url') : false);
bxc_transactions_webhook($transaction, $source ? bxc_settings_db('wp_api_url') : false);
}
if (BXC_CLOUD) bxc_cloud_spend_credit($transaction['amount_fiat'], $transaction['currency']);
return ['underpayment' => $underpayment, 'redirect' => $redirect, 'source' => $source];
}
function bxc_transactions_update($transaction_id, $values) {
$query = 'UPDATE bxc_transactions SET ';
if (is_string($values)) $values = json_decode($values, true);
foreach ($values as $key => $value) {
$query .= bxc_db_escape($key) . ' = "' . (is_string($value) ? bxc_db_escape($value) : bxc_db_json_escape($value)) . '",';
}
if (bxc_isset($values, 'status') == 'C') {
$transaction = bxc_transactions_get($transaction_id);
bxc_transactions_complete($transaction, $transaction['amount'], $transaction['from']);
}
return bxc_db_query(substr($query, 0, -1) . ' WHERE id = ' . bxc_db_escape($transaction_id, true));
}
function bxc_transactions_webhook($transaction, $webhook_url = false) {
if (!$webhook_url) $webhook_url = bxc_settings_get('webhook-url');
if (!$webhook_url) return false;
if (is_string($transaction)) $transaction = ['id' => bxc_transactions_decrypt($transaction)['id']];
$webhook_secret_key = bxc_settings_get('webhook-secret');
$transaction = bxc_transactions_get($transaction['id']);
if ($transaction['status'] != 'C') return false;
if (!bxc_transactions_webhook_authorized($transaction)) return false;
$body = json_encode(['key' => $webhook_secret_key ? $webhook_secret_key : BXC_PASSWORD, 'transaction' => $transaction]);
bxc_db_query('UPDATE bxc_transactions SET webhook = 1 WHERE id = ' . $transaction['id']);
return bxc_curl($webhook_url, $body, ['Content-Type: application/json', 'Content-Length: ' . strlen($body)], 'POST');
}
function bxc_transactions_webhook_authorized($transaction) {
if ($transaction['webhook']) {
$url = bxc_is_demo(true);
if (!$url || bxc_isset($url, 'webhook_key') != bxc_settings_get('webhook-secret')) return false;
}
return true;
}
function bxc_transactions_download($search = false, $status = false, $cryptocurrency = false, $date_range = false) {
return bxc_csv(bxc_transactions_get_all(-1, $search, $status, $cryptocurrency, $date_range), ['ID', 'Title', 'Description', 'From', 'To', 'Hash', 'Amount', 'Amount FIAT', 'Cryptocurrency', 'Currency', 'External Reference', 'Creation Time', 'Status', 'Webhook', 'Billing', 'VAT', 'VAT details'], 'transactions');
}
function bxc_transactions_invoice($transaction_id) {
require_once __DIR__ . '/vendor/fpdf/fpdf.php';
require_once __DIR__ . '/vendor/fpdf/autoload.php';
require_once __DIR__ . '/vendor/fpdf/Fpdi.php';
$file_name = 'inv-' . $transaction_id . '.pdf';
$invoice_url = BXC_URL . 'uploads/' . $file_name;
if (file_exists(__DIR__ . '/uploads/' . $file_name)) return $invoice_url;
$transaction = bxc_transactions_get($transaction_id);
if (!$transaction || $transaction['status'] != 'C') return false;
$billing = json_decode($transaction['billing'], true);
$billing_text = $billing ? bxc_isset($billing, 'name', '') . PHP_EOL . bxc_isset($billing, 'address', '') . PHP_EOL . bxc_isset($billing, 'city', '') . ', ' . bxc_isset($billing, 'state', '') . ', ' . bxc_isset($billing, 'zip', '') . PHP_EOL . bxc_isset($billing, 'country', '') . PHP_EOL . PHP_EOL . bxc_isset($billing, 'vat', '') : '';
$pdf = new \setasign\Fpdi\Fpdi();
$pdf->AddPage();
$pdf->setSourceFile(__DIR__ . '/resources/invoice.pdf');
$tpl = $pdf->importPage(1);
$pdf->useTemplate($tpl, 0, 0, null, null);
$pdf->SetTextColor(90, 90, 90);
$pdf->SetXY(20, 29);
$pdf->SetFont('Arial', 'B', 20);
$pdf->Cell(1000, 1, bxc_('Tax Invoice'));
$pdf->SetXY(130, 27);
$pdf->SetFont('Arial', '', 13);
$pdf->Multicell(500, 7, bxc_('Invoice date: ') . date('d-m-Y') . PHP_EOL . bxc_('Invoice number: ') . 'INV-' . $transaction['id']);
$pdf->SetXY(20, 60);
$pdf->SetFont('Arial', 'B', 13);
$pdf->Cell(50, 1, bxc_('To'));
$pdf->SetFont('Arial', '', 13);
$pdf->SetXY(20, 70);
$pdf->Multicell(168, 7, strip_tags(trim(iconv('UTF-8', 'windows-1252', $billing_text))));
$pdf->SetXY(130, 60);
$pdf->SetFont('Arial', 'B', 13);
$pdf->Cell(168, 1, bxc_('Supplier'));
$pdf->SetFont('Arial', '', 13);
$pdf->SetXY(130, 70);
$pdf->Multicell(168, 7, strip_tags(trim(iconv('UTF-8', 'windows-1252', bxc_settings_get('invoice-details')))));
$pdf->SetXY(20, 150);
$pdf->SetFont('Arial', 'B', 13);
$pdf->Cell(168, 1, bxc_('Purchase details'));
$pdf->SetFont('Arial', '', 13);
$pdf->SetXY(20, 160);
$pdf->Cell(168, 1, $transaction['title']);
$pdf->SetXY(20, 180);
$pdf->SetFont('Arial', 'B', 13);
$pdf->Cell(168, 1, bxc_('Transaction amount'));
$pdf->SetFont('Arial', '', 13);
$pdf->SetXY(20, 190);
$pdf->Cell(168, 1, strtoupper($transaction['currency']) . ' ' . $transaction['amount_fiat'] . ' (' . strtoupper($transaction['cryptocurrency']) . ' ' . $transaction['amount'] . ')');
if ($transaction['vat']) {
$pdf->SetXY(20, 200);
$pdf->Cell(100, 1, 'VAT ' . strtoupper($transaction['currency']) . ' ' . $transaction['vat']);
}
$pdf->Output(__DIR__ . '/uploads/' . $file_name, 'F');
return $invoice_url;
}
function bxc_transactions_decrypt($transaction) {
if (is_string($transaction)) return json_decode(bxc_encryption($transaction, false), true);
if (!bxc_verify_admin()) {
bxc_error('security-error', 'bxc_transactions_decrypt');
return 'security-error';
}
return $transaction;
}
function bxc_payment_link($transaction_id) {
return BXC_URL . 'pay.php?id=' . bxc_encryption($transaction_id);
}
function bxc_transactions_get_description($transaction_id) {
$description = json_decode(bxc_isset(bxc_db_get('SELECT description FROM bxc_transactions WHERE id = ' . bxc_db_escape($transaction_id, true)), 'description', '[]'), true);
return $description ? $description : [];
}
function bxc_transactions_cancel($transaction) {
$transaction = bxc_transactions_decrypt($transaction);
if (isset($transaction['id'])) {
bxc_db_query('DELETE FROM bxc_transactions WHERE id = ' . bxc_db_escape($transaction['id'], true));
$slug = $transaction['cryptocurrency'] . '-manual-addresses';
$addresses = json_decode(bxc_settings_db($slug, false, '{}'), true);
$to = bxc_isset($transaction, 'to');
if ($to) {
unset($addresses[$to]);
bxc_settings_db($slug, $addresses);
}
}
return false;
}
function bxc_transactions_refund($transaction_id) {
$transaction = bxc_transactions_get($transaction_id);
$status = ['transaction-not-found', 'Transaction not found.'];
if ($transaction) {
if (in_array($transaction['status'], ['C', 'X'])) {
if ($transaction['hash']) {
$cryptocurrency_code = $transaction['cryptocurrency'];
$transaction_blockchain = bxc_blockchain($cryptocurrency_code, 'transaction', $transaction['hash'], $transaction['to']);
$address = bxc_isset($transaction_blockchain, 'address');
if ($address) {
if ($transaction_blockchain['value'] === $transaction['amount'] && $address === $transaction['from']) {
$status = ['refunds-not-enabled', 'Refunds not enabled.'];
if (bxc_settings_get('btc-node-refunds') && $cryptocurrency_code == 'btc') {
require_once(__DIR__ . '/bitcoin.php');
$response = bxc_btc_transfer($transaction_blockchain['value'], $address);
if (is_string($response)) {
$status = [true, str_replace('{R}', '<a href="#" data-hash="' . $response . '" target="_blank">' . bxc_('here') . '</a>', bxc_('Refund sent. Transaction details {R}.'))];
} else if ($response['error']) {
$status = ['bitcoin-error', bxc_isset($response['error'], 'message', $response['error'])];
}
} else if (bxc_settings_get('eth-node-refunds') && in_array($cryptocurrency_code, bxc_get_cryptocurrency_codes('eth'))) {
require_once(__DIR__ . '/web3.php');
$response = bxc_eth_transfer($transaction_blockchain['value'], $cryptocurrency_code, $address);
if (is_string($response)) {
$status = [true, str_replace('{R}', '<a href="#" data-hash="' . $response . '" target="_blank">' . bxc_('here') . '</a>', bxc_('Refund sent. Transaction details {R}.'))];
} else if ($response['error']) {
$status = ['ethereum-error', bxc_isset($response['error'], 'message', $response['error'])];
}
} else if (bxc_settings_get('coinbase-refunds')) {
$account = bxc_coinbase_get_accounts($cryptocurrency_code);
if ($account) {
$response = bxc_coinbase_curl('/v2/accounts/' . $account['id'] . '/transactions', ['to' => $address, 'amount' => $transaction_blockchain['value'], 'currency' => $cryptocurrency_code, 'type' => 'send']);
if (bxc_isset(bxc_isset($response, 'data', []), 'status') == 'pending') {
$status = [true, str_replace('{R}', '<a href="https://www.coinbase.com' . str_replace('/v2', '', $response['data']['resource_path']) . '" target="_blank">' . bxc_('here') . '</a>', bxc_('Refund sent. Transaction details {R}.'))];
} else {
$status = ['coinbase-error', isset($response['errors']) ? $response['errors'][0]['message'] : json_encode($response)];
}
} else {
$status = ['unsupported-cryptocurrency', 'Cryptocurrency not supported.'];
}
}
} else {
$status = ['invalid-amount', 'Invalid amount or address.'];
}
} else {
$status = ['sender-address-not-found', 'Sender address not found.'];
}
} else {
$status = ['hash-not-found', 'Transaction hash not found.'];
}
} else {
$status = ['wrong-transaction-status', 'Incorrect transaction status. Only transactions marked as completed or underpaid can be refunded.'];
}
}
if ($status[0] === true) {
$description = bxc_transactions_get_description($transaction_id);
array_push($description, str_replace('{R}', date('Y-m-d H:i:s'), bxc_('Refund sent on {R}. Transaction hash: ')) . $response);
bxc_transactions_update($transaction_id, ['status' => 'R', 'description' => $description]);
}
return ['status' => $status[0], 'message' => bxc_($status[1])];
}
/*
* -----------------------------------------------------------
* CHECKOUT
* -----------------------------------------------------------
*
* 1. Return all checkouts or the specified one
* 2. Save a checkout
* 3. Delete a checkout
* 4. Direct payment checkout
*
*/
function bxc_checkout_get($checkout_id = false) {
return bxc_db_get('SELECT * FROM bxc_checkouts' . ($checkout_id ? ' WHERE id = ' . bxc_db_escape($checkout_id, true) : ''), $checkout_id);
}
function bxc_checkout_save($checkout) {
$checkout = json_decode($checkout, true);
if (empty($checkout['currency'])) $checkout['currency'] = bxc_settings_get('currency', 'USD');
if (empty($checkout['id'])) {
return bxc_db_query('INSERT INTO bxc_checkouts(title, description, price, currency, type, redirect, hide_title, external_reference, creation_time) VALUES ("' . bxc_db_escape($checkout['title']) . '", "' . bxc_db_escape(bxc_isset($checkout, 'description', '')) . '", "' . bxc_db_escape($checkout['price'], true) . '", "' . bxc_db_escape(bxc_isset($checkout, 'currency', '')) . '", "' . bxc_db_escape($checkout['type']) . '", "' . bxc_db_escape(bxc_isset($checkout, 'redirect', '')) . '", ' . (empty($checkout['hide_title']) ? 0 : 1) . ', "' . bxc_db_escape(bxc_isset($checkout, 'external_reference', '')) . '", "' . gmdate('Y-m-d H:i:s') . '")', true);
} else {
return bxc_db_query('UPDATE bxc_checkouts SET title = "' . bxc_db_escape($checkout['title']) . '", description = "' . bxc_db_escape(bxc_isset($checkout, 'description', '')) . '", price = "' . bxc_db_escape($checkout['price'], true) . '", currency = "' . bxc_db_escape(bxc_isset($checkout, 'currency', '')) . '", type = "' . bxc_db_escape($checkout['type']) . '", redirect = "' . bxc_db_escape(bxc_isset($checkout, 'redirect', '')) . '", hide_title = ' . (empty($checkout['hide_title']) ? 0 : 1) . ', external_reference = "' . bxc_db_escape(bxc_isset($checkout, 'external_reference', '')) . '" WHERE id = "' . bxc_db_escape($checkout['id'], true) . '"');
}
}
function bxc_checkout_delete($checkout_id) {
return bxc_db_query('DELETE FROM bxc_checkouts WHERE id = "' . bxc_db_escape($checkout_id) . '"');
}
function bxc_checkout_direct() {
if (isset($_GET['checkout_id'])) {
echo '<div data-boxcoin="' . $_GET['checkout_id'] . '" data-price="' . bxc_isset($_GET, 'price') . '" data-external-reference="' . bxc_isset($_GET, 'external_reference', bxc_isset($_GET, 'external-reference', '')) . '" data-redirect="' . bxc_isset($_GET, 'redirect', '') . '" data-currency="' . bxc_isset($_GET, 'currency', '') . '"' . (isset($_GET['title']) ? ' data-title="' . $_GET['title'] . '"' : '') . (isset($_GET['description']) ? ' data-description="' . $_GET['description'] . '"' : '') . (isset($_GET['note']) ? ' data-note="' . $_GET['note'] . '"' : '') . '>';
require_once(__DIR__ . '/init.php');
echo '</div>';
}
}
/*
* -----------------------------------------------------------
* CRYPTO
* -----------------------------------------------------------
*
* 1. Get balances
* 2. Get the API key
* 3. Get the fiat value of a cryptocurrency value
* 4. Get the cryptocurrency value of a fiat value
* 5. Get blockchain data
* 6. Get cryptocurrency name
* 7. Get the crypto payment address
* 8. Get USD exchange rate
* 9. Get exchange rate
* 10. Convert to FIAT
* 11. Transfer cryptocurrencies
* 12. Get crypto network
* 13. Return the base cryptocurrency code of a token
* 14. Verify an address
* 15. Get all custom tokens
* 16. Get cryptocurrency codes by blockchain
* 17. Get decimals of a cryptocurrency
* 18. Get the amount in the correct decimal length
* 19. Check if a currency is a cryptocurrency
* 20. Check if a cryptocurrency code is a custom token
* 21. Get the cryptocurrency logo of the specified cryptocurrency code
* 22. Validate an address
* 23. Return the external explorer link of a transaction
* 24. Return the blockchain fee
*
*/
function bxc_crypto_balances($cryptocurrency_code = false) {
$cryptocurrencies = $cryptocurrency_code ? [$cryptocurrency_code] : ['btc', 'eth', 'xrp', 'doge', 'usdt', 'usdt_tron', 'usdt_bsc', 'usdc', 'busd', 'bnb', 'shib', 'ltc', 'link', 'bat', 'algo', 'bch'];
$currency = bxc_settings_get('currency', 'USD');
$response = ['balances' => []];
$total = 0;
$custom_token_images = [];
if (!$cryptocurrency_code) {
$custom_tokens = bxc_get_custom_tokens();
foreach ($custom_tokens as $key => $value) {
array_push($cryptocurrencies, $value['code']);
$custom_token_images[$key] = $value['img'];
}
}
for ($i = 0; $i < count($cryptocurrencies); $i++) {
$cryptocurrency_code = $cryptocurrencies[$i];
if (bxc_settings_get_address($cryptocurrency_code)) {
$balance = bxc_blockchain($cryptocurrency_code, 'balance');
$fiat = 0;
if ($balance && is_numeric($balance)) {
$fiat = bxc_crypto_get_fiat_value($balance, bxc_crypto_get_base_code($cryptocurrency_code), $currency);
$total += $fiat;
} else {
$balance = 0;
}
$response['balances'][$cryptocurrency_code] = ['amount' => $balance, 'fiat' => $fiat, 'name' => bxc_crypto_name($cryptocurrency_code, true)];
}
}
$response['total'] = round($total, 2);
$response['currency'] = strtoupper($currency);
$response['token_images'] = $custom_token_images;
return $response;
}
function bxc_crypto_api_key($service, $url = false) {
$key = false;
$key_parameter = false;
switch ($service) {
case 'etherscan':
$keys = ['TBGQBHIXM113HT94ZWYY8MXGWFP9257541', 'GHAQC5VG536H7MSZR5PZF27GZJUSGH94TK', 'F1HZ35IJCR8DQC4SGVJBYMYB928UFV58MP', 'ADR46A53KIXDJ6BMJYK5EEGKQJDDQH6H1K', 'AIJ9S76757JZ7B9KQMJTAN3SRNKF5F5P4M'];
$key_parameter = 'apikey';
break;
case 'ethplorer':
$keys = ['EK-feNiM-th8gYm7-qECAq', 'EK-qCQHY-co6TwoA-ASWUm', 'EK-51EKh-8cvKWm5-qhjuU', 'EK-wmJ14-faiQNhf-C5Gsj', 'EK-i6f3K-1BtBfUf-Ud7Lo'];
$key_parameter = 'apiKey';
break;
case 'bscscan':
$keys = ['2Z5V3AZV5P4K95M9UXPABQ19CAVWR7RM78', '6JG8B7F5CC5APF2Q1C3BXRMZSS92F1RGKX', '2BAPYF16Z6BR8TY2SZGN74231JNZ8TFQKU', '1DNAQ7C2UAYPS5WW7HQXPCF8WFYG8CP3XQ', 'MP3XAXN1D7XVYZQVNCMGII5JZTBRASG996'];
$key_parameter = 'apiKey';
break;
case 'blockdaemon':
$keys = ['5inALCDK3NzmSoA-EC4ribZEDAvj0zy95tPaorxMZYzTRR0u', 'i1-LMC4x9ZgSlZ-kSrCf3pEeckZadAsKCJxuvXRq9pusgK2T', 'ktbzuPccKUwnnMI73YLEK7h29dEOQfFBOCNAXJ0SnHw8rn69', 'FI2b6Cfpf8lee2xaTs98IprkPb1OuxjW11M2Sq-vlIrqzKsR', '1nvtfBzPsjByQPYBr0xoxc1jv9KrntMnOhkjKTkTt3ejxUXk'];
$key_parameter = '-';
break;
case 'tatum':
$keys = ['90a07172-cd5e-452e-9b81-56f37c9693bb', '573c3fea-8325-4088-a35e-e97fdf2bc365', '330c5774-0de7-4963-895f-2b0c784011d2', '2f9a0a5f-f587-4545-8c38-f72007461e7a', '076a59f5-7cb5-4169-a038-3decda950b41'];
$key_parameter = '-';
break;
}
if ($key_parameter) {
$key = bxc_settings_get($service . '-key');
if (!$key) $key = $keys[rand(0, 4)];
}
return $key ? ($url ? ($url . (strpos($url, '?') ? '&' : '?') . $key_parameter . '=' . $key) : $key) : ($url ? $url : false);
}
function bxc_crypto_get_fiat_value($amount, $cryptocurrency_code, $currency_code) {
if (!is_numeric($amount)) return bxc_error('Invalid amount (' . $amount . ')', 'bxc_crypto_get_fiat_value');
$cryptocurrency_code = strtoupper(bxc_crypto_get_base_code($cryptocurrency_code));
$unsupported = ['BNB', 'BUSD'];
if (in_array($cryptocurrency_code, $unsupported)) {
$usd_rates = $currency_code == 'USD' ? 1 : bxc_usd_rates($currency_code);
$crypto_rate_usd = json_decode(bxc_curl('https://api.binance.us/api/v3/ticker/price?symbol=' . $cryptocurrency_code . 'USD'), true)['price'];
$rate = 1 / (floatval($crypto_rate_usd) * $usd_rates);
} else {
$rate = bxc_exchange_rates($currency_code, $cryptocurrency_code);
}
return round((1 / $rate) * floatval($amount), 2);
}
function bxc_crypto_get_cryptocurrency_value($amount, $cryptocurrency_code, $currency_code) {
$unsupported = ['BNB', 'BUSD'];
$cryptocurrency_code = strtoupper(bxc_crypto_get_base_code($cryptocurrency_code));
$rate = false;
$is_crypto = bxc_crypto_is($currency_code);
if (!$is_crypto && in_array($cryptocurrency_code, $unsupported)) {
$usd_rates = $currency_code == 'USD' ? 1 : bxc_usd_rates($currency_code);
$crypto_rate_usd = json_decode(bxc_curl('https://api.binance.us/api/v3/ticker/price?symbol=' . $cryptocurrency_code . 'USD'), true)['price'];
$rate = 1 / (floatval($crypto_rate_usd) * $usd_rates);
} else if ($is_crypto) {
$rate = bxc_exchange_rates('usd', $cryptocurrency_code) / bxc_exchange_rates('usd', $currency_code);
} else {
$rate = bxc_exchange_rates($currency_code, $cryptocurrency_code);
}
return bxc_crypto_get_value_with_decimals(bxc_decimal_number($rate * floatval($amount)), $cryptocurrency_code);
}
function bxc_blockchain($cryptocurrency_code, $action, $extra = false, $address = false) {
$services = [
'btc' => [['https://mempool.space/api/', 'address/{R}', 'address/{R}/txs', 'tx/{R}', 'blocks/tip/height', 'mempool'], ['https://blockstream.info/api/', 'address/{R}', 'address/{R}/txs', 'tx/{R}', 'blocks/tip/height', 'blockstream'], ['https://blockchain.info/', 'q/addressbalance/{R}', 'rawaddr/{R}?limit=30', 'rawtx/{R}', 'q/getblockcount', 'blockchain'], 'blockdaemon'],
'eth' => [['https://api.etherscan.io/api?', 'module=account&action=balance&address={R}', 'module=account&action=txlist&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', 'module=account&action=txlist&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', false, 'etherscan'], ['https://api.ethplorer.io/', 'getAddressInfo/{R}', 'getAddressTransactions/{R}?limit=99&showZeroValues=false', 'getTxInfo/{R}', 'getLastBlock', 'ethplorer'], ['https://blockscout.com/eth/mainnet/api?', 'module=account&action=balance&address={R}', 'module=account&action=txlist&address={R}', 'module=transaction&action=gettxinfo&txhash={R}', false, 'blockscout'], 'blockdaemon'],
'xrp' => [['https://data.ripple.com/v2/', 'accounts/{R}/balances', 'accounts/{R}/transactions', 'transactions/{R}', false, 'ripple'], 'blockdaemon'],
'doge' => ['blockcypher', 'blockdaemon'],
'algo' => [['https://algoindexer.algoexplorerapi.io/v2/', 'accounts/{R}', 'accounts/{R}/transactions?limit=99', 'transactions/{R}', 'accounts/{R}', 'algoexplorerapi'], 'blockdaemon'],
'bnb' => [['https://api.bscscan.com/api?', 'module=account&action=balance&address={R}', 'module=account&action=txlist&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', 'module=account&action=txlist&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', false, 'bscscan']],
'ltc' => ['tatum', 'blockdaemon', 'blockcypher'],
'bch' => [['https://rest1.biggestfan.net/v2/address/', 'details/{R}', 'transactions/{R}', 'transactions/{R}', false, 'biggestfan'], 'blockdaemon'],
'trx' => [['https://apilist.tronscan.org/api/', 'account?address={R}', 'transaction?sort=-timestamp&count=true&limit=99&start=0&address={R}', 'transaction-info?hash={R}', false, 'tronscan'], 'tatum']
];
$services_testnet = [
'btc' => [['https://mempool.space/testnet/api/', 'address/{R}', 'address/{R}/txs', 'tx/{R}', 'blocks/tip/height', 'mempool']],
'eth' => [['https://api-goerli.etherscan.io/api?', 'module=account&action=balance&address={R}', 'module=account&action=txlist&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', 'module=account&action=txlist&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', false, 'etherscan']],
];
if (bxc_settings_get('testnet-' . bxc_crypto_get_network($cryptocurrency_code)) && isset($services_testnet[$cryptocurrency_code])) $services = $services_testnet;
$address = $address ? $address : bxc_settings_get_address($cryptocurrency_code);
$address_lowercase = strtolower($address);
$cryptocurrency_code_base = bxc_crypto_get_base_code($cryptocurrency_code);
$return_explorer = $action == 'transaction-explorer';
if ($return_explorer) $action = 'transaction';
// Tokens
$custom_token_code = ['eth' => false, 'trx' => false, 'bsc' => false];
$custom_token = bxc_isset(bxc_get_custom_tokens(), $cryptocurrency_code);
$is_token = (in_array($cryptocurrency_code, bxc_get_cryptocurrency_codes('eth')) && $cryptocurrency_code != 'eth') || ($custom_token && $custom_token['type'] == 'erc-20') ? 'eth' : (in_array($cryptocurrency_code, ['usdt_tron']) ? 'trx' : (in_array($cryptocurrency_code, ['busd', 'usdt_bsc']) || $custom_token && $custom_token['type'] == 'bep-20' ? 'bsc' : false));
if ($is_token) {
switch ($is_token) {
case 'eth':
require_once(__DIR__ . '/web3.php');
$services = [['https://api.etherscan.io/api?', 'module=account&action=tokenbalance&contractaddress={A}&address={R}&tag=latest', 'module=account&action=tokentx&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', 'module=account&action=tokentx&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', false, 'etherscan', 'module=account&action=tokentx&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc'], ['https://api.ethplorer.io/', 'getAddressInfo/{R}', 'getAddressHistory/{R}?limit=99&showZeroValues=false', 'getTxInfo/{R}', false, 'ethplorer', 'getAddressHistory/{R}?limit=99&showZeroValues=false'], ['https://blockscout.com/eth/mainnet/api?', 'module=account&action=tokenbalance&contractaddress={A}&address={R}', 'module=account&action=tokentx&address={R}&offset=99', 'module=account&action=tokentx&address={R}&offset=99', false, 'blockscout', 'module=account&action=tokenlist&address={R}']];
$contract_address = bxc_eth_get_contract($cryptocurrency_code_base);
$contract_address = $contract_address ? $contract_address[0] : false;
break;
case 'trx':
$services = $services['trx'];
$services[0][2] = 'contract/events?address={R}&start=0&limit=30';
$contract_address = bxc_tron_get_contract_address($cryptocurrency_code_base);
break;
case 'bsc':
$services = [['https://api.bscscan.com/api?', 'module=account&action=tokenbalance&contractaddress={A}&address={R}&tag=latest', 'module=account&action=tokentx&contractaddress={A}&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', 'module=account&action=tokentx&contractaddress={A}&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc', false, 'bscscan', 'module=account&action=tokentx&address={R}&startblock=0&endblock=99999999&offset=99&sort=asc']];
$contract_address = bxc_binance_get_contract_address($cryptocurrency_code_base);
break;
}
$custom_token_code[$is_token] = $cryptocurrency_code;
} else {
$services = bxc_isset($services, $cryptocurrency_code);
}
if ($custom_token) {
$contract_address = bxc_isset($custom_token, 'contract_address', $contract_address);
}
$slugs = false;
$transactions = [];
$single_transaction = $action == 'transaction';
$divider = 1;
// Custom Blockchain explorer
$custom_explorer = bxc_settings_get('custom-explorer-active') ? bxc_settings_get('custom-explorer-' . $action . '-url') : false;
if ($custom_explorer) {
$path = bxc_settings_get('custom-explorer-' . $action . '-path');
$data = bxc_curl(str_replace(['{R}', '{N}', '{N2}'], [$single_transaction ? $extra : $address, $cryptocurrency_code, bxc_crypto_name($cryptocurrency_code)], $custom_explorer));
$data = bxc_get_array_value_by_path($action == 'transactions' ? trim(explode(',', $path)[0]) : $path, json_decode($data, true));
if ($data) {
$custom_explorer_divider = 1;
if (bxc_settings_get('custom-explorer-divider')) {
$custom_explorer_divider = $cryptocurrency_code == 'eth' ? 1000000000000000000 : 100000000;
}
switch ($action) {
case 'balance':
if (is_numeric($data)) {
return floatval($data) / $custom_explorer_divider;
}
break;
case 'transaction':
if (is_array($data) && $data[0]) {
return ['time' => $data[0], 'address' => $data[1], 'value' => floatval($data[2]) / $custom_explorer_divider, 'confirmations' => $data[3], 'hash' => $data[4]];
}
break;
case 'transactions':
if (is_array($data)) {
for ($i = 0; $i < count($data); $i++) {
$transaction = bxc_get_array_value_by_path($path, $data[$i]);
array_push($transactions, ['time' => $transaction[1], 'address' => $transaction[2], 'value' => floatval($transaction[3]) / $custom_explorer_divider, 'confirmations' => $transaction[4], 'hash' => $transaction[5]]);
}
return $transactions;
}
break;
}
}
}
// Multi Network Explorers
$data_original = false;
if (empty($services)) return;
for ($i = 0; $i < count($services); $i++) {
if (!$return_explorer) {
if ($services[$i] === 'tatum') {
$base_url = 'https://api.tatum.io/v3/' . bxc_crypto_get_network($cryptocurrency_code, 'full_name') . '/';
$header = ['x-api-key: ' . (BXC_CLOUD ? TATUM_API_KEY : bxc_crypto_api_key('tatum'))];
switch ($action) {
case 'balance':
if ($cryptocurrency_code == 'usdt_tron') {
$json = bxc_curl($base_url . 'account/' . $address);
$data = json_decode($json, true);
if ($is_token) {
$trc_20 = bxc_isset($data, 'trc20');
if ($trc_20 && count($trc_20) && isset($trc_20[0][$contract_address])) return bxc_decimal_number($trc_20[0][$contract_address] / (10 ** bxc_crypto_get_decimals($cryptocurrency_code)));
} else if (isset($data['balance'])) {
return bxc_decimal_number($data['balance'] / (10 ** bxc_crypto_get_decimals($cryptocurrency_code)));
}
} else {
$json = bxc_curl($base_url . 'address/balance/' . $address);
$data = json_decode($json, true);
if (isset($data['incoming'])) {
return bxc_decimal_number($data['incoming'] - $data['outgoing']);
}
}
bxc_error($json, 'tatum');
continue 2;
case 'transactions':
if ($cryptocurrency_code == 'usdt_tron') {
$json = bxc_curl($base_url . 'transaction/account/' . $address . ($is_token ? '/trc20' : ''), '', $header);
$data = json_decode($json, true);
if (isset($data['transactions'])) {
$slugs = [false, 'from', 'value', false, 'txID', false];
$transactions = $data['transactions'];
$transactions_data = [];
for ($j = 0; $j < count($transactions); $j++) {
$token_info = $transactions[$i]['tokenInfo'];
if (strtolower($token_info['symbol']) == $cryptocurrency_code_base) {
$divider = 10 ** $token_info['decimals'];
array_push($transactions_data, $transactions[$j]);
}
}
$data = $transactions_data;
} else {
bxc_error($json, 'tatum');
continue 2;
}
} else {
$json = bxc_curl($base_url . 'transaction/address/' . $address . '?pageSize=30', '', $header);
$data = json_decode($json, true);
if (is_array($data) && count($data) && isset($data[0]['inputs'])) {
$slugs = ['ts', 'from', 'value', false, 'hash', 'blockNumber'];
for ($j = 0; $j < count($data); $j++) {
$data[$j]['address'] = $data[$j]['inputs'][0]['coin']['address'];
$data[$j]['value'] = 0;
$outputs = $data[$j]['outputs'];
$total = 0;
for ($y = 0; $y < count($outputs); $y++) {
$value = $outputs[$y]['value'];
$total += $value;
if (strtolower($outputs[$y]['address']) == $address_lowercase) {
$data[$j]['value'] = $value;
break;
}
}
if (!$data[$j]['value']) $data[$j]['value'] = $total + $data[$j]['fee'];
}
} else if (isset($data['errorCode'])) {
bxc_error($json, 'tatum');
continue 2;
}
}
break;
case 'transaction':
$json = bxc_curl($base_url . 'transaction/' . $extra, '', $header);
$data = json_decode($json, true);
if ($cryptocurrency_code == 'usdt_tron') {
if (isset($data['txID'])) {
$slugs = ['time', 'from', 'value', 'confirmations', 'txID', 'blockNumber'];
$raw = $data['rawData'];
$data['time'] = $raw['timestamp'];
$data['from'] = $raw['contract'][0]['parameter']['value']['ownerAddressBase58'];
$data['confirmations'] = bxc_isset(json_decode(bxc_curl($base_url . 'info', '', $header), true), 'blockNumber', $data['blockNumber']) - $data['blockNumber'];
$data['value'] = bxc_decimal_number(hexdec($data['log'][0]['data']) / (10 ** bxc_crypto_get_decimals($cryptocurrency_code)));
$data = [$data];
} else {
bxc_error($json, 'tatum');
continue 2;
}
} else {
if (isset($data['hash'])) {
$slugs = ['time', 'from', 'value', 'confirmations', 'hash', 'blockNumber'];
$inputs = bxc_isset($data, 'inputs', []);
$outputs = bxc_isset($data, 'outputs', []);
$data['address'] = count($inputs) ? $inputs[0]['coin']['address'] : '';
$data['value'] = 0;
$total = 0;
$data['confirmations'] = 0;
for ($y = 0; $y < count($outputs); $y++) {
$value = $outputs[$y]['value'];
$total += $value;
if (strtolower($outputs[$y]['address']) == $address_lowercase) {
$data['value'] = $value;
break;
}
}
if (!$data['value']) $data['value'] = $total + $data['fee'];
if (!empty($data['blockNumber'])) {
$blocks_count = json_decode(bxc_curl($base_url . 'info', '', $header), true);
$data['confirmations'] = isset($blocks_count['blocks']) ? $blocks_count['blocks'] - $data['blockNumber'] + 1 : 0;
}
$data = [$data];
} else {
bxc_error($json, 'tatum');
continue 2;
}
}
break;
}
} else if ($services[$i] === 'blockdaemon') {
$base_url = 'https://svc.blockdaemon.com/universal/v1/' . bxc_crypto_name($cryptocurrency_code) . '/mainnet/';
$header = ['Content-Type: application/json', 'Authorization: Bearer ' . (BXC_CLOUD ? BLOCKDAEMON_API_KEY : bxc_crypto_api_key('blockdaemon'))];
switch ($action) {
case 'balance':
$json = bxc_curl($base_url . 'account/' . $address, '', $header);
$data = json_decode($json, true);
if (is_array($data) && isset($data[0]['confirmed_balance'])) {
return bxc_decimal_number($data[0]['confirmed_balance'] / (10 ** $data[0]['currency']['decimals']));
}
bxc_error($json, 'blockdaemon');
continue 2;
case 'transactions':
case 'transaction':
$json = bxc_curl($base_url . ($single_transaction ? 'tx/' . $extra : 'account/' . $address . '/txs'), '', $header);
$data = json_decode($json, true);
if ($data) {
if ($single_transaction) {
if (isset($data['events'])) $data = [$data];
} else if (isset($data['data'])) $data = $data['data'];
}
if (is_array($data)) {
if (count($data) && isset($data[0]['events'])) {
$slugs = ['date', 'address', 'value', 'confirmations', 'id', 'block_number'];
for ($j = 0; $j < count($data); $j++) {
$events = $data[$j]['events'];
$transaction_value = 0;
$sender_address = '';
for ($y = 0; $y < count($events); $y++) {
switch ($cryptocurrency_code) {
case 'btc':
if (!empty($events[$y]['meta']) && !empty($events[$y]['meta']['addresses'])) {
$event_address = $events[$y]['meta']['addresses'][0];
$amount = $events[$y]['amount'];
if ($events[$y]['type'] == 'utxo_output' && strtolower($event_address) == $address_lowercase) {
$transaction_value += $amount;
if (isset($events[$y]['decimals'])) $divider = 10 ** $events[$y]['decimals'];
} else if ($events[$y]['type'] == 'utxo_input') {
$sender_address = $event_address;
}
}
break;
case 'xrp':
case 'bch':
case 'algo':
case 'ltc':
case 'doge':
case 'eth':
$get_address = false;
if (strtolower(bxc_isset($events[$y], 'destination')) == $address_lowercase) {
$transaction_value += $events[$y]['amount'];
$get_address = true;
if (isset($events[$y]['decimals'])) $divider = 10 ** $events[$y]['decimals'];
} else if (bxc_isset($events[$y], 'type') == 'utxo_input') {
$get_address = true;
}
if ($get_address && !empty($events[$y]['source'])) $sender_address = $events[$y]['source'];
break;
}
}
$data[$j]['value'] = $transaction_value;
$data[$j]['address'] = $sender_address;
}
}
} else {
bxc_error($json, 'blockdaemon');
continue 2;
}
break;
}
} else if ($services[$i] === 'blockcypher') {
$base_url = 'https://api.blockcypher.com/v1/' . $cryptocurrency_code . '/main/';
switch ($action) {
case 'balance':
$json = bxc_curl($base_url . 'addrs/' . $address);
$data = json_decode($json, true);
if ($data && isset($data['balance'])) {
return bxc_decimal_number($data['balance'] / (10 ** bxc_crypto_get_decimals($cryptocurrency_code)));
}
bxc_error($json, 'blockcypher');
continue 2;
case 'transactions':
case 'transaction':
$json = bxc_curl($base_url . ($single_transaction ? 'txs/' . $extra : 'addrs/' . $address . '/full'));
$data = json_decode($json, true);
if ($data) {
if ($single_transaction) {
if (isset($data['hash'])) $data = [$data];
} else if (isset($data['txs'])) $data = $data['txs'];
}
if ($data && is_array($data)) {
if (count($data)) {
$slugs = ['time', 'address', 'value', 'confirmations', 'hash', 'block_height'];
$divider = 10 ** bxc_crypto_get_decimals($cryptocurrency_code_base);
for ($j = 0; $j < count($data); $j++) {
$outputs = bxc_isset($data[$j], 'outputs', []);
$data[$j]['time'] = strtotime($data[$j]['received']);
$data[$j]['address'] = $data[$j]['inputs'][0]['addresses'][0];
$data[$j]['value'] = 0;
for ($y = 0; $y < count($outputs); $y++) {
if (strtolower($outputs[$y]['addresses'][0]) == $address_lowercase) {
$data[$j]['value'] = $outputs[$y]['value'];
break;
}
}
}
}
} else {
bxc_error($json, 'blockcypher');
continue 2;
}
break;
}
}
}
// Other explorers
if (!in_array($services[$i], ['tatum', 'blockdaemon', 'blockcypher'])) {
$url_part = $services[$i][$action == 'balance' ? 1 : ($action == 'transactions' ? 2 : ($single_transaction ? 3 : 4))];
if ($url_part === false) continue;
$url = $services[$i][0] . str_replace('{R}', $single_transaction && !in_array($services[$i][5], ['etherscan', 'bscscan', 'biggestfan']) ? $extra : $address, $url_part);
if ($is_token) $url = str_replace('{A}', $contract_address, $url);
$data = $data_original = bxc_curl(bxc_crypto_api_key($services[$i][5], $url));
switch ($cryptocurrency_code) {
case 'btc':
switch ($action) {
case 'balance':
$data = json_decode($data, true);
switch ($i) {
case 0:
case 1:
if (isset($data['chain_stats'])) {
return ($data['chain_stats']['funded_txo_sum'] - $data['chain_stats']['spent_txo_sum']) / 100000000;
}
break;
case 2:
if (is_numeric($data)) {
return intval($data) / 100000000;
}
break;
}
break;
case 'transaction':
case 'transactions':
$data = json_decode($data, true);
$input_slug = false;
$output_slug = false;
$confirmations = false;
$continue = false;
// Get transaction and verify the API is working
switch ($i) {
case 0:
case 1:
if (is_array($data) && empty($data['error'])) {
$output_slug = 'vout';
$input_slug = 'vin';
$continue = true;
}
break;
case 2:
if (($single_transaction && isset($data['inputs'])) || isset($data['txs'])) {
if (!$single_transaction) $data = $data['txs'];
$input_slug = 'inputs';
$output_slug = 'out';
$continue = true;
}
break;
}
if ($continue) {
$slugs = ['time', 'address', 'value', 'confirmations', 'hash', 'block_height'];
$sender_address = '';
$time = 0;
$block_height = 0;
$hash = '';
$divider = $i === 1 ? 1 : 100000000;
if ($single_transaction) $data = [$data];
// Get transactions details
for ($j = 0; $j < count($data); $j++) {
$transaction_value = 0;
switch ($i) {
case 0:
case 1:
if (bxc_isset($data[$j]['status'], 'confirmed')) {
$time = $data[$j]['status']['block_time'];
$block_height = $data[$j]['status']['block_height'];
}
$hash = $data[$j]['txid'];
break;
case 2:
$time = $data[$j]['time'];
$block_height = $data[$j]['block_height'];
$hash = $data[$j]['hash'];
break;
}
// Get transaction amount
$outputs = $output_slug ? $data[$j][$output_slug] : [];
for ($y = 0; $y < count($outputs); $y++) {
switch ($i) {
case 0:
case 1:
$value = $outputs[$y]['value'];
$output_address = $outputs[$y]['scriptpubkey_address'];
break;
case 2:
$value = $outputs[$y]['value'];
$output_address = $outputs[$y]['addr'];
break;
}
if (strtolower($output_address) == $address_lowercase) {
$transaction_value += $value;
}
$outputs[$y] = ['value' => $value, 'address' => $output_address];
}
// Get sender address
$input = bxc_isset($data[$j], $input_slug);
if ($input && count($input)) {
$input = $input[0];
switch ($i) {
case 0:
case 1:
$sender_address = $input['prevout']['scriptpubkey_address'];
break;
case 2:
$sender_address = $input['prev_out']['addr'];
break;
}
}
// Assign transaction values
$data[$j]['time'] = $time;
$data[$j]['address'] = $sender_address;
$data[$j]['confirmations'] = $confirmations;
$data[$j]['value'] = $transaction_value;
$data[$j]['hash'] = $hash;
$data[$j]['block_height'] = $block_height;
}
}
break;
case 'blocks_count':
if (is_numeric($data)) {
return intval($data);
}
}
break;
case $custom_token_code['eth']:
case 'link':
case 'shib':
case 'bat':
case 'usdt':
case 'usdc':
case 'eth':
$data = json_decode($data, true);
switch ($action) {
case 'balance':
switch ($i) {
case 2:
case 0:
$data = bxc_isset($data, 'result');
if (is_numeric($data)) {
require_once(__DIR__ . '/web3.php');
return floatval($data) / ($is_token ? 10 ** ($custom_token ? $custom_token['decimals'] : bxc_eth_get_contract($cryptocurrency_code)[1]) : 1000000000000000000);
}
break;
case 1:
if ($is_token) {
$data = bxc_isset($data, 'tokens', []);
for ($j = 0; $j < count($data); $j++) {
if (strtolower(bxc_isset(bxc_isset($data, 'tokenInfo'), 'symbol')) == $cryptocurrency_code) {
return floatval($data['balance']) / (10 ** intval($data['tokenInfo']['decimals']));
}
}
} else {
$data = bxc_isset(bxc_isset($data, 'ETH'), 'balance');
if (is_numeric($data)) {
return floatval($data);
}
}
break;
}
break;
case 'transaction':
case 'transactions':
switch ($i) {
case 2:
case 0:
$data = bxc_isset($data, 'result');
if (is_array($data)) {
$count = count($data);
$slugs = ['timeStamp', 'from', 'value', 'confirmations', 'hash', 'blockNumber'];
$divider = $is_token ? 1000000 : 1000000000000000000;
if ($single_transaction) {
if ($i === 0) {
$data_single = [];
for ($j = 0; $j < $count; $j++) {
if ($data[$j]['hash'] == $extra) {
$data_single = [$data[$j]];
break;
}
}
$data = $data_single;
} else {
$data = [$data];
}
} else if ($is_token) {
$data_temp = [];
for ($j = 0; $j < $count; $j++) {
if (strtolower($data[$j]['tokenSymbol']) == $cryptocurrency_code) {
array_push($data_temp, $data[$j]);
}
}
$data = $data_temp;
}
if ($count && isset($data[0]['tokenDecimal'])) $divider = 10 ** intval($data[0]['tokenDecimal']);
}
break;
case 1:
if ($single_transaction || is_array($data) || $is_token) {
$slugs = ['timestamp', 'from', 'value', 'confirmations', 'hash', 'blockNumber'];
if ($single_transaction) $data = [$data];
}
if ($is_token) {
if ($single_transaction) {
if (count($data)) {
$transaction_value = 0;
if (isset($data[0]['operations'])) {
$operations = $data[0]['operations'];
$address = strtolower($address);
for ($j = 0; $j < count($operations); $j++) {
if ($operations[$j]['type'] == 'transfer' && strtolower($operations[$j]['to']) == $address_lowercase) {
$transaction_value += $operations[$j]['value'];
}
}
$divider = 10 ** intval($operations[0]['tokenInfo']['decimals']);
$data[0]['value'] = $transaction_value;
}
}
} else {
$data = bxc_isset($data, 'operations', []);
$data_temp = [];
for ($j = 0; $j < count($data); $j++) {
if (strtolower($data[$j]['tokenInfo']['symbol']) == $cryptocurrency_code) {
array_push($data_temp, $data[$j]);
$divider = 10 ** intval($data[$j]['tokenInfo']['decimals']);
}
}
$slugs[4] = 'transactionHash';
$data = $data_temp;
}
}
break;
}
if ($slugs && (!$data || (count($data) && (!isset($data[0]) || !bxc_isset($data[0], $slugs[0]))))) $slugs = false;
break;
case 'blocks_count':
switch ($i) {
case 1:
if (is_numeric($data['lastBlock'])) {
return intval($data['lastBlock']);
}
break;
}
}
break;
case 'doge':
$data = json_decode($data, true);
switch ($action) {
case 'balance':
switch ($i) {
case 0:
$data = bxc_isset($data, 'data');
if ($data && isset($data['confirmed_balance'])) {
return $data['confirmed_balance'];
}
break;
}
break;
case 'transaction':
case 'transactions':
switch ($i) {
case 0:
$data = bxc_isset($data, 'data');
if ($data) {
if (!$single_transaction) $data = bxc_isset($data, 'txs');
$slugs = ['time', 'address', 'value', 'confirmations', 'txid', false];
} else if (is_array($data)) return [];
break;
}
if ($slugs) {
if (is_array($data)) {
if ($single_transaction && ($i === 0 || $i === 1)) {
$data['address'] = $data['inputs'][0]['address'];
$outputs = $data['outputs'];
for ($j = 0; $j < count($outputs); $j++) {
if (strtolower($outputs[$j]['address']) == $address_lowercase) {
$data['value'] = $outputs[$j]['value'];
break;
}
}
$data = [$data];
}
}
if (!$data || (count($data) && (!isset($data[0]) || (!bxc_isset($data[0], $slugs[0]) && !bxc_isset($data[0], $slugs[1]))))) $slugs = false;
}
break;
case 'blocks_count':
switch ($i) {
case 0:
if (is_numeric($data['lastBlock'])) {
return intval($data['lastBlock']);
}
break;
}
}
break;
case 'algo':
$data = json_decode($data, true);
switch ($action) {
case 'balance':
switch ($i) {
case 0:
$data = bxc_isset(bxc_isset($data, 'account'), 'amount');
if (is_numeric($data)) {
return floatval($data) / 1000000;
}
break;
}
break;
case 'transaction':
case 'transactions':
switch ($i) {
case 0:
$current_round = bxc_isset($data, 'current-round');
$data = bxc_isset($data, $single_transaction ? 'transaction' : 'transactions');
if ($data) {
$slugs = ['round-time', 'sender', 'amount', 'confirmations', 'id', 'confirmed-round'];
$divider = 1000000;
if ($single_transaction) {
$data['amount'] = bxc_isset(bxc_isset($data, 'payment-transaction'), 'amount', -1);
$data['confirmations'] = $current_round - bxc_isset($data, 'confirmed-round');
$data = [$data];
} else {
for ($j = 0; $j < count($data); $j++) {
$data[$j]['amount'] = bxc_isset(bxc_isset($data[$j], 'payment-transaction'), 'amount', -1);
$data[$j]['confirmations'] = $current_round - bxc_isset($data[$j], 'confirmed-round');
}
}
} else if (is_array($data)) return [];
break;
}
break;
case 'blocks_count':
switch ($i) {
case 1:
if (is_numeric($data['current-round'])) {
return intval($data['current-round']);
}
break;
}
}
break;
case $custom_token_code['bsc']:
case 'usdt_bsc':
case 'busd':
case 'bnb':
$data = json_decode($data, true);
switch ($action) {
case 'balance':
switch ($i) {
case 0:
$data = bxc_isset($data, 'result');
if (is_numeric($data)) {
return floatval($data) / 1000000000000000000;
}
break;
}
break;
case 'transaction':
case 'transactions':
switch ($i) {
case 0:
$data = bxc_isset($data, 'result');
if (is_array($data)) {
$slugs = ['timeStamp', 'from', 'value', 'confirmations', 'hash', 'blockNumber'];
$divider = 1000000000000000000;
if ($single_transaction) {
if ($i === 0) {
$data_single = [];
for ($j = 0; $j < count($data); $j++) {
if ($data[$j]['hash'] == $extra) {
$data_single = [$data[$j]];
break;
}
}
$data = $data_single;
} else {
$data = [$data];
}
}
}
break;
}
break;
}
break;
case 'ltc':
$data = json_decode($data, true);
switch ($action) {
case 'balance':
switch ($i) {
case 0:
$data = bxc_isset($data, 'data');
if ($data && isset($data['confirmed_balance'])) {
return $data['confirmed_balance'];
}
break;
}
break;
case 'transaction':
case 'transactions':
switch ($i) {
case 0:
$data = bxc_isset($data, 'data');
if ($data) {
if (!$single_transaction) $data = bxc_isset($data, 'txs');
$slugs = ['time', 'address', 'value', 'confirmations', 'txid', false];
} else if (is_array($data)) return [];
break;
}
if ($slugs) {
if (is_array($data)) {
if ($single_transaction && ($i === 0 || $i === 1)) {
$data['address'] = $data['inputs'][0]['address'];
$outputs = $data['outputs'];
for ($j = 0; $j < count($outputs); $j++) {
if (strtolower($outputs[$j]['address']) == $address_lowercase) {
$data['value'] = $outputs[$j]['value'];
break;
}
}
$data = [$data];
}
}
if (!$data || (count($data) && (!isset($data[0]) || (!bxc_isset($data[0], $slugs[0]) && !bxc_isset($data[0], $slugs[1]))))) $slugs = false;
}
break;
}
break;
case 'bch':
$data = json_decode($data, true);
switch ($action) {
case 'balance':
switch ($i) {
case 0:
$data = bxc_isset($data, 'balance');
if ($data) return $data;
break;
}
break;
case 'transaction':
case 'transactions':
switch ($i) {
case 0:
$data = bxc_isset($data, 'txs');
if ($data) {
$slugs = ['time', 'address', 'value', 'confirmations', 'txid', false];
} else if (is_array($data)) return [];
break;
}
if ($slugs) {
if (is_array($data)) {
for ($j = 0; $j < count($data); $j++) {
$data_transaction = $data[$j][0];
$data_transaction['address'] = str_replace('bitcoincash:', '', $data_transaction['vin'][0]['cashAddress']);
$outputs = $data_transaction['vout'];
$address_prefix = 'bitcoincash:' . $address;
for ($y = 0; $y < count($outputs); $y++) {
if (strtolower($outputs[$y]['scriptPubKey']['addresses'][0]) == $address_prefix) {
$data_transaction['value'] = $outputs[$y]['value'];
break;
}
}