refactor: stalls use sign_and_send_to_nostr
This commit is contained in:
parent
54978c847f
commit
1622403cd1
2 changed files with 11 additions and 25 deletions
6
crud.py
6
crud.py
|
|
@ -222,7 +222,7 @@ async def update_product(user_id: str, product: Product) -> Product:
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f"""
|
f"""
|
||||||
UPDATE nostrmarket.products set name = ?, description = ?, images = ?, price = ?, quantity = ?, category_list = ?, meta = ?
|
UPDATE nostrmarket.products set name = ?, images = ?, price = ?, quantity = ?, category_list = ?, meta = ?
|
||||||
WHERE user_id = ? AND id = ?
|
WHERE user_id = ? AND id = ?
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
|
@ -230,10 +230,10 @@ async def update_product(user_id: str, product: Product) -> Product:
|
||||||
product.image,
|
product.image,
|
||||||
product.price,
|
product.price,
|
||||||
product.quantity,
|
product.quantity,
|
||||||
|
json.dumps(product.categories),
|
||||||
|
json.dumps(product.config.dict()),
|
||||||
user_id,
|
user_id,
|
||||||
product.id,
|
product.id,
|
||||||
json.dumps(product.categories),
|
|
||||||
json.dumps(product.config),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
updated_product = await get_product(user_id, product.id)
|
updated_product = await get_product(user_id, product.id)
|
||||||
|
|
|
||||||
30
views_api.py
30
views_api.py
|
|
@ -172,15 +172,9 @@ async def api_create_stall(
|
||||||
try:
|
try:
|
||||||
data.validate_stall()
|
data.validate_stall()
|
||||||
|
|
||||||
print("### stall", json.dumps(data.dict()))
|
|
||||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
|
||||||
assert merchant, "Cannot find merchat for stall"
|
|
||||||
|
|
||||||
stall = await create_stall(wallet.wallet.user, data=data)
|
stall = await create_stall(wallet.wallet.user, data=data)
|
||||||
|
|
||||||
event = stall.to_nostr_event(merchant.public_key)
|
event = await sign_and_send_to_nostr(wallet.wallet.user, stall)
|
||||||
event.sig = merchant.sign_hash(bytes.fromhex(event.id))
|
|
||||||
await publish_nostr_event(event)
|
|
||||||
|
|
||||||
stall.config.event_id = event.id
|
stall.config.event_id = event.id
|
||||||
await update_stall(wallet.wallet.user, stall)
|
await update_stall(wallet.wallet.user, stall)
|
||||||
|
|
@ -207,18 +201,13 @@ async def api_update_stall(
|
||||||
try:
|
try:
|
||||||
data.validate_stall()
|
data.validate_stall()
|
||||||
|
|
||||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
|
||||||
assert merchant, "Cannot find merchat for stall"
|
|
||||||
|
|
||||||
event = data.to_nostr_event(merchant.public_key)
|
|
||||||
event.sig = merchant.sign_hash(bytes.fromhex(event.id))
|
|
||||||
|
|
||||||
data.config.event_id = event.id
|
|
||||||
# data.config.event_created_at =
|
|
||||||
stall = await update_stall(wallet.wallet.user, data)
|
stall = await update_stall(wallet.wallet.user, data)
|
||||||
assert stall, "Cannot update stall"
|
assert stall, "Cannot update stall"
|
||||||
|
|
||||||
await publish_nostr_event(event)
|
event = await sign_and_send_to_nostr(wallet.wallet.user, stall)
|
||||||
|
|
||||||
|
stall.config.event_id = event.id
|
||||||
|
await update_stall(wallet.wallet.user, stall)
|
||||||
|
|
||||||
return stall
|
return stall
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
|
|
@ -297,15 +286,12 @@ async def api_delete_stall(
|
||||||
detail="Stall does not exist.",
|
detail="Stall does not exist.",
|
||||||
)
|
)
|
||||||
|
|
||||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
|
||||||
assert merchant, "Cannot find merchat for stall"
|
|
||||||
|
|
||||||
await delete_stall(wallet.wallet.user, stall_id)
|
await delete_stall(wallet.wallet.user, stall_id)
|
||||||
|
|
||||||
delete_event = stall.to_nostr_delete_event(merchant.public_key)
|
event = await sign_and_send_to_nostr(wallet.wallet.user, stall, True)
|
||||||
delete_event.sig = merchant.sign_hash(bytes.fromhex(delete_event.id))
|
|
||||||
|
|
||||||
await publish_nostr_event(delete_event)
|
stall.config.event_id = event.id
|
||||||
|
await update_stall(wallet.wallet.user, stall)
|
||||||
|
|
||||||
except HTTPException as ex:
|
except HTTPException as ex:
|
||||||
raise ex
|
raise ex
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue