Problem sending messages from a contract

Hi devs,
i am sending messages from a smart contract, and later, in subsequent blocks, I want to read them back, by the same contract, to react. I basically use the message function to store data "persistently" for a few blocks. To keep the contract itself stateless. I see that the message is submitted in the log, but I'm not able to retrieve it back using a getPrunableMessages call. I guess I make a mistake somewhere, and probably an obvious one.

In block X, I send this message:

SendMessageCall sendMessageCall = SendMessageCall.create(2).
message(message.toJSONString()).
messageIsPrunable(true).
feeNQT(IGNIS.ONE_COIN).
recipient(otherAccountRs);
context.createTransaction(sendMessageCall);

The node responds:

2021-03-17 08:02:22 INFO: main [sendMessage]: request broadcast=false&chain=2&requestType=sendMessage&messageIsPrunable=true&feeNQT=100000000&recipient=9753781029058255917&ecBlockHeight=8&publicKey=112e0c5748b5ea610a44a09b1ad0d2bddc945a6ef5edc7551b80576249ba585b&message={"submittedBy":"myContract","value1":false,"contract":"myContract","importantHeight":X,"source":"BLOCK"}&ecBlockId=5755268534631000133&timestamp=101668395
2021-03-17 08:02:22 INFO: main [sendMessage]: request broadcast=true&chain=2&requestType=sendMessage&messageIsPrunable=true&feeNQT=2000000&recipient=9753781029058255917&ecBlockHeight=8&publicKey=112e0c5748b5ea610a44a09b1ad0d2bddc945a6ef5edc7551b80576249ba585b&message={"submittedBy":"myContract","value1":false,"contract":"myContract","importantHeight":X,"source":"BLOCK"}&ecBlockId=5755268534631000133&timestamp=101668395

Note the change in fees between both rows.

In block X+1..n, using the same callback (processBlock), I want to check for this message:

JO response = GetPrunableMessagesCall.create(2).account(context.getAccountRs()).otherAccount(otherAccountNumeric).timestamp(timeOfABlockBeforeX).call();

And I don't find any messages.

  • Later,I tried without the timestamp in the GetPrunableMessagesCall, to no avail, unfortunately.
  • Checking for messages in the test that runs the contract also returns no messages.
  • I tried adding a message to the sendMoneyCall, which also didnt modify the standard {"submittedBy":"myContract","source":"BLOCK"} message.

thanks for any help!

Are you running all of this code from the same unit test? Notice that each unit test starts with an empty blockchain (there's a reset between tests).

Perhaps you can share the full log of the unit test run, we output quite some information to debug what's happening.

Hi Sergi,

I think I found the root cause of the issue.
replacing

context.createTransaction(sendMessageCall);

with

return context.createTransaction(sendMessageCall);

solved the issue.

To send multiple messages I have to return context.getResponse(). That wasn't obvious to me. Thanks for the support

Hi Jelurida, could you review that section of the docs in the context above? I think that the documentation misses the bit that you need to either return "getResponse()" or the "createTransaction()".

1 Like

I'm adding a note to my backlog to take a look into it as soon as possible.

I'm reviewing the docs about this. I have one question: if you weren't returning the context (either from createTransaction() or from getResponse() what were your returning instead?

I had to go back through my commits: I returned a self-made JO with some information, to add this information to the node log.