Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
def order():
    return Order(
        "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9",
        "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9",
        "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9",
        "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9",
        "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9",
        "0x55bdaAf9f941A5BB3EacC8D876eeFf90b90ddac9",
        100,
        100,
        100,
        100,
        10000,
        1000,
        28,
        bytes([12]),
        bytes([20]),
    )
Ejemplo n.º 3
0
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"),
    )
Ejemplo n.º 4
0
 def get_unavailable_amount(self, order: Order) -> int:
     return self._proxy.functions.getUnavailableTakerTokenAmount(
         order.hash()).call()
Ejemplo n.º 5
0
 def get_cancelled_amount(self, order: Order) -> int:
     return self._proxy.functions.cancelled(order.hash()).call()
Ejemplo n.º 6
0
 def validate_filled_amount(self, order: Order) -> bool:
     return (self._proxy.functions.getUnavailableTakerTokenAmount(
         order.hash()).call() < order.taker_token_amount)
Ejemplo n.º 7
0
def test_get_order(order: Order, orderbook_db: OrderBookDB):

    orderbook_db.add_order(order)

    assert orderbook_db.get_order_by_hash(order.hash()) == order
Ejemplo n.º 8
0
def test_invalid_address(invalid_exchange_order: Order):
    assert not invalid_exchange_order.validate_addresses()
    assert not invalid_exchange_order.validate()
Ejemplo n.º 9
0
def test_invalid_signature(invalid_signature_order: Order):
    assert not invalid_signature_order.validate_signature()
    assert not invalid_signature_order.validate()
Ejemplo n.º 10
0
def test_expired(valid_order: Order):
    assert not valid_order.is_expired(0)
    assert valid_order.is_expired(1517161471000)
Ejemplo n.º 11
0
def test_valid_order(valid_order: Order):
    assert valid_order.validate_addresses()
    assert valid_order.validate_signature()
    assert valid_order.validate()