コード例 #1
0
ファイル: structures.py プロジェクト: rotki/rotki
 def identifier(self) -> str:
     """Generate an unique identifier based on information from the base entry that is later
     hashed. It follows the pattern that we use in other places and has similar problems.
     """
     location_label = self.location_label if self.location_label is not None else ''
     event_subtype = self.event_subtype if self.event_subtype is not None else ''
     hashable = (str(self.location) + str(self.timestamp) +
                 self.event_identifier + str(self.sequence_index) +
                 location_label + str(self.asset_balance) +
                 str(self.event_type) + str(event_subtype))
     return sha3(hashable.encode()).hex()
コード例 #2
0
def private_keys(number_of_accounts, privatekey_seed):
    """ Private keys for each raiden node. """

    # Note: The fixtures depend on the order of the private keys
    result = [
        sha3(privatekey_seed.format(position).encode())
        for position in range(number_of_accounts)
    ]

    # this must not happen, otherwise the keys and addresses will be equal!
    assert len(set(result)) == number_of_accounts, '`privatekey_seed` generate repeated keys'

    return result
コード例 #3
0
def v7_generate_asset_movement_id(
    location: Location,
    category: AssetMovementCategory,
    time: Union[str, int],
    asset: str,
    fee_asset: str,
    link: str,
) -> str:
    """We copy the identifier() property of an asset movement at v7

    This is done in case the function ever changes in the future.
    """
    source_str = (str(location) + str(category) + str(time) + asset +
                  fee_asset + link)
    return sha3(source_str.encode()).hex()
コード例 #4
0
ファイル: v6_v7.py プロジェクト: zhiiker/rotki
def v6_generate_trade_id(
    location: Location,
    time: Union[str, int],
    trade_type: TradeType,
    pair: str,
    amount: str,
    rate: str,
    link: str,
) -> str:
    """We copy the identifier() property of a trade at v6

    This is done in case the function ever changes in the future.
    """
    source_str = (str(location) + str(time) + str(trade_type) + pair + amount +
                  rate + link)
    return sha3(source_str.encode()).hex()
コード例 #5
0
def _upgrade_trades_table(db: 'DBHandler') -> None:
    cursor = db.conn.cursor()
    # This is the data trades table at v5
    query = cursor.execute(
        """SELECT time, location, pair, type, amount, rate, fee, fee_currency,
        link, notes FROM trades;""", )
    trade_tuples = []
    for result in query:
        # This is the logic of trade addition in v6 of the DB
        time = result[0]
        pair = result[2]
        old_trade_type = result[3]
        # hand deserialize trade type from DB enum since this code is going to stay
        # here even if deserialize_trade_type_from_db() changes
        if old_trade_type == 'buy':
            trade_type = 'A'
        elif old_trade_type == 'sell':
            trade_type = 'B'
        else:
            raise DBUpgradeError(
                f'Unexpected trade_type "{trade_type}" found while upgrading '
                f'from DB version 5 to 6', )

        trade_id = sha3(('external' + str(time) + str(old_trade_type) +
                         pair).encode()).hex()
        trade_tuples.append((
            trade_id,
            time,
            'A',  # Symbolizes external in the location enum
            pair,
            trade_type,
            result[4],
            result[5],
            result[6],
            result[7],
            result[8],
            result[9],
        ))

    # We got all the external trades data. Now delete the old table and create
    # the new one
    cursor.execute('DROP TABLE trades;')
    db.conn.commit()
    # This is the scheme of the trades table at v6 from db/utils.py
    cursor.execute("""
    CREATE TABLE IF NOT EXISTS trades (
    id TEXT PRIMARY KEY,
    time INTEGER,
    location VARCHAR[24],
    pair VARCHAR[24],
    type CHAR(1) NOT NULL DEFAULT ('B') REFERENCES trade_type(type),
    amount TEXT,
    rate TEXT,
    fee TEXT,
    fee_currency VARCHAR[10],
    link TEXT,
    notes TEXT
    );""")
    db.conn.commit()

    # and finally move the data to the new table
    cursor.executemany(
        'INSERT INTO trades('
        '  id, '
        '  time,'
        '  location,'
        '  pair,'
        '  type,'
        '  amount,'
        '  rate,'
        '  fee,'
        '  fee_currency,'
        '  link,'
        '  notes)'
        'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
        trade_tuples,
    )
    db.conn.commit()
コード例 #6
0
def hash_id(hashable: str) -> TradeID:
    id_bytes = sha3(hashable.encode())
    return TradeID(id_bytes.hex())