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

runes: add a way to set a budget for amount fields? #6287

Closed
niftynei opened this issue May 28, 2023 · 1 comment
Closed

runes: add a way to set a budget for amount fields? #6287

niftynei opened this issue May 28, 2023 · 1 comment

Comments

@niftynei
Copy link
Contributor

Current behavior: Trying to set a budget for a rune (no invoices created over X amount, pay invoices up to X sats) fails as the pnameX restrictions are parsed as strings.

Desired behavior: pnameX where X is "amount_msat" is parsed as an integer (which would allow range assertions).

Relevant code from plugins/commando.c which causes this (L398-L432)

        if (strmap_empty(&cinfo->cached_params)) {
                const jsmntok_t *t;
                size_t i;
                
                if (cinfo->params->type == JSMN_OBJECT) {                   
                        json_for_each_obj(i, t, cinfo->params) {            
                                char *pmemname = tal_fmt(tmpctx,            
                                                         "pname%.*s",       
                                                         t->end - t->start, 
                                                         cinfo->buf + t->start);     
                                size_t off = strlen("pname");
                                /* Remove punctuation! */                   
                                for (size_t n = off; pmemname[n]; n++) {    
                                        if (cispunct(pmemname[n]))          
                                                continue;
                                        pmemname[off++] = pmemname[n];      
                                }               
                                pmemname[off++] = '\0'; 
                                strmap_add(&cinfo->cached_params, pmemname, t+1);    
                        }       
                } else if (cinfo->params->type == JSMN_ARRAY) {
                        json_for_each_arr(i, t, cinfo->params) {            
                                char *pmemname = tal_fmt(tmpctx, "parr%zu", i);              
                                strmap_add(&cinfo->cached_params, pmemname, t);
                        }
                }
        }

        ptok = strmap_get(&cinfo->cached_params, alt->fieldname);
        if (!ptok)
                return rune_alt_single_missing(ctx, alt);

        return rune_alt_single_str(ctx, alt,
                                   cinfo->buf + ptok->start,
                                   ptok->end - ptok->start);

niftynei added a commit to niftynei/lightning that referenced this issue May 28, 2023
This allows us to do restrictions with budgets/ranges.

eg amount_msat<4500

Fixes ElementsProject#6287
@vincenzopalazzo
Copy link
Contributor

Ok the PR is now merged #6295

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

2 participants