* server should check and return bitcoind status..
* improve txpoint sorting
* command to check cache
+
+ mempool transactions do not need to be added to the database; it slows it down
"""
_hash = store.binout(row[6])
address = hash_to_address(chr(0), _hash)
if self.tx_cache.has_key(address):
- print "cache: invalidating", address, self.ismempool
+ print "cache: invalidating", address
self.tx_cache.pop(address)
outrows = self.get_tx_outputs(txid, False)
for row in outrows:
_hash = store.binout(row[6])
address = hash_to_address(chr(0), _hash)
if self.tx_cache.has_key(address):
- print "cache: invalidating", address, self.ismempool
+ print "cache: invalidating", address
self.tx_cache.pop(address)
def safe_sql(self,sql, params=(), lock=True):
JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
WHERE pubkey.pubkey_hash = ? """, (dbhash,))
- def get_txpoints(self, addr):
+ def get_history(self, addr):
if config.get('server','cache') == 'yes':
cached_version = self.tx_cache.get( addr )
version, binaddr = decode_check_address(addr)
if binaddr is None:
- return "err"
+ return None
+
dbhash = self.binin(binaddr)
rows = []
rows += self.get_address_out_rows( dbhash )
tx_hash = self.hashout_hex(tx_hash)
if tx_hash in known_tx:
continue
+
+ # this means that pending transactions were added to the db, even if they are not returned by getmemorypool
+ address_has_mempool = True
+
+ # this means pending transactions are returned by getmemorypool
if tx_hash not in self.mempool_keys:
continue
- address_has_mempool = True
#print "mempool", tx_hash
txpoint = {
"nTime": 0,
-
def send_tx(tx):
import bitcoinrpc
conn = bitcoinrpc.connect_to_local()
try:
cmd, data = ast.literal_eval(msg[:-1])
except:
- print "syntax error", repr(msg)
+ print "syntax error", repr(msg), ipaddr
conn.close()
return
version = "old"
else:
version, addresses = ast.literal_eval(data)
- version = "v"+version
+ if version[0]=="0": version = "v" + version
except:
print "error", data
conn.close()
if store.tx_cache.get( addr ) is not None: k += 1
# get addtess status, i.e. the last block for that address.
- tx_points = store.get_txpoints(addr)
+ tx_points = store.get_history(addr)
if not tx_points:
status = None
else:
status = lastpoint['blk_hash']
# this is a temporary hack; move it up once old clients have disappeared
if status == 'mempool' and session['version'] != "old":
- status = status + ':%s'% lastpoint['tx_hash']
+ status = status + ':%d'% len(tx_points)
last_status = addresses.get( addr )
if last_status != status:
elif cmd == 'h':
# history
address = data
- out = repr( store.get_txpoints( address ) )
+ out = repr( store.get_history( address ) )
elif cmd == 'load':
if config.get('server','password') == data:
elif cmd =='clear_cache':
if config.get('server','password') == data:
- self.tx_cache = {}
+ store.tx_cache = {}
out = 'ok'
else:
out = 'wrong password'
conn.close()
-ds = BCDataStream.BCDataStream()
def memorypool_update(store):
+ ds = BCDataStream.BCDataStream()
store.mempool_keys = []
conn = bitcoinrpc.connect_to_local()
try:
ds.write(hextx.decode('hex'))
tx = deserialize.parse_Transaction(ds)
tx['hash'] = util.double_sha256(tx['tx'])
- store.mempool_keys.append(tx['hash'][::-1].encode('hex'))
+ tx_hash = tx['hash'][::-1].encode('hex')
+ store.mempool_keys.append(tx_hash)
if store.tx_find_id_and_value(tx):
pass
- else:
+ else:
store.import_tx(tx, False)
store.commit()
if len(sys.argv)>1:
cmd = sys.argv[1]
+ pw = config.get('server','password')
if cmd == 'load':
- request = "('load','%s')#"%config.get('server','password')
+ request = "('load','%s')#"%pw
elif cmd == 'peers':
request = "('peers','')#"
elif cmd == 'stop':
- request = "('stop','%s')#"%config.get('server','password')
+ request = "('stop','%s')#"%pw
elif cmd == 'clear_cache':
- request = "('clear_cache','%s')#"%config.get('server','password')
+ request = "('clear_cache','%s')#"%pw
elif cmd == 'get_cache':
- request = "('get_cache',('%s','%s'))#"%(config.get('server','password'),sys.argv[2])
+ request = "('get_cache',('%s','%s'))#"%(pw,sys.argv[2])
elif cmd == 'h':
request = "('h','%s')#"%sys.argv[2]
elif cmd == 'b':
args.connect_args = { 'database' : config.get('database','database') }
store = MyStore(args)
store.tx_cache = {}
- store.ismempool = False
store.mempool_keys = {}
thread.start_new_thread(listen_thread, (store,))
try:
dblock.acquire()
store.catch_up()
- store.ismempool = True
memorypool_update(store)
- store.ismempool = False
block_number = store.get_block_number(1)
dblock.release()
except: