1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
use crate::cosmos::Cosmos;
use crate::lcd::Lcd;
use crate::query::contract::ItemOrMap;
use query::contract::Contract;
use serde::{Serialize, Deserialize};
use std::collections::HashMap;
use std::io;
use csv::Writer;
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub struct Deck {
pub name: String,
pub id: u64,
pub nfts: Vec<String>,
}
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub struct CosmonStats {
pub key: String,
pub value: String,
}
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum XpQuery {
GetCosmonsStats { nfts: Vec<String> },
}
pub struct DeckExtended {
pub(crate) name: String,
pub(crate) id: u64,
pub(crate) nfts: Vec<CosmonStats>,
}
fn main() -> Result<(), anyhow::Error> {
env_logger::init();
let mut wtr = Writer::from_path("cosmon_decks.csv")?;
wtr.write_record(&["DeckID", "DeckName", "Ap", "Level", "Fp", "Xp", "Hp", "Spe", "Atq", "Luk", "Def", "Int", "Time", "Geographical", "Personality"])?;
let lcd = Lcd::new("https://api-kichain-ia.cosmosia.notional.ventures/".to_string())?;
let cosmos = Cosmos::new(&lcd);
let contract = Contract::new(
cosmos,
"ki1mf6ptkssddfmxvhdx0ech0k03ktp6kf9yk59renau2gvht3nq2gqw2adht".to_string(),
)?;
let cosmos = Cosmos::new(&lcd);
let mut decks_extended: Vec<DeckExtended> = vec![];
let entry = contract.state.get("DECKS").unwrap();
if let ItemOrMap::Map { map } = entry {
for (key, val) in map {
let deck: Deck = serde_json::from_str(val)?;
let new_deck = DeckExtended {
name: deck.name.to_string(),
id: deck.id,
nfts: vec![],
};
let stats: Vec<Vec<CosmonStats>> = cosmos.wasm.query_smart(
"ki1pu52z9aumq56s5gdg2ve2ahmr4fslnt27qztld83ng07s0ggvk6ste37qj".to_string(),
XpQuery::GetCosmonsStats { nfts: deck.nfts },
)?;
let mut serialize_line = |id, name, nft_stats: Vec<CosmonStats>| -> Result<(), anyhow::Error> {
wtr.serialize((id, name,
nft_stats.clone().into_iter().find(|x| x.key == "Ap").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Level").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Fp").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Xp").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Hp").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Spe").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Atq").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Luk").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Def").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Int").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Time").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Geographical").unwrap().value,
nft_stats.clone().into_iter().find(|x| x.key == "Personality").unwrap().value))?;
Ok(())
};
serialize_line(deck.id.clone(), deck.name.clone(), stats[0].clone())?;
serialize_line(deck.id.clone(), deck.name.clone(), stats[1].clone())?;
serialize_line(deck.id.clone(), deck.name.clone(), stats[2].clone())?;
log::info!("key {} => {:#?}", key, stats);
}
}
wtr.flush();
Ok(())
}
*/