Skip to content

Commit

Permalink
Add doc comments to Motoko actor endpoints; fix access control (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa committed Aug 24, 2023
1 parent d441c72 commit 58d8b78
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 6 additions & 6 deletions canisters/backend/Core.mo
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ module {
log.okWith(checkOutcome);
};

public func isNftOwned(caller : Principal, nft : Types.Nft.Nft) : async Bool {
public func isNftOwned(caller : Principal, principal : Principal, nft : Types.Nft.Nft) : async Bool {
let log = logger.Begin(caller, #isNftOwned(nft));
let isOwned = await isNftOwned_(caller, nft);
let isOwned = await isNftOwned_(principal, nft);
log.okWith(isOwned);
};

func isNftOwned_(caller : Principal, nft : Types.Nft.Nft) : async Bool {
switch (state.hasWalletSignsPrincipal(nft.owner, caller)) {
func isNftOwned_(principal : Principal, nft : Types.Nft.Nft) : async Bool {
switch (state.hasWalletSignsPrincipal(nft.owner, principal)) {
case (?_) {
switch (nft.tokenType) {
case (#erc721) {
Expand Down Expand Up @@ -110,15 +110,15 @@ module {
};

public func getHistory(caller : Principal) : ?[History.Event] {
assert caller == installer;
do ? {
// to do -- access control, maybe.
logger.getEvents(0, logger.getSize());
};
};

public func getState(caller : Principal) : ?[Snapshot.Entry] {
assert caller == installer;
do ? {
// to do -- access control, maybe.
Snapshot.getAll(_state);
};
};
Expand Down
14 changes: 12 additions & 2 deletions canisters/backend/Main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,52 @@ shared ({ caller = installer }) actor class Main() {

let core = Core.Core(installer, sys, _state_v0, _history_v0);

/// Login and fetch user details. Creates an account if none exists for the caller principal.
public shared ({ caller }) func login() : async Types.Resp.Login {
core.login(caller);
};

/// If you've already created an account, you can use this method to speed up the login process.
public query ({ caller }) func fastLogin() : async ?Types.Resp.Login {
core.fastLogin(caller);
};

/// Get a list of connected Ethereum wallets.
public query ({ caller }) func getEthWallets() : async Types.Resp.GetEthWallets {
core.getEthWallets(caller);
};

/// Connect a new Ethereum wallet, using the given ECDSA signature for authorization.
public shared ({ caller }) func connectEthWallet(wallet : Types.EthWallet, signedPrincipal : Types.SignedPrincipal) : async Types.Resp.ConnectEthWallet {
await core.connectEthWallet(caller, wallet, signedPrincipal);
};

public shared ({ caller }) func isNftOwned(caller : Principal, nft : Types.Nft.Nft) : async Bool {
await core.isNftOwned(caller, nft);
/// Check if an NFT is currently owned by the given principal.
public shared ({ caller }) func isNftOwned(principal : Principal, nft : Types.Nft.Nft) : async Bool {
await core.isNftOwned(caller, principal, nft);
};

/// Verify that the given NFTs are owned by the caller, and store the results.
public shared ({ caller }) func addNfts(nfts : [Types.Nft.Nft]) : async Bool {
await core.addNfts(caller, nfts);
};

/// Retrieve the NFTs which were previously verified via `addNfts()`.
public query ({ caller }) func getNfts() : async [Types.Nft.Nft] {
core.getNfts(caller);
};

/// Retrieve the full log for this canister.
public query ({ caller }) func getHistory() : async ?[History.Event] {
core.getHistory(caller);
};

/// Retrieve a public-facing log for this canister.
public query ({ caller }) func getPublicHistory() : async [Types.PublicEvent] {
core.getPublicHistory(caller);
};

/// Retrieve a Candid representation of the canister's internal state.
public query ({ caller }) func getState() : async ?[Snapshot.Entry] {
core.getState(caller);
};
Expand Down
2 changes: 2 additions & 0 deletions canisters/backend/tests/Main.test.mo
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// Write your unit tests here

assert true;

0 comments on commit 58d8b78

Please sign in to comment.