Rise In Logo





Move on Sui Course

🥳 Congratulations on making this far in the Bootcamp, you are doing great. Now it's time to for a small homework.

For the first homework assignment, you are going to extend the DevHub contract you build.

In the DevHub contract you have build the update_card_description function below:

public entry fun update_card_description(devhub: &mut DevHub, new_description: vector<u8>, id: u64, ctx: &mut TxContext) {
        let user_card = object_table::borrow_mut(&mut devhub.cards, id);
        assert!(tx_context::sender(ctx) == user_card.owner, NOT_THE_OWNER);
       
        let old_value = option::swap_or_fill(&mut user_card.description, string::utf8(new_description));




        event::emit(
            DescriptionUpdated{
                name: user_card.name,
                owner: user_card.owner,
                new_description: string::utf8(new_description)
            }
        );




        _ = old_value;
    }

This function only updates the card description. 

You also created a seperate function where users can update open_to_work field of DevCard struct:

public entry fun deactivate_card(devhub: &mut DevHub, id: u64, ctx: &mut TxContext) {
        let user_card = object_table::borrow_mut(&mut devhub.cards, id);
        assert!(tx_context::sender(ctx) == user_card.owner, NOT_THE_OWNER);
        user_card.open_to_work = false;
    }

Step 1

You will create a new function called update_portfolio.

This function will be similar to the deactivate function but instead of open_to_work field, you will update the portfolio field.

Step 2

Copy and paste your function below.

Bonus Step

This step is not mandatory but if you want to challenge yourself a bit more, this step is for you.

In this step, you will create a separate event like the one below:

struct DescriptionUpdated has copy, drop {
        name: String,
        owner: address,
        new_description: String,
    }

This event is from the DevHub contract you have written. The new event you will be creating will be named PortfolioUpdated. It will have three fields, name: String, owner: address and new_portfolio: String.

After creating this event, you will update the update_portfolio function so that this event will be emitted in the function. You can check update_card_description function above to see how event emitting is done. After you finish the function, copy and paste your function below.

Project

Rise In Logo

Rise together in web3