from eth_account import Account
import json
import os
import sys
sys.path.insert(0, "J:/Softwareprojekte/Polytrader/venv/Lib/site-packages")

from py_order_utils.builders.base_builder import BaseBuilder
from py_order_utils.model.order import OrderData
from py_order_utils.signer import Signer

order_json = '''{"salt":17747015785747,"maker":"0x628914cf1e96a9d1ab8f0489a9f64be5633bac41","signer":"0x883fe952a23bb68aab8832343d4bedde759b40ea","taker":"0x0000000000000000000000000000000000000000","tokenId":"54119275359569982132308633107899675342776540894581625713762792947175003762644","makerAmount":"999180","takerAmount":"3660000","expiration":"0","nonce":"0","feeRateBps":"0","side":"BUY","signatureType":0}'''

data = json.loads(order_json)
data["side"] = 0 if data["side"] == "BUY" else 1

priv_key = "0x" + "1"*64
signer = Signer(priv_key)

builder = BaseBuilder('0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E', 137, signer, lambda: 1)

from py_order_utils.model.order import Order
order = Order(
    salt=int(data["salt"]),
    maker=data["maker"],
    signer=data["signer"],
    taker=data["taker"],
    tokenId=int(data["tokenId"]),
    makerAmount=int(data["makerAmount"]),
    takerAmount=int(data["takerAmount"]),
    expiration=int(data["expiration"]),
    nonce=int(data["nonce"]),
    feeRateBps=int(data["feeRateBps"]),
    side=int(data["side"]),
    signatureType=int(data["signatureType"])
)

struct_hash = builder._create_struct_hash(order)
print("PYTHON_STRUCT_HASH|" + struct_hash)
print("PYTHON_SIG|" + signer.sign(struct_hash))
