Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Counter without auth #20

Closed
wants to merge 25 commits into from
Closed

Simple Counter without auth #20

wants to merge 25 commits into from

Conversation

kmlee307
Copy link

Type of this PR

Select at least one type

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Bug fix
  • Dependency, Environment, Build related update
  • Documentation
  • Other tiny fix

Describe your changes

Using UnordereMap to generate simple counter without auth
Used designated account name(kmlee) for test

Reference

https://github.com/near-examples/rust-status-message/blob/master/src/lib.rs
https://github.com/near-examples/rust-counter/blob/01-use-hashmap/contract/src/lib.rs
https://www.near-sdk.io/testing/unit-tests

Issue ticket number and other helpful resource

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • Leave reference about this pull request, if exist (ex. discord message, google docs, etc)
  • If it is a core feature, I have added thorough tests.

Checklist after creating a pull request

  • Mention reviews in discord channel directly

@kmlee307 kmlee307 requested a review from happyhappy-jun July 11, 2022 07:59
Copy link
Contributor

@happyhappy-jun happyhappy-jun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음으로 깃 사용해서 작업해보시느라 수고 많으셨습니다

커밋 메세지와 무관한 내용이 커밋에 담겨있습니다. interactive rebase 와 force push 를 이용해서 한 번 고쳐봅니다.

p.s. cli 로 이걸 하려면 굉장히 어렵습니다. fork 와 같은 버전관리 툴을 한번 사용해봅시다. 만약 도움이 필요하다면, 핑을 찍거나 저녁에 제가 디코에 있는 거 같을때 보이스챗으로 도와드리겠습니다

simple-counter/src/lib.rs Outdated Show resolved Hide resolved
pub fn increment(&mut self) {
//let caller = env::signer_account_id();
//use below line instead of below for test
let caller = "kmlee".to_string();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caller 가 어떠한 임의의 계정으로 고정이 되어있습니다

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env의 signer account로 변경했습니다!

let caller = "kmlee".to_string();
let current_val = match self.user_counters.get(&caller) { //get previous value
Some(val) => val,
None => 0i16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get을 했는데, 어떠한 값도 찾을 수 없다면, 0을 리턴하는 게 좋을까요? 아니면, panic 으로 터트리는게 더 좋을까요?

만약에 존재하지 않는 계정을 increase 하려고 하면 뭐가 문제일지 함수 명과 함께 생각해봅니다

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None의 경우 panic으로 수정했습니다

let caller = "kmlee".to_string();
let current_val = match self.user_counters.get(&caller) { //get previous value
Some(val) => val,
None => 0i16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 코멘트와 비슷한 맥락이지만, 이쪽은 더 위험합니다. 다행히 지금은 자료형이 i16 signed 이지만, u64에서는 무슨 일이 벌어질까요?

Copy link
Author

@kmlee307 kmlee307 Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자료형을 수정하고 이 또한 decrease 함수 또한 panic으로 수정했습니다

//logging
env::log(b"Reset counter to zero");
}
pub fn delete(&mut self, k: String) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use fommatter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants