Bitcoin Forum
November 09, 2024, 05:10:40 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: checking balances with electrum  (Read 698 times)
Drauganaut (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
June 13, 2015, 09:37:44 AM
 #1

I want to use electrum to check the balances of bitcoin addresses in my PHP application. Here is how I am currently doing this:

Code:
function get_address_balance($btcaddress) {
$output = shell_exec("electrum getaddressbalance ".escapeshellarg($btcaddress));

if ($output=='daemon is not connected'){return False;}

$balances = objectToArray(json_decode($output));

// $balances['confirmed'] and $balances['unconfirmed'];
return $balances;
}

This piece of code can take a very long time to execute, usually a minimum of one second but normally much longer than that. what is the best way to do this?
ThomasV
Moderator
Legendary
*
Offline Offline

Activity: 1896
Merit: 1353



View Profile WWW
June 13, 2015, 10:17:22 PM
 #2

are these addresses from a wallet, or just random addresses?
in the first case, you might want to try the jsonrpc interface that comes with version 2.3

Electrum: the convenience of a web wallet, without the risks
zebedee
Donator
Hero Member
*
Offline Offline

Activity: 668
Merit: 500



View Profile
June 19, 2015, 01:00:55 PM
 #3

I want to use electrum to check the balances of bitcoin addresses in my PHP application. Here is how I am currently doing this:

Code:
function get_address_balance($btcaddress) {
$output = shell_exec("electrum getaddressbalance ".escapeshellarg($btcaddress));

if ($output=='daemon is not connected'){return False;}

$balances = objectToArray(json_decode($output));

// $balances['confirmed'] and $balances['unconfirmed'];
return $balances;
}

This piece of code can take a very long time to execute, usually a minimum of one second but normally much longer than that. what is the best way to do this?
Electrum is an interpreted Python program.  You are restarting it on each run of this code.  The Python interpreter needs to load tons of Python scripts before it can even start doing anything useful.  Usually starting electrum and getting past initialization takes from 1.5 to 10 seconds, depending on your wallet size and computer speed, amongst other things.

If you want to go faster, you need to be asking a long-running daemon process of some kind, not an electrum client.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!