From 2f48cac20796ed0892823cd33b615d15ffdcab22 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 21 Feb 2023 16:28:49 -0500 Subject: [PATCH] feat: copy `create_ledger_footprint` from CLI This was in the utils.rs file in the cli and should be here --- soroban-env-host/src/storage.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/soroban-env-host/src/storage.rs b/soroban-env-host/src/storage.rs index 0b18b65ba..093e8d47a 100644 --- a/soroban-env-host/src/storage.rs +++ b/soroban-env-host/src/storage.rs @@ -9,6 +9,7 @@ use std::rc::Rc; +use soroban_env_common::xdr::{self, LedgerFootprint}; use soroban_env_common::Compare; use crate::budget::Budget; @@ -116,6 +117,23 @@ impl Footprint { Err(ScHostStorageErrorCode::AccessToUnknownEntry.into()) } } + + pub fn create_ledger_footprint(&self) -> Result { + let mut read_only: Vec = vec![]; + let mut read_write: Vec = vec![]; + let Footprint(m) = self; + for (k, v) in m { + let dest = match v { + AccessType::ReadOnly => &mut read_only, + AccessType::ReadWrite => &mut read_write, + }; + dest.push((**k).clone()); + } + Ok(LedgerFootprint { + read_only: read_only.try_into()?, + read_write: read_write.try_into()?, + }) + } } #[derive(Clone)]