cic-eth: Revert number as hex in tx-cache
This commit is contained in:
		
							parent
							
								
									fa83c50ab5
								
							
						
					
					
						commit
						500f0c3a41
					
				@ -27,8 +27,8 @@ def upgrade():
 | 
			
		||||
            sa.Column('destination_token_address', sa.String(42), nullable=False),
 | 
			
		||||
            sa.Column('sender', sa.String(42), nullable=False),
 | 
			
		||||
            sa.Column('recipient', sa.String(42), nullable=False),
 | 
			
		||||
            sa.Column('from_value', sa.String(), nullable=False),
 | 
			
		||||
            sa.Column('to_value', sa.String(), nullable=True),
 | 
			
		||||
            sa.Column('from_value', sa.NUMERIC(), nullable=False),
 | 
			
		||||
            sa.Column('to_value', sa.NUMERIC(), nullable=True),
 | 
			
		||||
            sa.Column('block_number', sa.BIGINT(), nullable=True),
 | 
			
		||||
            sa.Column('tx_index', sa.Integer, nullable=True),
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
@ -19,7 +19,6 @@ def upgrade():
 | 
			
		||||
    op.create_table(
 | 
			
		||||
            'tx_cache',
 | 
			
		||||
            sa.Column('id', sa.Integer, primary_key=True),
 | 
			
		||||
#            sa.Column('tx_id', sa.Integer, sa.ForeignKey('tx.id'), nullable=True),
 | 
			
		||||
            sa.Column('otx_id', sa.Integer, sa.ForeignKey('otx.id'), nullable=True),
 | 
			
		||||
            sa.Column('date_created', sa.DateTime, nullable=False),
 | 
			
		||||
            sa.Column('date_updated', sa.DateTime, nullable=False),
 | 
			
		||||
@ -27,8 +26,8 @@ def upgrade():
 | 
			
		||||
            sa.Column('destination_token_address', sa.String(42), nullable=False),
 | 
			
		||||
            sa.Column('sender', sa.String(42), nullable=False),
 | 
			
		||||
            sa.Column('recipient', sa.String(42), nullable=False),
 | 
			
		||||
            sa.Column('from_value', sa.BIGINT(), nullable=False),
 | 
			
		||||
            sa.Column('to_value', sa.BIGINT(), nullable=True),
 | 
			
		||||
            sa.Column('from_value', sa.NUMERIC(), nullable=False),
 | 
			
		||||
            sa.Column('to_value', sa.NUMERIC(), nullable=True),
 | 
			
		||||
            sa.Column('block_number', sa.BIGINT(), nullable=True),
 | 
			
		||||
            sa.Column('tx_index', sa.Integer, nullable=True),
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@
 | 
			
		||||
import datetime
 | 
			
		||||
 | 
			
		||||
# third-party imports
 | 
			
		||||
from sqlalchemy import Column, String, Integer, DateTime, Enum, ForeignKey, Boolean
 | 
			
		||||
from sqlalchemy import Column, String, Integer, DateTime, Enum, ForeignKey, Boolean, NUMERIC
 | 
			
		||||
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
 | 
			
		||||
#from sqlalchemy.orm import relationship, backref
 | 
			
		||||
#from sqlalchemy.ext.declarative import declarative_base
 | 
			
		||||
@ -55,8 +55,8 @@ class TxCache(SessionBase):
 | 
			
		||||
    destination_token_address = Column(String(42))
 | 
			
		||||
    sender = Column(String(42))
 | 
			
		||||
    recipient = Column(String(42))
 | 
			
		||||
    from_value = Column(String())
 | 
			
		||||
    to_value = Column(String())
 | 
			
		||||
    from_value = Column(NUMERIC())
 | 
			
		||||
    to_value = Column(NUMERIC())
 | 
			
		||||
    block_number = Column(Integer())
 | 
			
		||||
    tx_index = Column(Integer())
 | 
			
		||||
    date_created = Column(DateTime, default=datetime.datetime.utcnow)
 | 
			
		||||
@ -64,16 +64,6 @@ class TxCache(SessionBase):
 | 
			
		||||
    date_checked = Column(DateTime, default=datetime.datetime.utcnow)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def values(self):
 | 
			
		||||
        from_value_hex = bytes.fromhex(self.from_value)
 | 
			
		||||
        from_value = int.from_bytes(from_value_hex, 'big')
 | 
			
		||||
 | 
			
		||||
        to_value_hex = bytes.fromhex(self.to_value)
 | 
			
		||||
        to_value = int.from_bytes(to_value_hex, 'big')
 | 
			
		||||
 | 
			
		||||
        return (from_value, to_value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def check(self):
 | 
			
		||||
        """Update the "checked" timestamp to current time.
 | 
			
		||||
 | 
			
		||||
@ -116,15 +106,14 @@ class TxCache(SessionBase):
 | 
			
		||||
        if otx == None:
 | 
			
		||||
            raise NotLocalTxError('new {}'.format(tx_hash_new))
 | 
			
		||||
 | 
			
		||||
        values = txc.values()
 | 
			
		||||
        txc_new = TxCache(
 | 
			
		||||
                otx.tx_hash,
 | 
			
		||||
                txc.sender,
 | 
			
		||||
                txc.recipient,
 | 
			
		||||
                txc.source_token_address,
 | 
			
		||||
                txc.destination_token_address,
 | 
			
		||||
                values[0],
 | 
			
		||||
                values[1],
 | 
			
		||||
                int(txc.from_value),
 | 
			
		||||
                int(txc.to_value),
 | 
			
		||||
                )
 | 
			
		||||
        localsession.add(txc_new)
 | 
			
		||||
        localsession.commit()
 | 
			
		||||
@ -141,17 +130,12 @@ class TxCache(SessionBase):
 | 
			
		||||
            raise FileNotFoundError('outgoing transaction record unknown {} (add a Tx first)'.format(tx_hash))
 | 
			
		||||
        self.otx_id = tx.id
 | 
			
		||||
 | 
			
		||||
#        if tx == None:
 | 
			
		||||
#            session.close()
 | 
			
		||||
#            raise ValueError('tx hash {} (outgoing: {}) not found'.format(tx_hash, outgoing))
 | 
			
		||||
#        session.close()
 | 
			
		||||
 | 
			
		||||
        self.sender = sender
 | 
			
		||||
        self.recipient = recipient
 | 
			
		||||
        self.source_token_address = source_token_address
 | 
			
		||||
        self.destination_token_address = destination_token_address
 | 
			
		||||
        self.from_value = num_serialize(from_value).hex()
 | 
			
		||||
        self.to_value = num_serialize(to_value).hex()
 | 
			
		||||
        self.from_value = from_value
 | 
			
		||||
        self.to_value = to_value
 | 
			
		||||
        self.block_number = block_number
 | 
			
		||||
        self.tx_index = tx_index
 | 
			
		||||
        # not automatically set in sqlite, it seems:
 | 
			
		||||
 | 
			
		||||
@ -378,7 +378,6 @@ def get_tx_cache(tx_hash):
 | 
			
		||||
 | 
			
		||||
    session.close()
 | 
			
		||||
 | 
			
		||||
    values = txc.values()
 | 
			
		||||
    tx = {
 | 
			
		||||
        'tx_hash': otx.tx_hash,
 | 
			
		||||
        'signed_tx': otx.signed_tx,
 | 
			
		||||
@ -389,8 +388,8 @@ def get_tx_cache(tx_hash):
 | 
			
		||||
        'destination_token': txc.destination_token_address,
 | 
			
		||||
        'sender': txc.sender,
 | 
			
		||||
        'recipient': txc.recipient,
 | 
			
		||||
        'from_value': values[0],
 | 
			
		||||
        'to_value': values[1],
 | 
			
		||||
        'from_value': int(txc.from_value),
 | 
			
		||||
        'to_value': int(txc.to_value),
 | 
			
		||||
        'date_created': txc.date_created,
 | 
			
		||||
        'date_updated': txc.date_updated,
 | 
			
		||||
        'date_checked': txc.date_checked,
 | 
			
		||||
 | 
			
		||||
@ -59,9 +59,8 @@ def test_set(
 | 
			
		||||
        assert (tx_stored.recipient == tx_def['to'])
 | 
			
		||||
        assert (tx_stored.source_token_address == bogus_from_token)
 | 
			
		||||
        assert (tx_stored.destination_token_address == zero_address)
 | 
			
		||||
        assert (tx_stored.from_value == '1b1ae4d6e2ef500000')
 | 
			
		||||
        assert (tx_stored.to_value == '0d8d726b7177a80000')
 | 
			
		||||
        assert (tx_stored.values() == (tx_def['value'], to_value))
 | 
			
		||||
        assert (tx_stored.from_value == tx_def['value'])
 | 
			
		||||
        assert (tx_stored.to_value == to_value)
 | 
			
		||||
        assert (tx_stored.block_number == 666)
 | 
			
		||||
        assert (tx_stored.tx_index == 13)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -126,4 +126,5 @@ def test_queue_cache_convert(
 | 
			
		||||
    assert txc.recipient == init_w3.eth.accounts[0]
 | 
			
		||||
    assert txc.source_token_address == bancor_tokens[0]
 | 
			
		||||
    assert txc.destination_token_address == bancor_tokens[1]
 | 
			
		||||
    assert txc.values() == (amount, amount)
 | 
			
		||||
    assert txc.from_value == amount
 | 
			
		||||
    assert txc.to_value == amount
 | 
			
		||||
 | 
			
		||||
@ -85,4 +85,5 @@ def test_queue_cache_transfer(
 | 
			
		||||
    assert txc.recipient == init_w3.eth.accounts[1]
 | 
			
		||||
    assert txc.source_token_address == bancor_tokens[0]
 | 
			
		||||
    assert txc.destination_token_address == bancor_tokens[0]
 | 
			
		||||
    assert txc.values() == (value, value)
 | 
			
		||||
    assert txc.from_value == value
 | 
			
		||||
    assert txc.to_value == value
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user