README.md
contract
    Cargo.toml
    neardev
        dev-account.env
    src
        lib.rs
exercises
    0
        README.md
        lib.rs
        test.rs
    1
        README.md
        lib.rs
        test.rs
    2
        README.md
        lib.rs
        test.rs
    3
        README.md
        lib.rs
        test.rs
next.config.js
package.json
pages
    _app.js
    api
        execute.js
        exercises
            [id]
                index.js
    exercises
        [id]
            index.js
        index.js
    index.js
public
    vercel.svg
state
    exercise.js
    near.js
tests::(?<name>\w+) stdout
styles
    globals.css

# Saturating Counter Contract

In the last exercise we implemented a simple `Counter` smart contract. In this exercise we'll improve that contract by adding some overflow safety.

Since the `Counter` uses an `i8` the minimum `self.val` is `-128` and the maximum is `127`. If we try to `decrement` or `increment` outside the minimum or maximum an overflow will occur. This can be prevented by using the `saturating_*` methods.

## Improve increment

Update the `increment` method so that it saturates at the `i8::MAX` value.

## Improve decrement

Update the `decrement` method so that it saturates at the `i8::MIN` value.

## Resources

- [saturating_add](https://doc.rust-lang.org/std/primitive.i8.html#method.saturating_add)
- [saturating_sub](https://doc.rust-lang.org/std/primitive.i8.html#method.saturating_sub)
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
# Status Message

Implement a Smart Contract that can `set_status` and `get_status` using a `LookupMap`.

## set_status

The `set_status` smart contract method should `insert` a message into the `self.records` `LookupMap`.

## get_status

The `get_status` smart contract method should get a message stored at the `account_id` key inside the `self.records` `LookupMap`.

## Resources

- [LookupMap](https://docs.rs/near-sdk/3.1.0/near_sdk/collections/struct.LookupMap.html)
# Counter Contract

Implement a Smart Contract that can `increment`, `decrement`, and `reset` a `val`.

## get_num

The `get_num` smart contract method should return the current counter `val`. The counter struct is accessible via `self`.

## increment

The `increment` smart contract method should increment `val` by `1`. It is a mutable method (because it changes `val`). In Rust we need to explicitly state that `increment` can mutate the data held in the `Counter` struct by mutably borrowing `self` with `&mut self` as the first parameter in the method signature.

## decrement

The `decrement` smart contract method should decrement `val` by `1`. Like `increment`, it is a mutable method.

## reset

The `reset` smart contract method should reset `val` to `0`. Like `increment` and `decrement`, it is a mutable method.

## Resources

- [Rust Book - Data Types](https://ferrous-systems.github.io/teaching-material/basic-types.html#)
- [Rust Book - Structs](https://doc.rust-lang.org/book/ch05-01-defining-structs.html)
- [Rust Book - Method Syntax](https://doc.rust-lang.org/book/ch05-03-method-syntax.html)
- [Ferrous Systems - Basic Type](https://ferrous-systems.github.io/teaching-material/basic-types.html)
- [Ferrous Systems - Compound Types](https://ferrous-systems.github.io/teaching-material/compound-types.html#/)
# Wrapping Counter Contract

In the last exercise we improved the simple `Counter` smart contract utilizing the `saturating_*` methods. In this exercise we'll try an alternative approach using the `wrapping_*` methods.

## Improve increment

Update the `increment` method so that it wraps at the `i8::MAX` value.

## Improve decrement

Update the `decrement` method so that it wraps at the `i8::MIN` value.

## Resources

- [wrapping_add](https://doc.rust-lang.org/std/primitive.i8.html#method.wrapping_add)
- [wrapping_sub](https://doc.rust-lang.org/std/primitive.i8.html#method.wrapping_sub)
