diff --git a/contracts/cw-storage/src/cursor.rs b/contracts/cw-storage/src/cursor.rs new file mode 100644 index 00000000..6764f1ad --- /dev/null +++ b/contracts/cw-storage/src/cursor.rs @@ -0,0 +1,15 @@ +use crate::msg::{Cursor, ObjectId}; +use crate::ContractError; +use cosmwasm_std::{StdError, StdResult}; + +pub fn encode(id: ObjectId) -> Cursor { + bs58::encode(id).into_string() +} + +pub fn decode(cursor: String) -> StdResult { + let raw = bs58::decode(cursor) + .into_vec() + .map_err(|err| StdError::parse_err("Cursor", err))?; + + String::from_utf8(raw).map_err(|err| StdError::parse_err("Cursor", err)) +} diff --git a/contracts/cw-storage/src/lib.rs b/contracts/cw-storage/src/lib.rs index d838ea40..6d87cde9 100644 --- a/contracts/cw-storage/src/lib.rs +++ b/contracts/cw-storage/src/lib.rs @@ -1,5 +1,6 @@ pub mod contract; pub mod crypto; +mod cursor; mod error; pub mod msg; pub mod state;