app store fixes

This commit is contained in:
dr-frmr 2024-05-08 12:59:05 -06:00
parent 11f6fb26f2
commit b79c9535df
No known key found for this signature in database
5 changed files with 63 additions and 26 deletions

38
Cargo.lock generated
View File

@ -3084,7 +3084,7 @@ dependencies = [
"hmac",
"http 1.1.0",
"jwt",
"kit",
"kit 0.3.1 (git+https://github.com/kinode-dao/kit?rev=25b474a)",
"lazy_static",
"lib",
"log",
@ -3215,6 +3215,40 @@ dependencies = [
"wit-bindgen",
]
[[package]]
name = "kit"
version = "0.3.1"
source = "git+https://github.com/kinode-dao/kit?rev=25b474a#25b474abec180f6ae63b3f2c13f459a180b5be73"
dependencies = [
"anyhow",
"base64 0.21.7",
"clap",
"color-eyre",
"dirs 5.0.1",
"fs-err",
"futures-util",
"git2",
"hex",
"kinode_process_lib 0.6.0",
"nix",
"regex",
"reqwest 0.11.27",
"rmp-serde",
"semver 1.0.22",
"serde",
"serde_json",
"thiserror",
"tokio",
"tokio-tungstenite 0.20.1",
"toml",
"tracing",
"tracing-appender",
"tracing-error",
"tracing-subscriber",
"walkdir",
"zip 0.6.6",
]
[[package]]
name = "kit"
version = "0.3.1"
@ -3289,7 +3323,7 @@ version = "0.7.2"
dependencies = [
"alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=6f8ebb4)",
"anyhow",
"kit",
"kit 0.3.1 (git+https://github.com/kinode-dao/kit?rev=659f59e)",
"lazy_static",
"rand 0.8.5",
"reqwest 0.12.4",

View File

@ -218,9 +218,20 @@ fn init(our: Address) {
.send()
.unwrap();
// load in our saved state or initalize a new one if none exists
let mut state = get_typed_state(|bytes| Ok(bincode::deserialize(bytes)?))
.unwrap_or(State::new(CONTRACT_ADDRESS.to_string()).unwrap());
let mut state: State = match get_typed_state(|bytes| Ok(bincode::deserialize::<State>(bytes)?))
{
Some(state) => {
println!("loaded saved state");
state
}
_ => {
println!("failed to load state, initializing");
State::new(CONTRACT_ADDRESS.to_string()).unwrap()
}
};
// // load in our saved state or initalize a new one if none exists
// let mut state = get_typed_state(|bytes| Ok(bincode::deserialize(bytes)?))
// .unwrap_or(State::new(CONTRACT_ADDRESS.to_string()).unwrap());
if state.contract_address != CONTRACT_ADDRESS {
println!("warning: contract address mismatch--overwriting saved state");
@ -532,12 +543,14 @@ pub fn rebuild_index(
.from_block(state.last_saved_block - 1)
.events(EVENTS);
subscribe_to_logs(&eth_provider, filter.clone());
for log in fetch_logs(&eth_provider, &filter) {
if let Err(e) = state.ingest_listings_contract_event(our, log) {
println!("error ingesting log: {e:?}");
};
}
subscribe_to_logs(&eth_provider, filter);
LocalResponse::RebuiltIndex
}

View File

@ -73,6 +73,9 @@ pub struct PackageState {
pub installed: bool,
pub verified: bool,
pub caps_approved: bool,
/// the hash of the manifest file, which is used to determine whether package
/// capabilities have changed. if they have changed, auto-install must fail
/// and the user must approve the new capabilities.
pub manifest_hash: Option<String>,
/// are we serving this package to others?
pub mirroring: bool,
@ -360,7 +363,7 @@ impl State {
Ok(())
}
/// only saves state if last_saved_block is more than 1000 blocks behind
/// saves state
pub fn ingest_listings_contract_event(
&mut self,
our: &Address,
@ -518,10 +521,8 @@ impl State {
}
_ => {}
}
if block_number > self.last_saved_block + 1000 {
self.last_saved_block = block_number;
crate::set_state(&bincode::serialize(self)?);
}
self.last_saved_block = block_number;
crate::set_state(&bincode::serialize(self)?);
Ok(())
}
}

View File

@ -1,18 +1,4 @@
[
{
"chain_id": 1,
"trusted": false,
"provider": {
"RpcUrl": "wss://ethereum.publicnode.com"
}
},
{
"chain_id": 10,
"trusted": false,
"provider": {
"RpcUrl": "wss://optimism-rpc.publicnode.com"
}
},
{
"chain_id": 1,
"trusted": false,

View File

@ -391,7 +391,10 @@ async fn handle_message(
}
verbose_print(
&state.print_tx,
"eth: got sub_keepalive but no matching sub found",
&format!(
"eth: got sub_keepalive from {} but no matching sub found",
km.source
),
)
.await;
// send a response with an EthSubError