-1

I have a smart contract something like this

contract Foo {
    struct Post() {
        ....
    }
    mapping (uint256 => Post) private posts;
    mapping (uint256 => address) private owners;
}

And I have a backend code written with Python:

post_matchings = {}

@hug.post('match/post_id/')
def match_file(file_id, post_id):
    1. raise error, if caller of this endpoint is not owner of the post.
    2. Do something.

How can I accomplish this? By using signatures?

Thanks for your help.

Mirat Can Bayrak
  • 631
  • 7
  • 18

2 Answers2

1

you can make a view function that you can call from your backend to get this response, it could be something like this

function UserMakePost (address user, uint256 postId) external returns (bool) {
  return user == owners(postId);
}

otherwise if you cannot modify the contract because is already deployed you can count on offchain solutions, like if you already know the address you can't just do as you propose in your response, other solution could be read event's from the blockchain and store the information you need in a database, that way you don't need to consult all the time to the blockchain (this assuming that the contract emit events)

jhonny
  • 805
  • 4
  • 10
-1

I found the answer. You have to send a random string to frontend, ask frontend to sign it with dapp wallet then send it to backend and check validity.

Mirat Can Bayrak
  • 631
  • 7
  • 18