$userAgentString ); $responseOne = wp_remote_get($requestOne, $args); $firstResponseError = false; // set this flag and only run logic for requestTwo since requestOne failed if ( is_wp_error( $responseOne ) || $responseOne['response']['code'] !== 200) { AGC_Util::log(__FILE__, __LINE__, 'ERROR: ' . print_r($responseOne, true)); $firstResponseError = true; } // we know requestOne failed, so just return the results for requestTwo if ($firstResponseError) { $responseTwo = wp_remote_get($requestTwo, $args); if ( is_wp_error($responseTwo) || $responseTwo['response']['code'] !== 200) { AGC_Util::log(__FILE__, __LINE__, 'ERROR: ' . $responseTwo['response']['code']); throw new \Exception('Could not reach external services to verify electrum address is unused.'); } $totalReceivedSatoshi = (float) json_decode($responseTwo['body']); return $totalReceivedSatoshi > 0; } $totalReceivedOne = (float) json_decode($responseOne['body']); // we just need one verification the address is dirty if ($totalReceivedOne > 0) { return true; } // since the API sometimes fails with a response of 0, we try again $responseTwo = wp_remote_get($requestTwo, $args); if ( is_wp_error($responseTwo) || $responseTwo['response']['code'] !== 200) { return $totalReceivedOne > 0; } $totalReceivedTwo = (float) json_decode($responseTwo['body']); return $totalReceivedTwo > 0; } private static function check_dirty_litecoin($address) { $userAgentString = self::get_user_agent_string(); $requestOne = 'https://api.blockcypher.com/v1/ltc/main/addrs/' . $address . '?confirmations=0'; $requestTwo = 'https://chain.so/api/v2/get_address_received/LTC/' . $address; $args = array( 'user-agent' => $userAgentString ); $responseOne = wp_remote_get($requestOne, $args); $requestOneFailed = false; if (is_wp_error($responseOne) || $responseOne['response']['code'] !== 200) { AGC_Util::log(__FILE__, __LINE__, 'ERROR: ' . $responseOne['response']['code']); $requestOneFailed = true; } if ($requestOneFailed) { $responseTwo = wp_remote_get($requestTwo, $args); if (is_wp_error($responseTwo) || $responseTwo['response']['code'] !== 200) { AGC_Util::log(__FILE__, __LINE__, 'ERROR: ' . $responseTwo['response']['code']); throw new \Exception('Could not reach external services to verify electrum address is unused.'); } $unconfirmedAmount = (float) json_decode($responseTwo['body'])->data->unconfirmed_received_value; $confirmedAmount = (float) json_decode($responseTwo['body'])->data->confirmed_received_value; $totalReceivedTwo = $unconfirmedAmount + $confirmedAmount; return $totalReceivedTwo > 0; } $totalReceivedOne = json_decode($responseOne['body'])->total_received; if ($totalReceivedOne > 0) { return true; } $responseTwo = wp_remote_get($requestTwo, $args); if (is_wp_error($responseTwo) || $responseTwo['response']['code'] !== 200) { return $totalReceivedOne > 0; } $unconfirmedAmount = (float) json_decode($responseTwo['body'])->data->unconfirmed_received_value; $confirmedAmount = (float) json_decode($responseTwo['body'])->data->confirmed_received_value; $totalReceivedTwo = $unconfirmedAmount + $confirmedAmount; return $totalReceivedTwo > 0; } private static function get_bitcoin_received_by($address, $requiredConfirmations) { $userAgentString = self::get_user_agent_string(); $request = 'https://blockchain.info/q/getreceivedbyaddress/' . $address . '?confirmations=' . $requiredConfirmations; $args = array( 'user-agent' => $userAgentString ); $response = wp_remote_get($request, $args); if ( is_wp_error( $response ) || $response['response']['code'] !== 200) { AGC_Util::log(__FILE__, __LINE__, 'ERROR: ' . $response['response']['code']); throw new \Exception('Could not reach external services to verify electrum address total received.'); } $totalReceivedSatoshi = (float) json_decode($response['body']); $totalReceived = $totalReceivedSatoshi / 100000000; return $totalReceived; } private static function get_litecoin_received_by($address, $requiredConfirmations) { $userAgentString = self::get_user_agent_string(); $requestOne = 'https://api.blockcypher.com/v1/ltc/main/addrs/' . $address . '?confirmations=' . $requiredConfirmations; $requestTwo = 'https://chain.so/api/v2/get_address_received/LTC/' . $address; $args = array( 'user-agent' => $userAgentString ); $responseOne = wp_remote_get($requestOne, $args); $requestOneFailure = false; if (is_wp_error($responseOne) || $responseOne['response']['code'] !== 200) { AGC_Util::log(__FILE__, __LINE__, 'ERROR: ' . $responseOne['response']['code']); $requestOneFailure = true; } if ($requestOneFailure) { AGC_Util::log(__FILE__, __LINE__, 'calling received by: ' . $requestTwo); $responseTwo = wp_remote_get($requestTwo, $args); if (is_wp_error($responseTwo) || $responseTwo['response']['code'] !== 200) { AGC_Util::log(__FILE__, __LINE__, 'ERROR: ' . $responseTwo['response']['code']); throw new \Exception('Could not reach external services to verify electrum address total received.'); } $unconfirmedAmount = (float) json_decode($responseTwo['body'])->data->unconfirmed_received_value; $confirmedAmount = (float) json_decode($responseTwo['body'])->data->confirmed_received_value; $totalReceived = $confirmedAmount; return $totalReceived; } $totalReceivedMmltc = json_decode($responseOne['body'])->total_received; $totalReceived = $totalReceivedMmltc / 100000000; return $totalReceived; } public static function verify_exact_ether_transaction_amount($address, $amount, $requiredConfirmations) { $request = 'http://api.etherscan.io/api?module=account&action=txlist&address=' . $address . '&startblock=0&endblock=99999999&sort=asc'; $response = wp_remote_get($request); if (is_wp_error($response) || $response['response']['code'] !== 200) { throw new \Exception('Count not reach external services to verify ether transaction.'); } $body = json_decode($response['body']); $transactions = $body->result; foreach ($transactions as $transaction) { $confirmations = $transaction->confirmations; if ($confirmations >= $requiredConfirmations) { $etherToMatch = 1000000000000000000 * $amount; if (abs($etherToMatch - $transaction->value) < 1) { AGC_Util::log(__FILE__, __LINE__, 'We found a matching transaction for an order... Transaction hash: ' . $transaction->hash); return $transaction->hash; } } } return ''; } private static function get_user_agent_string() { return 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.576.0 Safari/534.12'; } } ?>