Skip to content

Commit 2fd1b18

Browse files
committed
feat: implement airdrop108 in ic_panda_luckypool
1 parent b9e7743 commit 2fd1b18

File tree

12 files changed

+520
-83
lines changed

12 files changed

+520
-83
lines changed

Cargo.lock

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli_airdrop/src/block.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,7 @@ impl<'a> Iterator for BlocksIter<'a> {
232232
}
233233
}
234234

235-
if let Some(block) = self.blocks.remove(&index) {
236-
Some((index, block))
237-
} else {
238-
None
239-
}
235+
self.blocks.remove(&index).map(|block| (index, block))
240236
}
241237
}
242238

src/cli_airdrop/src/main.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use clap::{Parser, Subcommand};
44
use ic_agent::identity::AnonymousIdentity;
55
use ic_icrc1::Operation;
66
use icrc_ledger_types::icrc1::account::Account;
7-
use num_traits::{cast::ToPrimitive, Saturating};
7+
use num_traits::cast::ToPrimitive;
88
use serde::{Deserialize, Serialize};
99
use serde_bytes::{ByteArray, ByteBuf};
1010
use sha2::Digest;
11+
use std::fmt::Write;
1112
use std::{
1213
collections::BTreeMap,
1314
time::{SystemTime, UNIX_EPOCH},
@@ -47,6 +48,15 @@ pub struct Cli {
4748

4849
#[derive(Subcommand)]
4950
pub enum Commands {
51+
Blob {
52+
/// file path to read
53+
#[arg(long)]
54+
path: String,
55+
56+
/// file path to write
57+
#[arg(long)]
58+
output: Option<String>,
59+
},
5060
Neurons {},
5161
Ledger {
5262
/// blocks store directory
@@ -60,6 +70,7 @@ pub enum Commands {
6070
},
6171
}
6272

73+
// cargo run -p cli_airdrop -- blob --path ./debug/ledger_airdrops_1730272519.cbor.7c054a384a1db11259b9451b172b8c8eedc01144e448d802c686f9bbd1f47381
6374
// cargo run -p cli_airdrop -- neurons
6475
// cargo run -p cli_airdrop -- sync --store ./debug/panda_blocks
6576
// cargo run -p cli_airdrop -- ledger --store ./debug/panda_blocks
@@ -73,6 +84,27 @@ async fn main() -> Result<(), String> {
7384
let snapshot = SNAPSHOT_TIME.min(now);
7485

7586
match &cli.command {
87+
Some(Commands::Blob { path, output }) => match std::fs::read(path) {
88+
Ok(data) => {
89+
let s = data.iter().fold(String::new(), |mut output, b| {
90+
let _ = write!(output, "\\{b:02x}");
91+
output
92+
});
93+
// candid blob:
94+
let s = format!("blob \"{}\"", s);
95+
match output {
96+
Some(output) => {
97+
std::fs::write(output, s.as_bytes()).map_err(format_error)?;
98+
}
99+
None => {
100+
println!("{}", s);
101+
}
102+
}
103+
}
104+
Err(err) => {
105+
return Err(format!("{:?}", err));
106+
}
107+
},
76108
Some(Commands::Neurons {}) => {
77109
let cli = NeuronAgent {
78110
agent,
@@ -112,7 +144,7 @@ async fn main() -> Result<(), String> {
112144
total_e8s += amount;
113145
airdrops
114146
.entry(principal)
115-
.or_insert_with(|| vec![])
147+
.or_default()
116148
.push(Airdrop(amount, None, Some(neuron_id)));
117149
}
118150
}
@@ -223,8 +255,8 @@ async fn main() -> Result<(), String> {
223255
));
224256
total_e8s += *amount;
225257
airdrops
226-
.entry(account.owner.clone())
227-
.or_insert_with(|| vec![])
258+
.entry(account.owner)
259+
.or_default()
228260
.push(Airdrop(
229261
*amount,
230262
account.subaccount.map(ByteArray::from),

src/ic_message_profile/src/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub mod profile {
218218
let mut m = r.borrow_mut();
219219
match m.get(&user) {
220220
None => Err("profile not found".to_string()),
221-
Some(mut p) => f(&mut p).inspect(|r| {
221+
Some(mut p) => f(&mut p).inspect(|_r| {
222222
m.insert(user, p);
223223
}),
224224
}

src/ic_panda_luckypool/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ ic-cdk = { workspace = true }
2626
ic-cdk-timers = { workspace = true }
2727
ic-stable-structures = { workspace = true }
2828
icrc-ledger-types = { workspace = true }
29-
ic-ledger-types = "0.13"
3029
once_cell = "1.19"
3130
scopeguard = "1.2"
3231
finl_unicode = "1.2"

src/ic_panda_luckypool/ic_panda_luckypool.did

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ type AddPrizeInputV2 = record {
1111
quantity : nat16;
1212
expire : nat16;
1313
};
14+
type Airdrop = record {
15+
weight : nat64;
16+
subaccount : opt text;
17+
neuron_id : opt text;
18+
};
1419
type AirdropClaimInput = record {
1520
recaptcha : opt text;
1621
challenge : text;
@@ -40,6 +45,21 @@ type AirdropStateOutput = record {
4045
claimed : nat;
4146
claimable : nat;
4247
};
48+
type Airdrops108Output = record {
49+
status : int8;
50+
ledger_updated_at : nat64;
51+
airdrops : vec Airdrop;
52+
ledger_weight_total : nat64;
53+
tokens_per_weight : float64;
54+
error : opt text;
55+
neurons_hash : text;
56+
neurons_airdropped : bool;
57+
ledger_hash : text;
58+
tokens_distributed : nat64;
59+
neurons_weight_total : nat64;
60+
neurons_updated_at : nat64;
61+
ledger_airdropped : bool;
62+
};
4363
type CaptchaOutput = record { challenge : text; img_base64 : text };
4464
type ClaimPrizeInput = record { challenge : blob; code : text };
4565
type ClaimPrizeOutput = record {
@@ -102,18 +122,21 @@ type PrizeOutput = record {
102122
};
103123
type Result = variant { Ok : PrizeOutput; Err : text };
104124
type Result_1 = variant { Ok; Err : text };
105-
type Result_10 = variant { Ok : NameOutput; Err : text };
106-
type Result_11 = variant { Ok : State; Err };
107-
type Result_12 = variant { Ok : nat; Err : text };
108-
type Result_13 = variant { Ok : principal; Err };
125+
type Result_10 = variant { Ok : nat64; Err : text };
126+
type Result_11 = variant { Ok : opt NameOutput; Err };
127+
type Result_12 = variant { Ok : principal; Err : text };
128+
type Result_13 = variant { Ok : NameOutput; Err : text };
129+
type Result_14 = variant { Ok : State; Err };
130+
type Result_15 = variant { Ok : nat; Err : text };
131+
type Result_16 = variant { Ok : principal; Err };
109132
type Result_2 = variant { Ok : AirdropStateOutput; Err : text };
110133
type Result_3 = variant { Ok : AirdropStateOutput; Err };
111-
type Result_4 = variant { Ok : CaptchaOutput; Err : text };
112-
type Result_5 = variant { Ok : ClaimPrizeOutput; Err : text };
113-
type Result_6 = variant { Ok : LuckyDrawOutput; Err : text };
114-
type Result_7 = variant { Ok : text; Err : text };
115-
type Result_8 = variant { Ok : opt NameOutput; Err };
116-
type Result_9 = variant { Ok : principal; Err : text };
134+
type Result_4 = variant { Ok : Airdrops108Output; Err };
135+
type Result_5 = variant { Ok : CaptchaOutput; Err : text };
136+
type Result_6 = variant { Ok : ClaimPrizeOutput; Err : text };
137+
type Result_7 = variant { Ok : LuckyDrawOutput; Err : text };
138+
type Result_8 = variant { Ok : text; Err : text };
139+
type Result_9 = variant { Ok : bool; Err : text };
117140
type State = record {
118141
latest_luckydraw_logs : vec LuckyDrawLog;
119142
total_luckydraw : nat64;
@@ -135,34 +158,39 @@ type State = record {
135158
service : () -> {
136159
add_prize : (AddPrizeInputV2) -> (Result);
137160
admin_collect_icp : (nat) -> (Result_1);
161+
admin_collect_tokens : (nat) -> (Result_1);
138162
admin_set_managers : (vec principal) -> (Result_1);
139163
airdrop : (AirdropClaimInput) -> (Result_2);
140164
airdrop_codes_of : (principal) -> (vec AirdropCodeOutput) query;
141165
airdrop_logs : (opt nat, opt nat) -> (vec AirdropLog) query;
142166
airdrop_state_of : (opt principal) -> (Result_3) query;
167+
airdrops108_of : (opt principal) -> (Result_4) query;
143168
api_version : () -> (nat16) query;
144-
captcha : () -> (Result_4);
145-
claim_prize : (ClaimPrizeInput) -> (Result_5);
169+
captcha : () -> (Result_5);
170+
claim_prize : (ClaimPrizeInput) -> (Result_6);
146171
harvest : (AirdropHarvestInput) -> (Result_2);
147-
luckydraw : (LuckyDrawInput) -> (Result_6);
172+
luckydraw : (LuckyDrawInput) -> (Result_7);
148173
luckydraw_logs : (opt nat, opt nat) -> (vec LuckyDrawLog) query;
149174
manager_add_notification : (Notification) -> (Result_1);
150-
manager_add_prize : (AddPrizeInput) -> (Result_7);
151-
manager_add_prize_v2 : (AddPrizeInputV2) -> (Result_7);
175+
manager_add_prize : (AddPrizeInput) -> (Result_8);
176+
manager_add_prize_v2 : (AddPrizeInputV2) -> (Result_8);
152177
manager_ban_users : (vec principal) -> (Result_1);
153-
manager_get_airdrop_key : () -> (Result_7) query;
178+
manager_get_airdrop_key : () -> (Result_8) query;
154179
manager_remove_notifications : (blob) -> (Result_1);
155180
manager_set_challenge_pub_key : (text) -> (Result_1);
181+
manager_start_airdrops108 : () -> (Result_9);
156182
manager_update_airdrop_amount : (nat64) -> (Result_1);
157183
manager_update_airdrop_balance : (nat64) -> (Result_1);
184+
manager_update_airdrops108_ledger_list : (blob) -> (Result_10);
185+
manager_update_airdrops108_neurons_list : (blob) -> (Result_10);
158186
manager_update_prize_subsidy : (
159187
opt record { nat64; nat16; nat32; nat8; nat32; nat16 },
160188
) -> (Result_1);
161189
my_luckydraw_logs : (opt nat, opt nat) -> (vec LuckyDrawLog) query;
162-
name_lookup : (text) -> (Result_8) query;
163-
name_of : (opt principal) -> (Result_8) query;
190+
name_lookup : (text) -> (Result_11) query;
191+
name_of : (opt principal) -> (Result_11) query;
164192
notifications : () -> (vec Notification) query;
165-
principal_by_luckycode : (text) -> (Result_9) query;
193+
principal_by_luckycode : (text) -> (Result_12) query;
166194
prize : (text) -> (Result_2);
167195
prize_claim_logs : (principal, opt nat, opt nat) -> (vec PrizeClaimLog) query;
168196
prize_info : (text, opt principal) -> (Result) query;
@@ -171,13 +199,14 @@ service : () -> {
171199
prizes_of : (opt principal) -> (
172200
vec record { nat32; nat32; nat16; nat32; nat16; nat16 },
173201
) query;
174-
register_name : (NameInput) -> (Result_10);
175-
state : () -> (Result_11) query;
176-
unregister_name : (NameInput) -> (Result_12);
177-
update_name : (NameInput) -> (Result_10);
178-
validate2_admin_collect_icp : (nat) -> (Result_7);
179-
validate2_admin_set_managers : (vec principal) -> (Result_7);
202+
register_name : (NameInput) -> (Result_13);
203+
state : () -> (Result_14) query;
204+
unregister_name : (NameInput) -> (Result_15);
205+
update_name : (NameInput) -> (Result_13);
206+
validate2_admin_collect_icp : (nat) -> (Result_8);
207+
validate2_admin_set_managers : (vec principal) -> (Result_8);
180208
validate_admin_collect_icp : (nat) -> (Result_1);
209+
validate_admin_collect_tokens : (nat) -> (Result_8);
181210
validate_admin_set_managers : (vec principal) -> (Result_1);
182-
whoami : () -> (Result_13) query;
211+
whoami : () -> (Result_16) query;
183212
}

0 commit comments

Comments
 (0)