Skip to content

Commit

Permalink
feat: implement airdrop108 in ic_panda_luckypool
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Oct 30, 2024
1 parent b9e7743 commit 2fd1b18
Show file tree
Hide file tree
Showing 12 changed files with 520 additions and 83 deletions.
18 changes: 1 addition & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/cli_airdrop/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,7 @@ impl<'a> Iterator for BlocksIter<'a> {
}
}

if let Some(block) = self.blocks.remove(&index) {
Some((index, block))
} else {
None
}
self.blocks.remove(&index).map(|block| (index, block))
}
}

Expand Down
40 changes: 36 additions & 4 deletions src/cli_airdrop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use clap::{Parser, Subcommand};
use ic_agent::identity::AnonymousIdentity;
use ic_icrc1::Operation;
use icrc_ledger_types::icrc1::account::Account;
use num_traits::{cast::ToPrimitive, Saturating};
use num_traits::cast::ToPrimitive;
use serde::{Deserialize, Serialize};
use serde_bytes::{ByteArray, ByteBuf};
use sha2::Digest;
use std::fmt::Write;
use std::{
collections::BTreeMap,
time::{SystemTime, UNIX_EPOCH},
Expand Down Expand Up @@ -47,6 +48,15 @@ pub struct Cli {

#[derive(Subcommand)]
pub enum Commands {
Blob {
/// file path to read
#[arg(long)]
path: String,

/// file path to write
#[arg(long)]
output: Option<String>,
},
Neurons {},
Ledger {
/// blocks store directory
Expand All @@ -60,6 +70,7 @@ pub enum Commands {
},
}

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

match &cli.command {
Some(Commands::Blob { path, output }) => match std::fs::read(path) {
Ok(data) => {
let s = data.iter().fold(String::new(), |mut output, b| {
let _ = write!(output, "\\{b:02x}");
output
});
// candid blob:
let s = format!("blob \"{}\"", s);
match output {
Some(output) => {
std::fs::write(output, s.as_bytes()).map_err(format_error)?;
}
None => {
println!("{}", s);
}
}
}
Err(err) => {
return Err(format!("{:?}", err));
}
},
Some(Commands::Neurons {}) => {
let cli = NeuronAgent {
agent,
Expand Down Expand Up @@ -112,7 +144,7 @@ async fn main() -> Result<(), String> {
total_e8s += amount;
airdrops
.entry(principal)
.or_insert_with(|| vec![])
.or_default()
.push(Airdrop(amount, None, Some(neuron_id)));
}
}
Expand Down Expand Up @@ -223,8 +255,8 @@ async fn main() -> Result<(), String> {
));
total_e8s += *amount;
airdrops
.entry(account.owner.clone())
.or_insert_with(|| vec![])
.entry(account.owner)
.or_default()
.push(Airdrop(
*amount,
account.subaccount.map(ByteArray::from),
Expand Down
2 changes: 1 addition & 1 deletion src/ic_message_profile/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub mod profile {
let mut m = r.borrow_mut();
match m.get(&user) {
None => Err("profile not found".to_string()),
Some(mut p) => f(&mut p).inspect(|r| {
Some(mut p) => f(&mut p).inspect(|_r| {
m.insert(user, p);
}),
}
Expand Down
1 change: 0 additions & 1 deletion src/ic_panda_luckypool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ ic-cdk = { workspace = true }
ic-cdk-timers = { workspace = true }
ic-stable-structures = { workspace = true }
icrc-ledger-types = { workspace = true }
ic-ledger-types = "0.13"
once_cell = "1.19"
scopeguard = "1.2"
finl_unicode = "1.2"
Expand Down
81 changes: 55 additions & 26 deletions src/ic_panda_luckypool/ic_panda_luckypool.did
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ type AddPrizeInputV2 = record {
quantity : nat16;
expire : nat16;
};
type Airdrop = record {
weight : nat64;
subaccount : opt text;
neuron_id : opt text;
};
type AirdropClaimInput = record {
recaptcha : opt text;
challenge : text;
Expand Down Expand Up @@ -40,6 +45,21 @@ type AirdropStateOutput = record {
claimed : nat;
claimable : nat;
};
type Airdrops108Output = record {
status : int8;
ledger_updated_at : nat64;
airdrops : vec Airdrop;
ledger_weight_total : nat64;
tokens_per_weight : float64;
error : opt text;
neurons_hash : text;
neurons_airdropped : bool;
ledger_hash : text;
tokens_distributed : nat64;
neurons_weight_total : nat64;
neurons_updated_at : nat64;
ledger_airdropped : bool;
};
type CaptchaOutput = record { challenge : text; img_base64 : text };
type ClaimPrizeInput = record { challenge : blob; code : text };
type ClaimPrizeOutput = record {
Expand Down Expand Up @@ -102,18 +122,21 @@ type PrizeOutput = record {
};
type Result = variant { Ok : PrizeOutput; Err : text };
type Result_1 = variant { Ok; Err : text };
type Result_10 = variant { Ok : NameOutput; Err : text };
type Result_11 = variant { Ok : State; Err };
type Result_12 = variant { Ok : nat; Err : text };
type Result_13 = variant { Ok : principal; Err };
type Result_10 = variant { Ok : nat64; Err : text };
type Result_11 = variant { Ok : opt NameOutput; Err };
type Result_12 = variant { Ok : principal; Err : text };
type Result_13 = variant { Ok : NameOutput; Err : text };
type Result_14 = variant { Ok : State; Err };
type Result_15 = variant { Ok : nat; Err : text };
type Result_16 = variant { Ok : principal; Err };
type Result_2 = variant { Ok : AirdropStateOutput; Err : text };
type Result_3 = variant { Ok : AirdropStateOutput; Err };
type Result_4 = variant { Ok : CaptchaOutput; Err : text };
type Result_5 = variant { Ok : ClaimPrizeOutput; Err : text };
type Result_6 = variant { Ok : LuckyDrawOutput; Err : text };
type Result_7 = variant { Ok : text; Err : text };
type Result_8 = variant { Ok : opt NameOutput; Err };
type Result_9 = variant { Ok : principal; Err : text };
type Result_4 = variant { Ok : Airdrops108Output; Err };
type Result_5 = variant { Ok : CaptchaOutput; Err : text };
type Result_6 = variant { Ok : ClaimPrizeOutput; Err : text };
type Result_7 = variant { Ok : LuckyDrawOutput; Err : text };
type Result_8 = variant { Ok : text; Err : text };
type Result_9 = variant { Ok : bool; Err : text };
type State = record {
latest_luckydraw_logs : vec LuckyDrawLog;
total_luckydraw : nat64;
Expand All @@ -135,34 +158,39 @@ type State = record {
service : () -> {
add_prize : (AddPrizeInputV2) -> (Result);
admin_collect_icp : (nat) -> (Result_1);
admin_collect_tokens : (nat) -> (Result_1);
admin_set_managers : (vec principal) -> (Result_1);
airdrop : (AirdropClaimInput) -> (Result_2);
airdrop_codes_of : (principal) -> (vec AirdropCodeOutput) query;
airdrop_logs : (opt nat, opt nat) -> (vec AirdropLog) query;
airdrop_state_of : (opt principal) -> (Result_3) query;
airdrops108_of : (opt principal) -> (Result_4) query;
api_version : () -> (nat16) query;
captcha : () -> (Result_4);
claim_prize : (ClaimPrizeInput) -> (Result_5);
captcha : () -> (Result_5);
claim_prize : (ClaimPrizeInput) -> (Result_6);
harvest : (AirdropHarvestInput) -> (Result_2);
luckydraw : (LuckyDrawInput) -> (Result_6);
luckydraw : (LuckyDrawInput) -> (Result_7);
luckydraw_logs : (opt nat, opt nat) -> (vec LuckyDrawLog) query;
manager_add_notification : (Notification) -> (Result_1);
manager_add_prize : (AddPrizeInput) -> (Result_7);
manager_add_prize_v2 : (AddPrizeInputV2) -> (Result_7);
manager_add_prize : (AddPrizeInput) -> (Result_8);
manager_add_prize_v2 : (AddPrizeInputV2) -> (Result_8);
manager_ban_users : (vec principal) -> (Result_1);
manager_get_airdrop_key : () -> (Result_7) query;
manager_get_airdrop_key : () -> (Result_8) query;
manager_remove_notifications : (blob) -> (Result_1);
manager_set_challenge_pub_key : (text) -> (Result_1);
manager_start_airdrops108 : () -> (Result_9);
manager_update_airdrop_amount : (nat64) -> (Result_1);
manager_update_airdrop_balance : (nat64) -> (Result_1);
manager_update_airdrops108_ledger_list : (blob) -> (Result_10);
manager_update_airdrops108_neurons_list : (blob) -> (Result_10);
manager_update_prize_subsidy : (
opt record { nat64; nat16; nat32; nat8; nat32; nat16 },
) -> (Result_1);
my_luckydraw_logs : (opt nat, opt nat) -> (vec LuckyDrawLog) query;
name_lookup : (text) -> (Result_8) query;
name_of : (opt principal) -> (Result_8) query;
name_lookup : (text) -> (Result_11) query;
name_of : (opt principal) -> (Result_11) query;
notifications : () -> (vec Notification) query;
principal_by_luckycode : (text) -> (Result_9) query;
principal_by_luckycode : (text) -> (Result_12) query;
prize : (text) -> (Result_2);
prize_claim_logs : (principal, opt nat, opt nat) -> (vec PrizeClaimLog) query;
prize_info : (text, opt principal) -> (Result) query;
Expand All @@ -171,13 +199,14 @@ service : () -> {
prizes_of : (opt principal) -> (
vec record { nat32; nat32; nat16; nat32; nat16; nat16 },
) query;
register_name : (NameInput) -> (Result_10);
state : () -> (Result_11) query;
unregister_name : (NameInput) -> (Result_12);
update_name : (NameInput) -> (Result_10);
validate2_admin_collect_icp : (nat) -> (Result_7);
validate2_admin_set_managers : (vec principal) -> (Result_7);
register_name : (NameInput) -> (Result_13);
state : () -> (Result_14) query;
unregister_name : (NameInput) -> (Result_15);
update_name : (NameInput) -> (Result_13);
validate2_admin_collect_icp : (nat) -> (Result_8);
validate2_admin_set_managers : (vec principal) -> (Result_8);
validate_admin_collect_icp : (nat) -> (Result_1);
validate_admin_collect_tokens : (nat) -> (Result_8);
validate_admin_set_managers : (vec principal) -> (Result_1);
whoami : () -> (Result_13) query;
whoami : () -> (Result_16) query;
}
Loading

0 comments on commit 2fd1b18

Please sign in to comment.