2

I'm trying to access a storage data of a contract from another one using the continuous passing style in smartPy.

import smartpy as sp
class XXIFA12(sp.Contract):
    def __init__(self, admin):
        self.init(balances = sp.big_map(tvalue = sp.TRecord(balance = sp.TNat)), administrator = admin, totalSupply = 0)

    @sp.entry_point
    def mint(self, params):
        sp.verify(sp.sender == self.data.administrator)
        self.addAddressIfNecessary(params.address)
        self.data.balances[params.address].balance += params.amount
        self.data.totalSupply += params.amount

    def addAddressIfNecessary(self, address):
        sp.if ~ self.data.balances.contains(address):
            self.data.balances[address] = sp.record(balance = 0)

    @sp.entry_point
    def getBalance(self, params):
       sp.transfer(
         self.data.balances[params.arg.owner].balance,
         sp.tez(0), 
         sp.contract(sp.TNat, params.target
       ).open_some())

class DIVIDENDS(sp.Contract):
    def __init__(self, admin, xxiAdd):
        self.init(
            xxiAddress = xxiAdd,
            balance = 0
        )

    @sp.entry_point
    def testGetBalance(self, params):
        assertTrasnferRecord = sp.record(arg = sp.record(owner = params.owner), target = params.address)
        entryPointName = "getBalance"
        c = sp.contract(
        t = sp.TRecord(arg = sp.TRecord(owner = sp.TAddress), target = sp.TAddress),
            address = self.data.xxiAddress,
            entry_point = entryPointName
        ).open_some()
        sp.transfer(assertTrasnferRecord, sp.mutez(0), c)

        # this is what I want to do but it doesn't compile
        #self.data.balance = sp.transfer(assertTrasnferRecord, sp.mutez(0), c)
if "templates" not in __name__:
    @sp.add_test(name = "FA12")
    def test():
        scenario = sp.test_scenario()
        scenario.h1("Dividends Contract")
        # sp.test_account generates ED25519 key-pairs deterministically:
        admin = sp.address("tz1g37HrEzgqVtCEs5ea5m3RhL6jfsvTiJfR")
        alice = sp.test_account("Alice")
        bob   = sp.test_account("Robert")
        # Let's display the accounts:
        scenario.h2("Accounts")
        scenario.show([alice, bob])
        c1 = XXIFA12(admin)
        scenario += c1
        scenario.h2("Admin mints a few coins")
        scenario += c1.mint(address = alice.address, amount = 12).run(sender = admin)

        c2 = DIVIDENDS(admin, c1.address)
        scenario += c2

        c3 = c2.testGetBalance(owner = alice.address, address = c2.address).run(sender = admin)
        scenario += c3

I got this error in smartpy.io :

Error: Error in Scenario
Unexpected error in transaction, please use .run(valid=False, ..)
ChannelNotFound: 'default'
default (12 : sp.TNat) line 64
Traceback (most recent call last):
3

There are several example templates, such as FA2 (real world token contracts) and Collatz (small demo and test template). https://www.smartpy.io/dev/?template=FA2.py https://www.smartpy.io/dev/?template=collatz.py

For your example, the error message is clearly unhelping but you should define an entry point to receive the value in a contract.

You cannot use testGetBalance to both send the request and receive the result of the request so you should define another entry point to receive the result.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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