generated from okp4/template-rust
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): add cursor bs58 encoding helpers
- Loading branch information
Showing
2 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|