def addByPublic(self, pubKey): printable = pk2address(pubKey) if printable in self.accountsCache: acc = self.accountsCache[printable] if 'pubKey' in acc: return acc['id'] accId = self.db.updateAccount(acc['id'], pubKey, printable) else: accId = self.db.addAccount(pubKey, printable) self.accountsCache[printable] = {'id':accId, 'pubKey':pubKey} return accId
def processBlock(self, block): blockHarvesterAddress = pk2address(block['signer']) block['timestamp_unix'] = self._calc_unix(block['timeStamp']) block['timestamp'] = self._calc_timestamp(block['timestamp_unix']) block['timestamp_nem'] = block['timeStamp'] del block['timeStamp'] sid = self.accounts.addByPublic(block['signer']) block['signer_id'] = sid feesTotal = 0 txes = block["transactions"] del block['transactions'] success("processing block[{}] : {} : {}".format( block['height'], blockHarvesterAddress, block['hash'])) # first add all accounts for tx in txes: feesTotal += self.calculateFee(tx) self.addAllAccounts(tx) # commit block and accounts block['fees'] = feesTotal block['tx_count'] = len(txes) dbBlock = self.db.findBlock(block['height']) if dbBlock == None: blockId = self.db.addBlock(block) self.db.commit() else: blockId = dbBlock[0] print "BLOCK ID:", blockId # fix fields and cache delegation info for tx in txes: self.addTxSepcifics(block, tx) # add txes to db self.db.processTxes(block, txes) self.processInouts(block, txes) self.db.commit()
def processBlock(self, block): blockHarvesterAddress = pk2address(block['signer']) block['timestamp_unix'] = self._calc_unix(block['timeStamp']) block['timestamp'] = self._calc_timestamp(block['timestamp_unix']) block['timestamp_nem'] = block['timeStamp'] del block['timeStamp'] sid = self.accounts.addByPublic(block['signer']) block['signer_id'] = sid feesTotal = 0 txes = block["transactions"] del block['transactions'] success("processing block[{}] : {} : {}".format(block['height'], blockHarvesterAddress, block['hash'])) # first add all accounts for tx in txes: feesTotal += self.calculateFee(tx); self.addAllAccounts(tx) # commit block and accounts block['fees'] = feesTotal block['tx_count'] = len(txes) dbBlock = self.db.findBlock(block['height']) if dbBlock == None: blockId = self.db.addBlock(block) self.db.commit() else: blockId = dbBlock[0] print "BLOCK ID:", blockId # fix fields and cache delegation info for tx in txes: self.addTxSepcifics(block, tx) # add txes to db self.db.processTxes(block, txes) self.processInouts(block, txes) self.db.commit()
def processNemFlow(self, tx): txtype = tx['type'] # transfer transaction if txtype == 257: self.nemSub(pk2address(tx['signer']), tx['fee']); self.nemSub(pk2address(tx['signer']), tx['amount']); self.nemAdd(tx['recipient'], tx['amount']) # importance transfer elif txtype == 2049: self.nemSub(pk2address(tx['signer']), tx['fee']); # aggregate elif txtype == 4097: self.nemSub(pk2address(tx['signer']), tx['fee']); # sig - won't happen elif txtype == 4098: pass # MT elif txtype == 4100: # charge multisig account self.nemSub(pk2address(tx['otherTrans']['signer']), tx['fee']); for sig in tx['signatures']: self.nemSub(pk2address(tx['otherTrans']['signer']), sig['fee']); self.processNemFlow(tx['otherTrans'])
def processNemFlow(self, tx): txtype = tx['type'] # transfer transaction if txtype == 257: self.nemSub(pk2address(tx['signer']), tx['fee']) self.nemSub(pk2address(tx['signer']), tx['amount']) self.nemAdd(tx['recipient'], tx['amount']) # importance transfer elif txtype == 2049: self.nemSub(pk2address(tx['signer']), tx['fee']) # aggregate elif txtype == 4097: self.nemSub(pk2address(tx['signer']), tx['fee']) # sig - won't happen elif txtype == 4098: pass # MT elif txtype == 4100: # charge multisig account self.nemSub(pk2address(tx['otherTrans']['signer']), tx['fee']) for sig in tx['signatures']: self.nemSub(pk2address(tx['otherTrans']['signer']), sig['fee']) self.processNemFlow(tx['otherTrans'])
def addAccountTx(self, pk, tx): address=pk2address(pk) self._addAccountTx(address, tx)
def processBlock(self, blockData): block = blockData["block"] blockHarvesterAddress = pk2address(block['signer']) print "block height:", block['height'], blockHarvesterAddress, block['hash'] = blockData['hash'] if len(self.redis_client.zrangebyscore('blocks', block['height'], block['height'])) >= 1: print int(json.loads(zlib.decompress(self.redis_client.zrangebyscore('blocks', block['height'], block['height'])[0]))['height']) self.lastHeight = block['height'] return print print "processing block height:", block['height'], blockHarvesterAddress #if self.seen_blocks >= block['height']: # return #else: # self.seen_blocks = block['height'] block['timestamp_unix'] = self._calc_unix(block['timeStamp']) block['timestamp'] = self._calc_timestamp(block['timestamp_unix']) fees_total = 0 txes = blockData["txes"] block['txes'] = [] for txData in txes: if not ('tx' in txData): tx = txData txData = {} txData['tx'] = tx txData['hash'] = tx['signature'][0:64] tx = txData['tx'] tx['hash'] = txData['hash'] timestamps_unix = self._calc_unix(tx['timeStamp']) tx['timestamp'] = self._calc_timestamp(timestamps_unix) tx['block'] = block['height'] fees_total += self.calculateFee(tx); #save tx in redis self.redis_client.set(txData['hash'], tornado.escape.json_encode(tx)) self.redis_client.zadd('tx', timestamps_unix, tornado.escape.json_encode(tx)) self.redis_client.publish('tx_channel', tornado.escape.json_encode(tx)) self.processTransaction(tx) block['txes'].append(tx) #save blocks in redis self.redis_client.zadd('blocks', block['height'], zlib.compress(tornado.escape.json_encode(block), 9)) print "after add", len(self.redis_client.zrangebyscore('blocks', block['height'], block['height'])) self.redis_client.set(blockData['hash'], tornado.escape.json_encode(block)) self.redis_client.publish('block_channel', tornado.escape.json_encode(block)) print block['height'], block['timestamp_unix'] self.redis_client.zincrby('timestamps', block['height'], block['timestamp_unix']) self.redis_client.zincrby('harvesters', blockHarvesterAddress, 1.0) self.redis_client.zincrby('fees_earned', blockHarvesterAddress, fees_total)
def addAccountTx(self, pk, tx): address = pk2address(pk) self._addAccountTx(address, tx)
def processBlock(self, blockData): block = blockData["block"] blockHarvesterAddress = pk2address(block['signer']) print "block height:", block['height'], blockHarvesterAddress, block['hash'] = blockData['hash'] if len( self.redis_client.zrangebyscore('blocks', block['height'], block['height'])) >= 1: print int( json.loads( zlib.decompress( self.redis_client.zrangebyscore( 'blocks', block['height'], block['height'])[0]))['height']) self.lastHeight = block['height'] return print print "processing block height:", block[ 'height'], blockHarvesterAddress #if self.seen_blocks >= block['height']: # return #else: # self.seen_blocks = block['height'] block['timestamp_unix'] = self._calc_unix(block['timeStamp']) block['timestamp'] = self._calc_timestamp(block['timestamp_unix']) fees_total = 0 txes = blockData["txes"] block['txes'] = [] for txData in txes: if not ('tx' in txData): tx = txData txData = {} txData['tx'] = tx txData['hash'] = tx['signature'][0:64] tx = txData['tx'] tx['hash'] = txData['hash'] timestamps_unix = self._calc_unix(tx['timeStamp']) tx['timestamp'] = self._calc_timestamp(timestamps_unix) tx['block'] = block['height'] fees_total += self.calculateFee(tx) #save tx in redis self.redis_client.set(txData['hash'], tornado.escape.json_encode(tx)) self.redis_client.zadd('tx', timestamps_unix, tornado.escape.json_encode(tx)) self.redis_client.publish('tx_channel', tornado.escape.json_encode(tx)) self.processTransaction(tx) block['txes'].append(tx) #save blocks in redis self.redis_client.zadd( 'blocks', block['height'], zlib.compress(tornado.escape.json_encode(block), 9)) print "after add", len( self.redis_client.zrangebyscore('blocks', block['height'], block['height'])) self.redis_client.set(blockData['hash'], tornado.escape.json_encode(block)) self.redis_client.publish('block_channel', tornado.escape.json_encode(block)) print block['height'], block['timestamp_unix'] self.redis_client.zincrby('timestamps', block['height'], block['timestamp_unix']) self.redis_client.zincrby('harvesters', blockHarvesterAddress, 1.0) self.redis_client.zincrby('fees_earned', blockHarvesterAddress, fees_total)