0

I am creating a big_maps with a value type of struct Assets and AssetsDetails. While i try to put the value in map getting an error of: [error] File "smartML/tools/compiler.ml", line 2210, characters 18-24: Assertion failed. The error is from this part of code: assets[i]=sp.record( coin_name=coin_names[i], value=values[i], )

Here is the code:

import smartpy as sp

Asset = sp.TRecord(
    coin_name=sp.TString,
    value=sp.TNat
    )

class Preiphery(sp.Contract):
    @sp.entry_point
    def send_service_message(self, _from, to, coin_names, values, fees):
        sp.set_type(_from, sp.TAddress)
        sp.set_type(to, sp.TString)
        sp.set_type(coin_names, sp.TMap(sp.TNat, sp.TString))
        sp.set_type(values, sp.TMap(sp.TNat, sp.TNat))
        sp.set_type(fees, sp.TMap(sp.TNat, sp.TNat))

        assets = sp.big_map(tkey=sp.TNat, tvalue=Asset)

        sp.for i in sp.range(sp.nat(0), sp.len(coin_names)):
            assets[i]=sp.record(
                coin_name=coin_names[i],
                value=values[i]
            )

@sp.add_test(name="Counter")
def test():
    scenario = sp.test_scenario()
    counter = Preiphery()
    scenario += counter

1 Answer 1

0

In the legacy syntax sp.big_map(...) does not create a big_map. It only returns an expression that, when evaluated, creates a big_map.

If you want to modify a variable you have to use a sp.local. As big_map are only updated through methods you can even simplify and use sp.compute.

 assets = sp.compute(sp.big_map(tkey=sp.TNat, tvalue=Asset))

Now let me add that it's strange having to do what you are doing. Why not giving a more proximate type in the entrypoint?

class Preiphery(sp.Contract):
    @sp.entry_point
    def send_service_message(self, _from, to, coins):
        sp.set_type(_from, sp.TAddress)
        sp.set_type(to, sp.TString)
        sp.set_type(coins, sp.TList(Asset))

        assets = sp.compute(sp.big_map(tkey=sp.TNat, tvalue=Asset))
        i = sp.local("i", 0)

        sp.for coin in coins:
            assets[i.value]=coin
            i.value += 1

Would do the same thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.