コード例 #1
0
ファイル: account.py プロジェクト: kmn/bc4py
def read_txhash2log(txhash, cur):
    d = cur.execute(
        """
        SELECT `type`,`user`,`coin_id`,`amount`,`time` FROM `log` WHERE `hash`=?
    """, (txhash, )).fetchall()
    if len(d) == 0:
        return None
    movement = Accounting()
    _type = _time = None
    for _type, user, coin_id, amount, _time in d:
        movement.add_coins(user, coin_id, amount)
    return MoveLog(txhash, _type, movement, _time, False)
コード例 #2
0
ファイル: builder.py プロジェクト: kmn/bc4py
 def affect_new_tx(self, tx, outer_cur=None):
     with closing(create_db(V.DB_ACCOUNT_PATH)) as db:
         cur = outer_cur or db.cursor()
         movement = Accounting()
         # send_from_applyで登録済み
         if tx.hash in self.memory_movement:
             return
         # memory_movementに追加
         for txhash, txindex in tx.inputs:
             input_tx = tx_builder.get_tx(txhash)
             address, coin_id, amount = input_tx.outputs[txindex]
             user = read_address2user(address, cur)
             if user is not None:
                 movement.add_coins(user, coin_id, -1 * amount)
         for address, coin_id, amount in tx.outputs:
             user = read_address2user(address, cur)
             if user is not None:
                 movement.add_coins(user, coin_id, amount)
         # check
         if len(movement) == 0:
             return  # 無関係である
         move_log = MoveLog(tx.hash, tx.type, movement, tx.time, True, tx)
         self.memory_movement[tx.hash] = move_log
         logging.debug("Affect account new tx. {}".format(tx))