Skip to content

Commit

Permalink
feat(storage): persist bucket owner address
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Mar 7, 2023
1 parent 262f15e commit 758ed9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions contracts/cw-storage/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
let bucket = Bucket::new(msg.bucket, msg.limits.into())?;
let bucket = Bucket::new(info.sender, msg.bucket, msg.limits.into())?;

set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
BUCKET.save(deps.storage, &bucket)?;
Expand Down Expand Up @@ -191,6 +191,12 @@ mod tests {
let res = query(deps.as_ref(), mock_env(), QueryMsg::Bucket {}).unwrap();
let value: BucketResponse = from_binary(&res).unwrap();
assert_eq!("foo", value.name);

// check internal state too
let bucket = BUCKET.load(&deps.storage).unwrap();
assert_eq!("creator", bucket.owner.into_string());
assert_eq!(Uint128::zero(), bucket.stat.size);
assert_eq!(Uint128::zero(), bucket.stat.object_count);
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion contracts/cw-storage/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub const DATA: Map<String, Vec<u8>> = Map::new("DATA");

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Bucket {
/// The owner of the bucket.
pub owner: Addr,
/// The name of the bucket.
pub name: String,
/// The limits of the bucket.
Expand All @@ -27,13 +29,14 @@ pub struct BucketStat {
}

impl Bucket {
pub fn new(name: String, limits: Limits) -> Result<Self, BucketError> {
pub fn new(owner: Addr, name: String, limits: Limits) -> Result<Self, BucketError> {
let n: String = name.split_whitespace().collect();
if n.is_empty() {
return Err(EmptyName);
}

Ok(Self {
owner,
name: n,
limits,
stat: BucketStat {
Expand Down

0 comments on commit 758ed9a

Please sign in to comment.