Skip to content

Commit eace4c9

Browse files
committed
initial implementation for claim protocol
1 parent 5928eab commit eace4c9

File tree

10 files changed

+1487
-96
lines changed

10 files changed

+1487
-96
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ repository = "https://github.com/<xxx>/<xxx>"
1111
[lib]
1212
crate-type = ["cdylib", "rlib"]
1313

14-
# fields to configure build with WASM reproducibility, according to specs
15-
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
14+
# fields to configure build with WASM reproducibility, according to specs
15+
# in https://github.com/near/NEPs/blob/master/neps/nep-0330.md
1616
[package.metadata.near.reproducible_build]
1717
# docker image, descriptor of build environment
1818
image = "sourcescan/cargo-near:0.12.1-rust-1.82.0"
@@ -22,7 +22,7 @@ image_digest = "sha256:841e72af53e151e3d8f65ef2e50dcec162699d876348a8ec0e77b6cde
2222
# in a reproducible manner
2323
# supported by `sourcescan/cargo-near:0.10.1-rust-1.82.0` image or later images
2424
passed_env = []
25-
# build command inside of docker container
25+
# build command inside of docker container
2626
# if docker image from default gallery is used https://hub.docker.com/r/sourcescan/cargo-near/tags,
2727
# the command may be any combination of flags of `cargo-near`,
2828
# supported by respective version of binary inside the container besides `--no-locked` flag
@@ -37,6 +37,7 @@ near-sdk = { version = "5.6", features = ["unit-testing"] }
3737
near-workspaces = { version = "0.15", features = ["unstable"] }
3838
tokio = { version = "1.12.0", features = ["full"] }
3939
serde_json = "1"
40+
chrono = "0.4.40"
4041

4142
[profile.release]
4243
codegen-units = 1

README.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1 @@
11
# claim-protocol
2-
3-
cargo-near-new-project-description
4-
5-
## How to Build Locally?
6-
7-
Install [`cargo-near`](https://github.com/near/cargo-near) and run:
8-
9-
```bash
10-
cargo near build
11-
```
12-
13-
## How to Test Locally?
14-
15-
```bash
16-
cargo test
17-
```
18-
19-
## How to Deploy?
20-
21-
Deployment is automated with GitHub Actions CI/CD pipeline.
22-
To deploy manually, install [`cargo-near`](https://github.com/near/cargo-near) and run:
23-
24-
```bash
25-
cargo near deploy <account-id>
26-
```
27-
28-
## Useful Links
29-
30-
- [cargo-near](https://github.com/near/cargo-near) - NEAR smart contract development toolkit for Rust
31-
- [near CLI](https://near.cli.rs) - Interact with NEAR blockchain from command line
32-
- [NEAR Rust SDK Documentation](https://docs.near.org/sdk/rust/introduction)
33-
- [NEAR Documentation](https://docs.near.org)
34-
- [NEAR StackOverflow](https://stackoverflow.com/questions/tagged/nearprotocol)
35-
- [NEAR Discord](https://near.chat)
36-
- [NEAR Telegram Developers Community Group](https://t.me/neardev)
37-
- NEAR DevHub: [Telegram](https://t.me/neardevhub), [Twitter](https://twitter.com/neardevhub)

src/claim.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use crate::*;
2+
3+
#[near(serializers=[borsh, json])]
4+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
5+
pub enum ClaimType {
6+
Near,
7+
FungibleToken {
8+
contract_id: AccountId,
9+
},
10+
NonFungibleToken {
11+
contract_id: AccountId,
12+
token_id: String,
13+
},
14+
}
15+
16+
#[near(serializers=[borsh, json])]
17+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
18+
pub struct Claim {
19+
pub claim_type: ClaimType,
20+
pub amount: u128, // For NEAR and FTs. Ignored for NFTs
21+
pub tipper: AccountId,
22+
pub timestamp: u64,
23+
pub expires_at: u64,
24+
pub claimed: bool,
25+
}
26+
27+
impl Claim {
28+
pub fn new_near(tipper: AccountId, amount: u128) -> Self {
29+
Self {
30+
claim_type: ClaimType::Near,
31+
amount,
32+
tipper,
33+
timestamp: env::block_timestamp(),
34+
expires_at: env::block_timestamp() + crate::CLAIM_EXPIRATION_PERIOD,
35+
claimed: false,
36+
}
37+
}
38+
39+
pub fn new_ft(tipper: AccountId, contract_id: AccountId, amount: u128) -> Self {
40+
Self {
41+
claim_type: ClaimType::FungibleToken { contract_id },
42+
amount,
43+
tipper,
44+
timestamp: env::block_timestamp(),
45+
expires_at: env::block_timestamp() + crate::CLAIM_EXPIRATION_PERIOD,
46+
claimed: false,
47+
}
48+
}
49+
50+
pub fn new_nft(tipper: AccountId, contract_id: AccountId, token_id: String) -> Self {
51+
Self {
52+
claim_type: ClaimType::NonFungibleToken {
53+
contract_id,
54+
token_id,
55+
},
56+
amount: 0, // Not used for NFTs
57+
tipper,
58+
timestamp: env::block_timestamp(),
59+
expires_at: env::block_timestamp() + crate::CLAIM_EXPIRATION_PERIOD,
60+
claimed: false,
61+
}
62+
}
63+
64+
pub fn is_expired(&self) -> bool {
65+
env::block_timestamp() >= self.expires_at
66+
}
67+
68+
pub fn amount(&self) -> u128 {
69+
self.amount
70+
}
71+
72+
pub fn tipper(&self) -> &AccountId {
73+
&self.tipper
74+
}
75+
76+
pub fn token_type(&self) -> &str {
77+
match &self.claim_type {
78+
ClaimType::Near => "NEAR",
79+
ClaimType::FungibleToken { .. } => "FT",
80+
ClaimType::NonFungibleToken { .. } => "NFT",
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)