plebemineira / notemine_hw

nostr note miner written in rust, aiming at hardware acceleration
GNU General Public License v3.0
3 stars 0 forks source link

use `nostr-zapper` crate to implement `sell::verify_zap` #3

Closed plebhash closed 1 month ago

plebhash commented 1 month ago

the mine JSON-RPC method allows a buyer to submit:

$ curl -s -X POST \
     -H "Content-Type: application/json" \
     -d '{
           "jsonrpc": "2.0",
           "method": "mine",
           "params": {
             "event": {
               "pubkey": "98590c0f4959a49f3524b7c009c190798935eeaa50b1232ba74195b419eaa2f2",
               "created_at": 1668680774,
               "kind": 1,
               "tags": [],
               "content": "hello world"
             },
             "difficulty": 15,
             "zap": "f481897ee877321783bb76133622b3cc344d691bb79cd6be88f44e819c3b2306"
           },
           "id": 1
         }' \
     http://localhost:1337

it is assumed that the buyer has previously called the quote JSON-RPC method, so they know how many sats they should send in the zap.

but maybe they send an invalid zap, or the zap does not have enough sats.

so the JSON-RPC handler needs to validate the zap before it starts mining: https://github.com/plebemineira/notemine_hw/blob/ade25cbb4b75fb8d05e56a10c7a211dae454191c/src/lib/service.rs#L101-L111

currently, verify_zap has a dummy placeholder implementation: https://github.com/plebemineira/notemine_hw/blob/759177453006f8b9a0ae6c18c51c342ebc491dfa/src/lib/sell.rs#L7-L25

this implementation should leverage nostr-zapper crate to actually verify if:

only if those two verifications are succesful, should we start mining

plebhash commented 1 month ago

https://nostr.how/en/zaps