Rise In Logo



Learn everything about Move on Sui

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

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!

Disclaimer: The information /programs / events provided on https://patika.dev and https://risein.com are strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice and do not make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://patika.dev and https://risein.com disclaim any responsibility for financial decisions made by users based on information provided here.