Tico4Chain-Coders / Trustless-Work

Trustless Work provides permissionles escrow infrastructure. By using Trustless Work, any platform can integrate escrows in their user flow, it leverages Stellar Soroban Smart Contracts and USDC, a digital version of the dollar.
https://www.trustlesswork.com
5 stars 6 forks source link

smart contracts: Create function to update escrow milestones information #21

Open JoelVR17 opened 1 day ago

JoelVR17 commented 1 day ago

You must apply through OnlyDust. If not, you'll be ignored

Description:

Functions are needed to modify the “status” and “flag” of an escrow milestone in the contract.rs file. Two functions are needed since one must be executed only by the service provider and one by the signer.

What is a milestone?

Milestone is a property of the escrow itself which can be found defined in the storage_types.rs file. It defines a series of objectives to be met by the service provider in order to complete an escrow.

First requirement:

A function must be created which can be executed only by the service provider. This function must be able to change the value of the “status” property of the milestone.

This function must be called: “change_milestone_status”.

The function must receive the following parameters:

  1. engagement_id (type: String) → Escrow identifier.
  2. milestone_index (type: i128) → index of the milestone to be modified
  3. new_status (type: String) → new milestone status value.

Note: Feel free to add more parameters to the function if necessary.

Validations required:

  1. The index of the milestone must exist
  2. The engagement id must match the one already defined for the escrow. Otherwise, this means that the escrow has not been initialized.
  3. Only the service provider defined within the escrow can perform this function.
  4. This function can only be executed if the escrow has at least 1 milestone defined. Since there is a possibility that the escrow was initially initialized without any milestone.

Second requirement:

A function must be created which can be executed only by the signer. This function must be able to change the value of the “flag” property of the milestone.

This function must be called: “change_milestone_flag”.

The function must receive the following parameters:

  1. engagement_id (type: String) → identifier of the escrow.
  2. milestone_index (type: i128) → index of the milestone to modify
  3. new_flag (type: bool) → new value of the milestone flag.

Note: Feel free to add more parameters to the function if necessary.

Validations required:

  1. The index of the milestone must exist.
  2. The engagement id must match the one already defined for the escrow. Otherwise, this means that the escrow has not been initialized.
  3. Only the client defined within the escrow can perform this function.
  4. This function can only be executed if the escrow has at least 1 milestone defined. Since there is a possibility that the escrow was initially initialized without any milestone.

Note: Regarding the required parameters, feel free to add any other parameters to the functions needed to complete the issue.

Ensure that the new milestone information is stored correctly within the escrow.

Errors:

We currently have a number of custom errors which we throw when executing some of the contract functions. An example of the above would be the following:

if escrow.balance != escrow.amount {
      return Err(ContractError::EscrowBalanceNotSufficienteToSendEarnings);
}

You only need to worry about throwing the error message, you don't need to handle custom errors. So if you need to return an error within the flow due to one of the validations, you can do it as follows:

if escrow.balance != escrow.amount {
      return Err("Your error message");
}

You must make sure that the message you are sending as an error is very clear and makes sense as to why the error is being sent.

Tests:

In the test.rs file you must develop the following test to check that the contract flow works correctly together with the functions you have just built:

  1. Initialize the escrow (initialize_escrow) with status equal to “in-progress” in each of the milestones.
  2. Change the “status” property using the “change_milestone_status” function and verify that the value has been changed to “completed”.
  3. Change the “flag” property using the “change_milestone_flag” function and verify that the boolean value has been changed to true.
  4. Verify that all required validations for “change_milestone_status” and “change_milestone_flag” are working correctly.
  5. Both functions must verify that the escrow must have at least 1 milestone. Otherwise it will throw an error and the test will fail.

You can rely on the previously created tests to complete your test. The important thing is that you succeed in testing your code and that it works well in conjunction with the entire contract flow which is explained in the list above. Also, please note that you should not create a test for each of the items in the above list. This list indicates with each of its items the flow that must contain the only test that you must create to verify that the code you made works. You can also create more than 1 test if necessary, but if you do, you must justify why.

⚠️ Important: Please define a clear name for the test so that the purpose of the test is clearly understood.

To run the test you have just created you can use the command cargo test.

Recommendation:

Stellar people have in their discord a channel called “stella-help”, in that channel you can ask your technical questions about Stellar and its libraries (including the “soroban_sdk” library we use in the contract). This bot can help you a lot to solve your issues. Just remember that before submitting your query you must add the word “stella” at the beginning of the query. Otherwise the bot will not answer you. The Stellar discord where you can find this channel is the following: Stellar Discord

⚠️ Please follow the guidelines for requesting an issue, launching commits and describing PR's. Otherwise they will be ignored. ⚠️

Bosun-Josh121 commented 22 hours ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged:

software engineering background, backend & smart contract dev with contribution to similar tasks(https://app.onlydust.com/u/Josh-121) looking to make first contribution on this project

How I plan on tackling this issue I would create function and ensure it meets stated requirements, I would also work on feedback & recommendation ensuring contact. Can deliver within a day upon assignment

Jonatan-Chaverri commented 21 hours ago

I will like to take care of this issue! I'm a member of Dojo Coding community! Have experience working with Rust before, contributing to Dojo game engine mostly.

joanne-cmd commented 21 hours ago

hello , my name is joanne, currently i have been working with rust creating simple projects to improve my skills, i would love to work on this issues to challenge my self, by creating the required function and implement the tests

Unickhub commented 21 hours ago

I'd like to handle this task.

ikemHood commented 20 hours ago

Hello, I'm Ikem, a blockchain developer with over 3 years of experience in smart contract development.

I would love to help implement the milestone management functions for the escrow system.

My proposed approach:

  1. Implement change_milestone_status function with Service provider authorization, Milestone existence validation and Escrow state verification.
  2. Create change_milestone_flag function including Signer-only access control, Required validation checks, State updates.
  3. Develop comprehensive test suite covering:
    • Complete milestone workflow
    • Authorization checks
    • Edge cases for milestone validation

Looking forward to enhancing the escrow system! 🚀

emarc99 commented 18 hours ago

Let me try this one! I can write cairo & rust, also I have contributed to OD hack in cairo.

armandocodecr commented 18 hours ago

This issue is for you @Bosun-Josh121 ! 🚀 Remember to follow all the guidelines, both the ones inside the repository and the guideline to perform the PR.

Many thanks to all the other dev's who sent in their application. 🔥