Rise In Logo



Move on Sui Course

Functions 2

  • In this lesson, you are going to create three more functions.
  • With the update_card_description function, users will be able to update their card's description.
  • With the deactivate_card function, users will be able to indicate that they are no longer to open to work.
  • Finally you will create a public function which will return the card information based on the given id.

You can access the codes we wrote in this lesson below. 👇

 // With this function the user can change his/her card's description
  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;
  }

  // With this function user can deactivate his/her account by setting open_to_work field of his/her card to false
  public entry fun deactivate_card(devhub: &mut DevHub, id: u64, ctx: &mut TxContext) {
    let card = object_table::borrow_mut(&mut devhub.cards, id);
    assert!(card.owner == tx_context::sender(ctx), NOT_THE_OWNER);
    card.open_to_work = false;
  }

  // This function returns the card based on the id provided
  public fun get_card_info(devhub: &DevHub, id: u64): (
    String,
    address,
    String,
    Url,
    Option<String>,
    u8,
    String,
    String,
    String,
    bool,
  ) {
    let card = object_table::borrow(&devhub.cards, id);
    (
      card.name,
      card.owner,
      card.title,
      card.img_url,
      card.description,
      card.years_of_exp,
      card.technologies,
      card.portfolio,
      card.contact,
      card.open_to_work
    )
  }


Comments

Anonymous

0/500

You need to enroll in the course to be able to comment!

Stay in the know

Never miss updates on new programs and opportunities.

Rise In Logo

Rise together in web3!