Skip to content

Commit 246ecf1

Browse files
committed
initial testnet deploy
1 parent 74110d5 commit 246ecf1

4 files changed

Lines changed: 167 additions & 53 deletions

File tree

src/claim.rs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,50 @@ pub enum ClaimType {
1717
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
1818
pub struct Claim {
1919
pub claim_type: ClaimType,
20-
pub amount: u128, // For NEAR and FTs. Ignored for NFTs
20+
pub amount: NearToken, // For NEAR and FTs. Ignored for NFTs
2121
pub tipper: AccountId,
2222
pub timestamp: u64,
2323
pub expires_at: u64,
2424
pub claimed: bool,
2525
}
2626

27+
#[near(serializers=[borsh, json])]
28+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
29+
pub struct ClaimExternal {
30+
pub id: ClaimId,
31+
pub claim_type: String,
32+
pub amount: U128, // For NEAR and FTs. Ignored for NFTs
33+
pub tipper: AccountId,
34+
pub timestamp: u64,
35+
pub expires_at: u64,
36+
pub claimed: bool,
37+
}
38+
39+
pub(crate) fn format_claim(claim_id: &ClaimId, claim: &Claim) -> ClaimExternal {
40+
let claim_type = match &claim.claim_type {
41+
ClaimType::Near => "Near".to_string(),
42+
ClaimType::FungibleToken { contract_id } => format!("FT({})", contract_id),
43+
ClaimType::NonFungibleToken {
44+
contract_id,
45+
token_id,
46+
} => format!("NFT({}, {})", contract_id, token_id),
47+
};
48+
ClaimExternal {
49+
id: claim_id.clone(),
50+
claim_type,
51+
amount: claim.amount.as_yoctonear().into(),
52+
tipper: claim.tipper.clone(),
53+
timestamp: claim.timestamp,
54+
expires_at: claim.expires_at,
55+
claimed: claim.claimed,
56+
}
57+
}
58+
2759
impl Claim {
2860
pub fn new_near(tipper: AccountId, amount: u128) -> Self {
2961
Self {
3062
claim_type: ClaimType::Near,
31-
amount,
63+
amount: NearToken::from_yoctonear(amount),
3264
tipper,
3365
timestamp: env::block_timestamp(),
3466
expires_at: env::block_timestamp() + crate::CLAIM_EXPIRATION_PERIOD,
@@ -39,7 +71,7 @@ impl Claim {
3971
pub fn new_ft(tipper: AccountId, contract_id: AccountId, amount: u128) -> Self {
4072
Self {
4173
claim_type: ClaimType::FungibleToken { contract_id },
42-
amount,
74+
amount: NearToken::from_yoctonear(amount),
4375
tipper,
4476
timestamp: env::block_timestamp(),
4577
expires_at: env::block_timestamp() + crate::CLAIM_EXPIRATION_PERIOD,
@@ -53,7 +85,7 @@ impl Claim {
5385
contract_id,
5486
token_id,
5587
},
56-
amount: 0, // Not used for NFTs
88+
amount: NearToken::from_yoctonear(0), // Not used for NFTs
5789
tipper,
5890
timestamp: env::block_timestamp(),
5991
expires_at: env::block_timestamp() + crate::CLAIM_EXPIRATION_PERIOD,
@@ -66,7 +98,7 @@ impl Claim {
6698
}
6799

68100
pub fn amount(&self) -> u128 {
69-
self.amount
101+
self.amount.as_yoctonear()
70102
}
71103

72104
pub fn tipper(&self) -> &AccountId {

src/events.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn log_account_linked_event(platform: &str, handle: &str, account_id: &Accou
2929
pub fn log_tip_transferred_event(
3030
platform: &str,
3131
handle: &str,
32-
amount: u128,
32+
amount: U128,
3333
token_type: &str,
3434
recipient: &AccountId,
3535
) {
@@ -45,7 +45,7 @@ pub fn log_tip_transferred_event(
4545
{
4646
"platform": platform,
4747
"handle": handle,
48-
"amount": amount.to_string(),
48+
"amount": amount,
4949
"token_type": token_type,
5050
"recipient": recipient,
5151
}
@@ -59,7 +59,7 @@ pub fn log_tip_transferred_event(
5959
pub fn log_claim_created_event(
6060
platform: &str,
6161
handle: &str,
62-
amount: u128,
62+
amount: U128,
6363
token_type: &str,
6464
tipper: &AccountId,
6565
) {
@@ -75,7 +75,7 @@ pub fn log_claim_created_event(
7575
{
7676
"platform": platform,
7777
"handle": handle,
78-
"amount": amount.to_string(),
78+
"amount": amount,
7979
"token_type": token_type,
8080
"tipper": tipper,
8181
}
@@ -89,7 +89,7 @@ pub fn log_claim_created_event(
8989
pub fn log_claim_processed_event(
9090
platform: &str,
9191
handle: &str,
92-
amount: u128,
92+
amount: U128,
9393
token_type: &str,
9494
claimer: &AccountId,
9595
) {
@@ -105,7 +105,7 @@ pub fn log_claim_processed_event(
105105
{
106106
"platform": platform,
107107
"handle": handle,
108-
"amount": amount.to_string(),
108+
"amount": amount,
109109
"token_type": token_type,
110110
"claimer": claimer,
111111
}
@@ -119,7 +119,7 @@ pub fn log_claim_processed_event(
119119
pub fn log_tip_reclaimed_event(
120120
platform: &str,
121121
handle: &str,
122-
amount: u128,
122+
amount: U128,
123123
token_type: &str,
124124
tipper: &AccountId,
125125
) {
@@ -135,7 +135,7 @@ pub fn log_tip_reclaimed_event(
135135
{
136136
"platform": platform,
137137
"handle": handle,
138-
"amount": amount.to_string(),
138+
"amount": amount,
139139
"token_type": token_type,
140140
"tipper": tipper,
141141
}

0 commit comments

Comments
 (0)