Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
plebhash opened this issue Sep 21, 2024 · 1 comment
Closed

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

plebhash opened this issue Sep 21, 2024 · 1 comment

Comments

@plebhash
Copy link
Member

plebhash commented Sep 21, 2024

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

  • an event to be mined
  • the desired PoW difficulty
  • the zap paying for the PoW
$ 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:

io.add_method("mine", move |params: Params| async move {
let parsed: Result<MineRpc, _> = serde_json::from_value(params.parse()?)
.map_err(|_| Error::invalid_params("Invalid params"));
match parsed {
Ok(MineRpc {
event,
difficulty,
zap,
}) => {
if verify_zap(zap, args.pow_price_factor, difficulty).await {
// mine

currently, verify_zap has a dummy placeholder implementation:

pub async fn verify_zap(
_zap: String,
pow_price_factor: f64,
difficulty: u32,
) -> Result<(), ZapError> {
let _pow_price = pow_price(pow_price_factor, difficulty);
// todo: check zap is valid
// if !valid_zap {
// return Err(ZapError::InvalidZap);
// }
// todo: read zap value
// if (zap_value as f64) < pow_price {
// return Err(ZapError::InsufficientZap);
// }
Ok(())
}

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

  • zap is valid
  • zap contains more sats than pow_price

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

@plebhash plebhash added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Sep 21, 2024
@plebhash
Copy link
Member Author

@plebhash plebhash closed this as completed Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant