0

I was building a semi Dapp, don't have the balls to call it a Dapp. Basically it's a market place that connects service providers with service seekers. It will have a smart contract that handles payments between the two, when a certain service is delivered and verified by a moderator or a third party. The service seeker will escrow his tokens before the service is started and sign an off-chain typev4 signature which will be verified by the smart contract and the service provider will claim the escrowed token with the signature. I have created a struct that represents the service, which holds the es-crowed amount.

struct Job{
        address host;
        mapping(address=>bool) isReceiver;
        uint256 amount;
        uint256 maximumProviders;
        uint256 expiration;
        uint256 total_receivers;
    }
// service seeker will deposit to the smart contract
function deposit(uint256 _amount) public returns (bool) {
        _balances[msg.sender]=_balances[msg.sender].add(_amount);
        require(_token.transferFrom(msg.sender,address(this),_amount));
        emit Deposit(msg.sender,_amount);
        return true;
    }

//called by job seeker
function createJob(uint256 amount,uint256 maximumProviders,uint256 expiration) external returns(bool){
// some operations like setting the jobId, expiration etc,
' some operation
' some operation

 job.amount=amount;
_balances[msg.sender]=_balances[msg.sender].sub(amount);
}

// called by service providers that is  be a receiver
function redeem(uint256 jobId,uint256 amount,bytes calldata signature){

 require(job.isReceiver[msg.sender],"not receiver");


//some other operation
'some other operation
'some other operation

}

//can only be called by the job host or creator
 function addReceivers(uint256 jobId,address[] calldata receivers) onlyOwner(msg.sender){


// adds receivers to the job with the spercified by jobId
emit(receivers);

}

The problem is that the service providers are not known at the time of job instance creation. it is later after they have claimed the job that they will be added to the instance as the receivers by the job host. To make sure they job host are adding the correct receivers provided by the backend, I dedicated a server that continuously polls the events and cross check if the right receivers are added by the job host.The website backend will communicate with the event listener backend to verify that whether a transaction happens or not. the events are accessible from the frontend but data coming from frontend can not be trusted as a source of truth.

Is there a better way to design such system?

Architecture

11
  • 1
    You'd receive better answers if you split your question into multiple (generic) sub-problems. Oct 10 at 9:16
  • Sure! Issue 1: how do i make sure an action performed on chain by a client is what the application or the system expected it to be. let's say we want a user to call a smart contract function with a data fetched from the back-end of our application as a parameter. if the user succeeds we want to provide a certain privilege to the user. since smart contract invocation happens on the front-end by the user, how do i make sure the right data has been passed as a parameter to the smart contract? my assumed solution is illustrated above in the figure. Just wanted to make sure i am correct.
    – leycun
    Oct 10 at 10:30
  • What I meant is post new StackExchange questions for those sub-problems if there aren't already answers for them. Oct 10 at 11:04
  • My take on your first question in the comment, though: that is not possible. As per Hyrum's Law, all observable behaviors of your system will eventually be depended on by somebody. Oct 10 at 11:06
  • definitely, thank you for your answers. I understand that I can not make sure they use the right parameter as it i can not control the behaviors of the user. thank you for the reference Hyrum's Law. I feel like am stupid but what i wanted to say was how do i monitor if they have passed the correct parameter or not in order to verify them or not. I guess it could be done listening to the events emitted by the contract when a certain action happens. My interest is to know which architecture is best suited for orchestrating the backends, the smart contract and the frontend? thanks!
    – leycun
    Oct 10 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.