Open a-moreira opened 1 year ago
Perhaps another way to think about this would also be as follows:
Does the phat contract need to implement a general
onMessageReceived
type of callback handler which receives whatever the pallet passed into theanchor::push_message()
call? -- This would be akin to theOnResponse
which a pallet would implement but on the phat contract side.
As an example, let's assume we'd like like to call the feed_price()
function in the deployed sub_price_feed
phat contract which we've successfully initialized rollup for.
I want to invoke a specific function within a deployed Phat Contract from Anchor by calling anchor::push_message.
@FaisalAl-Tameemi's answer is correct. If you want to trigger the Phat Contract from the anchor side (pallet or smart contract), you will need to push a message. Once the message is pushed, it stays in the anchor storage. The next time when the offchain rollup Phat Contract reads the storage, it will notice it, and you can get it by accessing the request queue from your PC like mentioned in the readme file (assume you have initialized a rollup client):
// Get a request if available
if let Some(raw_req) = client
.session()
.pop()
.expect("failed to read queue") {
// let action: Vec<u8> = ... Create your response based on the raw_req ...
client.action(Action::Reply(action));
}
This is called Req-Resp model. You add requests on chain, and the Phat Contract answer it later on. The request will be removed once the blockchain receives the response. The request and the response are bytes arrays. So you can pass arbitrary message back and forth.
@h4x3rotab out of curiously, is it correct that XCM could also be used to invoke an ink! message in the phat contract?
Theoretically you can send a Transact message to Phala to call phalaPhatContract.pushContractMessage
but not recommended vs. RPC?
I want to invoke a specific function within a deployed Phat Contract from Anchor by calling
anchor::push_message
. I know this should be encoded as thedata
field, but would like further clarification on how to do it. I've been able to receive responses from this Phat Contract into my Anchor pallet via theOnResponse
trait, but not yet to send to it.