I write a smart contract that has a read-only function.
I am aware a contract should not store sensible info. However, I want to ensure that this function is only called by the contract owner (the same address that initialized the contract) since the data returned by this function is let's call it "private" to the owner and only the owner should have access to this.
To achieve this, in the function I validate that the address sent as an argument is equals to the contract owner, and then do address.require_auth(). This works.
/// Gets the super secret data stored in the contract. Only the owner can call this function.
pub fn get_data(env: Env, address: Address) -> Data {
authentication::check_admin_address(&env, &address);
address.require_auth();
storage::get_data(&env)
}
But I just realized that the simulateTransaction returns the value anyway, ignoring this address.require_auth step. Is this okay? 🤔
So what is the way to ensure that a read-only function only returns data if it is invoked by the contract owner?