I am trying to write a contract that receives rewards from the baker using a default entry point and should only allow me to change the baker from a different entry point.
I am using the smartpy tool to write a contract.
import smartpy as sp
class DelegateAndRewards(sp.Contract):
def __init__(self,admin):
self.init(admin = admin)
@sp.entry_point
def default(self):
sp.verify(sp.amount > sp.mutez(0))
@sp.entry_point
def setDelegation(self,params):
sp.verify(sp.sender == self.data.admin)
sp.set_delegate(params.baker)
@sp.add_test(name="test")
def test():
obj = DelegateAndRewards(admin = sp.address("tz1a4UNywaxaAfh2LRBP2UugQTeCVcLCn5Sa"))
scenario = sp.test_scenario()
scenario += obj
This contract gets originated (KT1Qk5To61kToEbfPPbsaCvAE8xt3fDMHF6B) but fails at invocation of "setDelegation" entry point.
If you change the name of the "default" entry point to something like "getRewardsFromBaker" (KT1B3J5EHQM92GZH9hRJjAn7Rab16unLoHLx). Things would work fine but I am not sure whether the baker would be able to transfer rewards. If yes then how?
Thanks in advance.