lbry-sdk/lbrynet/wallet/server/block_processor.py

46 lines
1.6 KiB
Python
Raw Normal View History

from torba.server.block_processor import BlockProcessor
2019-03-31 00:40:01 +01:00
from lbrynet.schema.claim import Claim
from lbrynet.wallet.server.db import SQLDB
class LBRYBlockProcessor(BlockProcessor):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.env.coin.NET == "regtest":
self.prefetcher.polling_delay = 0.5
self.should_validate_signatures = self.env.boolean('VALIDATE_CLAIM_SIGNATURES', False)
2019-03-31 00:40:01 +01:00
self.logger.info(f"LbryumX Block Processor - Validating signatures: {self.should_validate_signatures}")
self.sql: SQLDB = self.db.sql
def advance_blocks(self, blocks):
2019-03-31 00:40:01 +01:00
self.sql.begin()
try:
super().advance_blocks(blocks)
except:
self.logger.exception(f'Error while advancing transaction in new block.')
raise
finally:
self.sql.commit()
def advance_txs(self, height, txs):
undo = super().advance_txs(height, txs)
self.sql.advance_txs(height, txs)
return undo
2019-03-26 19:10:15 +01:00
def _checksig(self, value, address):
try:
2019-03-20 06:46:23 +01:00
claim_dict = Claim.from_bytes(value)
cert_id = claim_dict.signing_channel_hash
if not self.should_validate_signatures:
return cert_id
if cert_id:
cert_claim = self.db.get_claim_info(cert_id)
if cert_claim:
2019-03-20 06:46:23 +01:00
certificate = Claim.from_bytes(cert_claim.value)
claim_dict.validate_signature(address, certificate)
return cert_id
2019-03-20 20:47:40 +01:00
except Exception:
pass