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

StorageMap can't be written in static variables #310

Closed
chenzhitong opened this issue Jun 24, 2020 · 3 comments · Fixed by #321
Closed

StorageMap can't be written in static variables #310

chenzhitong opened this issue Jun 24, 2020 · 3 comments · Fixed by #321

Comments

@chenzhitong
Copy link
Member

chenzhitong commented Jun 24, 2020

I found that if StorageMap is written in a global variables, the execution will report an error.
If the StorageMap is written in a variable in the method, it is executed correctly.

[Features(ContractFeatures.HasStorage)]
public class Contract1 : SmartContract
{
    private static readonly StorageMap Data = Storage.CurrentContext.CreateMap("data");

    public static void Put(string message)
    {
        Data.Put(message, Blockchain.GetHeight());
    }

    public static BigInteger Get(string msg)
    {
        return Data.Get(msg)?.ToBigInteger() ?? 0;
    }

    public static void Put2(string message)
    {
        var Data2 = Storage.CurrentContext.CreateMap("data");
        Data2.Put(message, Blockchain.GetHeight());
    }

    public static BigInteger Get2(string msg)
    {
        var Data2 = Storage.CurrentContext.CreateMap("data");
        return Data2.Get(msg)?.ToBigInteger() ?? 0;
    }
}

The put and get methods will fail to execute, but the put2 and get2 methods will execute successfully.

This bug will appear in both Neo2 and Neo3

The picture below is the execution result:

image

StorageMap 如果写在全局变量(静态变量)中,会执行出错,但写在方法里面就能正常执行,从Neo2到现在一直存在的Bug。为此我还补充了文档。但我觉得有坑的话应该先把坑填上,而不是叫所有人都绕过去走。

image

@shargon
Copy link
Member

shargon commented Jun 24, 2020

Could you take a look @lightszero ?

@lightszero
Copy link
Member

I think this is about #237

@ShawnYun
Copy link
Contributor

I will check it, but according to the above mentioned, this bug will appear in both Neo2 and Neo3.

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

Successfully merging a pull request may close this issue.

4 participants