Skip to content

A list of resources to quickly learn from the best on the IC

Notifications You must be signed in to change notification settings

fowlerlee/IC-notes-projects-tips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

IC-notes-projects-tips

Links to great videos and learning content

Encrypted notes dapp

shared({ caller = initializer }) actor class() {...};

// Below, we implement the upgrade hooks for our canister. // See https://smartcontracts.org/docs/language-guide/upgrades.html

// The work required before a canister upgrade begins. // See [nextNoteId], [stable_notesByUser], [stable_users] system func preupgrade() { Debug.print("Starting pre-upgrade hook..."); stable_notesByUser := Iter.toArray(notesByUser.entries()); stable_users := UserStore.serializeAll(users); Debug.print("pre-upgrade finished."); };

// The work required after a canister upgrade ends. // See [nextNoteId], [stable_notesByUser], [stable_users] system func postupgrade() { Debug.print("Starting post-upgrade hook..."); notesByUser := Map.fromIter<PrincipalName, List.List>( stable_notesByUser.vals(), stable_notesByUser.size(), Text.equal, Text.hash);

users := UserStore.deserialize(stable_users, stable_notesByUser.size()); stable_notesByUser := []; Debug.print("post-upgrade finished."); };

Note: that the dapp allows many devices to be connected for the same user but for stability and security only 1000 users are allowed to register.

The II is a actor that is part of this dapp but is used as an external actor to the shared actor herein.

When we want to do a try-catch type assertion with exception, do the following with “expect(... , .);”: var existingNotes = expect(notesByUser.get(principalName), "registered user (principal " # principalName # ") w/o allocated notes"); The caller of this function is set in the actor initialization and then used throughout the code as “caller” in methods as a parameter: // in the actor creation part on top of all the code shared({ caller = initializer }) actor class() {...};

//in the methods throughout the code we use caller public shared({ caller }) func update_note(encrypted_note: EncryptedNote): async () {...};

Cool projects on ICP

About

A list of resources to quickly learn from the best on the IC

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published