-
Notifications
You must be signed in to change notification settings - Fork 139
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
LSP error with certain tuple #1382
Comments
Ah, I figured out the problem - it's due to the length of the lists. I'll update my description. |
You can use async function findStxBootstrapAmount() {
const simnet = await initSimnet(manifestFile);
let boot: any = null;
try {
boot = simnet.getContractAST('boot');
}
catch (error) {
throw new Error(`Failed to read boot contract`);
}
return findStxBootstrapAmountAtom(boot.expressions);
}
function findStxBootstrapAmountAtom(items: any[]): bigint | null {
for (let i = 0; i < items.length; ++i) {
const item = items[i];
if (item.expr?.List?.length === 3) {
let [a, b, c] = item.expr.List;
if (a.expr?.Atom === "define-constant" && b.expr?.Atom === "stx-bootstrap-amount")
return c.expr.LiteralValue.UInt;
}
else if (item.expr?.List) {
const result: any = findStxBootstrapAmountAtom(item.expr.List);
if (result !== null)
return result;
}
}
return null;
} |
Hey @hstove (define-data-var stackerdb-signer-slots-0 (list 2570 { signer: principal, num-slots: uint }) (list))
(define-data-var stackerdb-signer-slots-1 (list 2570 { signer: principal, num-slots: uint }) (list))
{
stackerdb-signer-slots-0: (var-get stackerdb-signer-slots-0),
stackerdb-signer-slots-1: (var-get stackerdb-signer-slots-1),
} What do you think about @MarvinJanssen solution? |
@MarvinJanssen yeah that works for the majority of cases, but not with dynamic / code based things, like: (define-constant FIVE_STX (u1 * u1000000))
(define-data-var fee-rate uint (contract-call? .fee get-rate) u1) There are definitely workarounds, and I think this also points to a better solution of not using a single tuple for all variables. It could be the same approach but with a single read-only fn to get each variable individually, etc. |
@hstove |
Ah, true! I wrote this code before |
Closing this - maybe the LSP error should be better, but there isn't a bug around whether this should compile. |
Thanks @hstove and @MarvinJanssen |
I didn't know about
Right. I guess you could turn the AST back into Clarity code and evaluate it if you detect that it is not a simple atomic value, but that sounds a little tricky. |
As part of Clarigen I have a step where I basically evaluate all constants and variables to get their default values. The way I do this is by re-deploying the contract and returning a tuple with the key/value pairs.
I've been using this with some of the boot contracts for Nakamoto, and I ran into a peculiar issue with the
signers-voting.clar
contract. The LSP highlights the bottom tuple (created programmatically by Clarigen) and shows the errorinvalid tuple syntax, expecting list of pair
. I also get an error when trying to deploy this contract usingclarinet-sdk
.EDIT: the error stems from the length of the lists. I've found that if the lists are both of length 2569, there is no error. Any higher will cause an error.
It seems to relate to the two bottom
stackerdb-signer-slots-N
lines. If I comment either of them out, the error goes away. If I rename one or both of them, it the error stays. If I rename one or both of them (including the variable name), the errors stays. If I wrap that tuple inside a function, the error stays. It doesn't appear that there are any funky characters in this, but I might be wrong. I've tried to debug if I'm missing something obvious here in the generated code, but I haven't found anything.To reproduce: in any Clarinet project, add a contract to your manifest, and paste in this code:
The text was updated successfully, but these errors were encountered: