def post(self, args): orderbook = self.trustlines.orderbook order = Order( exchange_address=args["exchangeContractAddress"], maker_address=args["maker"], taker_address=args["taker"], maker_token=args["makerTokenAddress"], taker_token=args["takerTokenAddress"], fee_recipient=args["feeRecipient"], maker_token_amount=args["makerTokenAmount"], taker_token_amount=args["takerTokenAmount"], maker_fee=args["makerFee"], taker_fee=args["takerFee"], expiration_timestamp_in_sec=args["expirationUnixTimestampSec"], salt=args["salt"], v=args["ecSignature"]["v"], r=args["ecSignature"]["r"], s=args["ecSignature"]["s"], ) if not order.validate_signature(): abort(422, message="Invalid ECDSA") if not orderbook.validate_exchange_address(order): abort(422, message="Invalid Exchange Address") if not orderbook.validate_timestamp(order): abort(422, message="Order already timed out") try: self.trustlines.orderbook.add_order(order) except OrderInvalidException: abort(422, message="Invalid Order")
def order(): return Order( "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9", "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9", "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9", "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9", "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9", "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9", 100, 100, 100, 100, 10000, 1000, 28, bytes([12]), bytes([20]), )
def invalid_signature_order(addresses): A, B, C, D = addresses return Order( exchange_address=A, maker_address=B, taker_address=NULL_ADDRESS, maker_token=C, taker_token=D, fee_recipient=NULL_ADDRESS, maker_token_amount=100, taker_token_amount=200, maker_fee=0, taker_fee=0, expiration_timestamp_in_sec=123, salt=123, v=27, r=(18).to_bytes(32, byteorder="big"), s=(2748).to_bytes(32, byteorder="big"), )
def get_unavailable_amount(self, order: Order) -> int: return self._proxy.functions.getUnavailableTakerTokenAmount( order.hash()).call()
def get_cancelled_amount(self, order: Order) -> int: return self._proxy.functions.cancelled(order.hash()).call()
def validate_filled_amount(self, order: Order) -> bool: return (self._proxy.functions.getUnavailableTakerTokenAmount( order.hash()).call() < order.taker_token_amount)
def test_get_order(order: Order, orderbook_db: OrderBookDB): orderbook_db.add_order(order) assert orderbook_db.get_order_by_hash(order.hash()) == order
def test_invalid_address(invalid_exchange_order: Order): assert not invalid_exchange_order.validate_addresses() assert not invalid_exchange_order.validate()
def test_invalid_signature(invalid_signature_order: Order): assert not invalid_signature_order.validate_signature() assert not invalid_signature_order.validate()
def test_expired(valid_order: Order): assert not valid_order.is_expired(0) assert valid_order.is_expired(1517161471000)
def test_valid_order(valid_order: Order): assert valid_order.validate_addresses() assert valid_order.validate_signature() assert valid_order.validate()