Serialize collection type and append

Hi,

I am trying to do the following:

    auth: Dict[UInt160, UInt160] = {}                           
                                                                
    auth[UInt160('somedata)] = UInt160('somedata')                         
    auth[UInt160('somedata2')] = UInt160('somedata2')                         
                                                                
    debug(['dict: ', auth])                                     
                                                                
    serialized = serialize(auth)                                
    put(AUTH_ADDRESSES, serialized)                             
                                                                
    serialized = get(AUTH_ADDRESSES)                            
    auth = cast(dict[UInt160, UInt160], deserialize(serialized))
                                                                
    auth[UInt160(b'3')] = UInt160(b'3')                         
                                                             

But I am getting an Internal compiler error. AttributeError: 'Call' object has no attribute 'value'

I am using latest neo3-boa on development branch.

I have also tried the same with a list type, but didn’t get it to work either.

BR,

Merl

1 Like

What does your debug event look like? I can get the code above to compile (after fixing a couple of syntax issues) but I’m just using a guess at the debug implementation:

debug = CreateNewEvent(
    [
        ('params', List)
    ],
    'Debug'
).

The debug event was actually a function that called notify. I tried with a real event, but that didn’t change anything yet.

I am getting a compiled contract too, but I am receiving the above error on the lines that add data to the dict.

    auth: Dict[UInt160, UInt160] = {}
    x = UInt160()

    auth[x] = x

    serialized = serialize(auth)
    put(AUTH_ADDRESSES, serialized)

    serialized = get(AUTH_ADDRESSES)
    auth = cast(dict[UInt160, UInt160], deserialize(serialized))

this builds, with a warning for the cast, which I think is expected, and the Internal compiler error. AttributeError: 'Name' object has no attribute 'value' for the line auth[x] = x.

If I try to run everything in a test, I get RVCount doesn't match with EvaluationStack but that’s probably a followup error.

I can’t seem to replicate that error with that code. Using neo3-boa 0.8.1, development branch.

Complete test contract I created from your example:

from boa3.builtin import CreateNewEvent
from boa3.builtin.interop.binary import serialize, deserialize
from boa3.builtin.interop.storage import get, put
from boa3.builtin.type import UInt160
from typing import Any, List, Dict, cast


debug = CreateNewEvent(
    [
        ('params', List)
    ],
    'Debug'
)

AUTH_ADDRESSES = b'AUTH_ADDRESSES'

def test():

    auth: Dict[UInt160, UInt160] = {}
    x = UInt160()

    auth[x] = x

    serialized = serialize(auth)
    put(AUTH_ADDRESSES, serialized)

    serialized = get(AUTH_ADDRESSES)
    auth = cast(dict[UInt160, UInt160], deserialize(serialized))

The result is:

INFO: Started compiling test.py
INFO: Importing 'boa3.builtin'
INFO: Importing 'boa3.builtin.interop.binary'
INFO: Importing 'boa3.builtin.interop.storage'
INFO: Importing 'boa3.builtin.type'
INFO: Importing 'typing'

WARNING: 29:11 - Casting any to dict[UInt160, UInt160]. Be aware that casting types may lead to runtime errors.

INFO: '_initialize' method included in the ABI
INFO: Wrote test.nef 

Same thing with your test contract. Could the python version be the problem, I am running on 3.9.4.

Yeah, installed python38, works.