Skip to content

Commit

Permalink
feat(storage): add cursor bs58 encoding helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Mar 9, 2023
1 parent aa09eb3 commit 1e7c2bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions contracts/cw-storage/src/cursor.rs
Original file line number Diff line number Diff line change
@@ -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<Cursor> {
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))
}
1 change: 1 addition & 0 deletions contracts/cw-storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod contract;
pub mod crypto;
mod cursor;
mod error;
pub mod msg;
pub mod state;
Expand Down

0 comments on commit 1e7c2bc

Please sign in to comment.