Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.7 Upgrade with Storage and Readme Updates (for Cosmwasm v1.0) #66

Merged
merged 37 commits into from Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3294b0b
fix clippy warnings
srdtrk Sep 16, 2022
2928716
Added Keyset and added option to disable iter to Keymap
srdtrk Sep 18, 2022
e56ff86
updated append_store and improved iterators of appendstore and keymap…
srdtrk Sep 20, 2022
82bbdca
improved iterators of keymap and keyset, added more tests
srdtrk Sep 20, 2022
7b5466b
deque_store updated with custom indexes
srdtrk Sep 21, 2022
3a5b752
added a new test to dequestore
srdtrk Sep 21, 2022
d1ff524
readme and release notes updated + added extra tests to append_store
srdtrk Sep 21, 2022
1ee4242
updated readme and changed WithNoIter to WithoutIter
srdtrk Sep 22, 2022
956bc43
made keymap and keyset share their IterOption types
srdtrk Sep 22, 2022
2b1ba83
split keymap and keyset IterOption types again
srdtrk Sep 22, 2022
23df400
combined keymap and keyset IterOption in a different way
srdtrk Sep 22, 2022
a5190a2
attempt to fix importing issues
srdtrk Sep 22, 2022
75326b0
amother attempt to fix importing issues
srdtrk Sep 22, 2022
14b233b
yet another attempt to fix importing issues
srdtrk Sep 22, 2022
afa30ce
another attempt to fix importing issues
srdtrk Sep 22, 2022
32ac53c
Cashmap removed from incubator readme
srdtrk Sep 22, 2022
51ed87f
Typo fixes for some readme files
srdtrk Sep 22, 2022
3f54283
typo fix in release notes
srdtrk Sep 22, 2022
976aff9
Merge branch 'master' into cw-v1.0-storage
toml01 Oct 27, 2022
619dd27
changed rust back to ignore in readme
srdtrk Oct 29, 2022
88262bf
Merge branch 'cw-v1.0-storage' of https://github.com/srdtrk/secret-to…
srdtrk Oct 29, 2022
39d5bfb
replace more rust with ignore in readme
srdtrk Oct 29, 2022
c3df1ae
added serde test to keymap
srdtrk Nov 11, 2022
5fccc01
remove _ from the start of function names
srdtrk Nov 11, 2022
ec283de
fix some clippy errors
srdtrk Nov 11, 2022
28a3c7a
made all error messages lower case and fixed some error messages
srdtrk Nov 11, 2022
c00e4cf
keymap updated to be more efficient if page_size == 1
srdtrk Nov 11, 2022
c63f1db
made page_size == 1 changes to keyset, appendstore and dequestore as …
srdtrk Nov 24, 2022
e1da71a
saved_indexes renamed to cache
srdtrk Nov 24, 2022
aecffe2
refactored push_back and push_front
srdtrk Nov 24, 2022
1768f47
refactored pop_front and pop_back
srdtrk Nov 24, 2022
355a215
Merge branch 'update-dep-versions' of https://github.com/scrtlabs/sec…
srdtrk Nov 25, 2022
9a00505
Merge branch 'scrtlabs-update-dep-versions' into cw-v1.0-storage
srdtrk Nov 25, 2022
af004a3
renamed Releases.md version to 0.7
srdtrk Nov 25, 2022
2fff51b
merged release notes
srdtrk Dec 6, 2022
fd9204a
accepted master release.md
srdtrk Dec 6, 2022
55bb431
merge release notes again
srdtrk Dec 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Releases.md
@@ -1,5 +1,13 @@
# Release notes for the Secret Toolkit


## secret-toolkit-storage v0.6.1

- Added the `Keyset` storage object (A hashset like storage object).
- Allowed further customisation of Keymap and Keyset with new constructor structs called `KeymapBuilder` and `KeysetBuilder` which allow the user to disable the iterator feature (saving gas) or adjust the internal indexes' page size so that the user may determine how many objects are to be stored/loaded together in the iterator.
- `::new_with_page_size(namespace, page_size)` method was added to `AppendStore` and `DequeStore` so that the user may adjust the internal indexes' page size which determine how many objects are to be stored/loaded together in the iterator.
- Minor performance upgrades to `Keymap`, `AppendStore`, and `DequeStore`.

## v0.6.0

This release upgrades all `secret-toolkit` packages to be compatible with Cosmwasm v1.0 (Secret Network v1.4).
Expand Down
2 changes: 1 addition & 1 deletion packages/incubator/Readme.md
Expand Up @@ -96,7 +96,7 @@ assert_eq!(heap_store.remove(), Ok(Tx{

Also known as a slot map, a generational index storage is an iterable data structure where each element in the list is identified by a unique key that is a pair (index, generation). Each time an item is removed from the list the generation of the storage increments by one. If a new item is placed at the same index as a previous item which had been removed previously, the old references will not point to the new element. This is because although the index matches, the generation does not. This ensures that each reference to an element in the list is stable and safe.

Starting with an empty set, if we insert A we will have key: (index: 0, generation: 0). Inserting B will have the key: (index: 1, generation: 0). When we remove A the generation will increment by 1 and index 0 will be freed up. When we insert C it will go to the head of our list of free slots and be given the key (index: 0, generation: 1). If you attempt to get A the result will be None, even though A and C have both been at "0" position in the list.
Starting with an empty set, if we insert A we will have key: (index: 0, generation: 0). Inserting B will have the key: (index: 1, generation: 0). When we remove A the generation will increment by 1 and index 0 will be freed up. When we insert C it will go to the head of our list of free slots and be given the key (index: 0, generation: 1). If you attempt to get A the result will be None, even though A and C have both been at "0" position in the list.

Unlike AppendStore, iteration over a generational index storage is not in order of insertion.

Expand Down
2 changes: 1 addition & 1 deletion packages/incubator/src/generational_store.rs
Expand Up @@ -881,7 +881,7 @@ mod tests {
assert_eq!(gen_store.get(delta.clone()), Some(String::from("Delta")));
// check that the generation has updated
assert_ne!(
delta.clone(),
delta,
Index {
index: 1,
generation: 0
Expand Down
48 changes: 25 additions & 23 deletions packages/snip20/Readme.md
Expand Up @@ -11,13 +11,14 @@ You can create a HandleMsg variant and call the `to_cosmos_msg` function to gene
Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.

Example:

```ignore
let recipient = HumanAddr("ADDRESS_TO_TRANSFER_TO".to_string());
let recipient = "ADDRESS_TO_TRANSFER_TO".to_string();
let amount = Uint128(10000);
let padding = None;
let block_size = 256;
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();

let cosmos_msg = transfer_msg(
recipient,
Expand All @@ -28,19 +29,17 @@ Example:
contract_addr,
)?;

Ok(HandleResponse {
messages: vec![cosmos_msg],
log: vec![],
data: None,
})
Ok(Response::new().add_message(cosmos_msg))
```

All you have to do to call a SNIP-20 Handle function is call the appropriate toolkit function, and place the resulting `CosmosMsg` in the `messages` Vec of the InitResponse or HandleResponse. In this example, we are transferring 10000 (in the lowest denomination of the token) to the recipient address. We are not using the `padding` field of the Transfer message, but instead, we are padding the entire message to blocks of 256 bytes.

You probably have also noticed that CreateViewingKey is not supported. This is because a contract can not see the viewing key that is returned because it has already finished executing by the time CreateViewingKey would be called. If a contract needs to have a viewing key, it must create its own sufficiently complex viewing key, and pass it as a parameter to SetViewingKey. You can see an example of creating a complex viewing key in the [Snip20 Reference Implementation](http://github.com/enigmampc/snip20-reference-impl). It is also highly recommended that you use the block_size padding option to mask the length of the viewing key your contract has generated.

## Queries

These are the types that SNIP20 tokens can return from queries

```ignore
pub struct TokenInfo {
pub name: String,
Expand All @@ -56,8 +55,8 @@ pub struct ExchangeRate {
}

pub struct Allowance {
pub spender: HumanAddr,
pub owner: HumanAddr,
pub spender: String,
pub owner: String,
pub allowance: Uint128,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiration: Option<u64>,
Expand All @@ -69,9 +68,9 @@ pub struct Balance {

pub struct Tx {
pub id: u64,
pub from: HumanAddr,
pub sender: HumanAddr,
pub receiver: HumanAddr,
pub from: String,
pub sender: String,
pub receiver: String,
pub coins: Coin,
#[serde(skip_serializing_if = "Option::is_none")]
pub memo: Option<String>,
Expand All @@ -87,17 +86,17 @@ pub struct TransferHistory {
#[serde(rename_all = "snake_case")]
pub enum TxAction {
Transfer {
from: HumanAddr,
sender: HumanAddr,
recipient: HumanAddr,
from: String,
sender: String,
recipient: String,
},
Mint {
minter: HumanAddr,
recipient: HumanAddr,
minter: String,
recipient: String,
},
Burn {
burner: HumanAddr,
owner: HumanAddr,
burner: String,
owner: String,
},
Deposit {},
Redeem {},
Expand All @@ -119,22 +118,25 @@ pub struct TransactionHistory {
}

pub struct Minters {
pub minters: Vec<HumanAddr>,
pub minters: Vec<String>,
}
```

You can create a QueryMsg variant and call the `query` function to query a SNIP20 token contract.

Or you can call the individual function for each query.

Example:

```ignore
let address = HumanAddr("ADDRESS_WHOSE_BALANCE_IS_BEING_REQUESTED".to_string());
let address = "ADDRESS_WHOSE_BALANCE_IS_BEING_REQUESTED".to_string();
let key = "THE_VIEWING_KEY_PREVIOUSLY_SET_BY_THE_ADDRESS".to_string();
let block_size = 256;
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();

let balance =
balance_query(&deps.querier, address, key, block_size, callback_code_hash, contract_addr)?;
balance_query(deps.querier, address, key, block_size, callback_code_hash, contract_addr)?;
```

In this example, we are doing a Balance query for the specified address/key pair and storing the response in the balance variable, which is of the Balance type defined above. The query message is padded to blocks of 256 bytes.
46 changes: 24 additions & 22 deletions packages/snip721/Readme.md 100755 → 100644
Expand Up @@ -11,14 +11,15 @@ You can create a HandleMsg variant and call the `to_cosmos_msg` function to gene
Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.

Example:

```ignore
let recipient = HumanAddr("ADDRESS_TO_TRANSFER_TO".to_string());
let recipient = "ADDRESS_TO_TRANSFER_TO".to_string();
let token_id = "TOKEN_ID".to_string();
let memo = Some("TRANSFER_MEMO".to_string());
let padding = None;
let block_size = 256;
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();

let cosmos_msg = transfer_nft_msg(
recipient,
Expand All @@ -30,19 +31,17 @@ Example:
contract_addr,
)?;

Ok(HandleResponse {
messages: vec![cosmos_msg],
log: vec![],
data: None,
})
Ok(Response::new().add_message(cosmos_msg))
```

All you have to do to call a SNIP-721 Handle function is call the appropriate toolkit function, and place the resulting `CosmosMsg` in the `messages` Vec of the InitResponse or HandleResponse. In this example, we are transferring an NFT named "TOKEN_ID" to the recipient address. We are not using the `padding` field of the Transfer message, but instead, we are padding the entire message to blocks of 256 bytes.

You probably have also noticed that CreateViewingKey is not supported. This is because a contract can not see the viewing key that is returned because it has already finished executing by the time CreateViewingKey would be called. If a contract needs to have a viewing key, it must create its own sufficiently complex viewing key, and pass it as a parameter to SetViewingKey. You can see an example of creating a complex viewing key in the [Snip20 Reference Implementation](http://github.com/enigmampc/snip20-reference-impl). It is also highly recommended that you use the block_size padding option to mask the length of the viewing key your contract has generated.

## Queries

These are the types that the SNIP-721 toolkit queries can return

```ignore
pub struct ContractInfo {
pub name: String,
Expand All @@ -58,12 +57,12 @@ pub struct TokenList {
}

pub struct Cw721Approval {
pub spender: HumanAddr,
pub spender: String,
pub expires: Expiration,
}

pub struct OwnerOf {
pub owner: Option<HumanAddr>,
pub owner: Option<String>,
pub approvals: Vec<Cw721Approval>,
}

Expand All @@ -79,14 +78,14 @@ pub struct AllNftInfo {
}

pub struct Snip721Approval {
pub address: HumanAddr,
pub address: String,
pub view_owner_expiration: Option<Expiration>,
pub view_private_metadata_expiration: Option<Expiration>,
pub transfer_expiration: Option<Expiration>,
}

pub struct NftDossier {
pub owner: Option<HumanAddr>,
pub owner: Option<String>,
pub public_metadata: Option<Metadata>,
pub private_metadata: Option<Metadata>,
pub display_private_metadata_error: Option<String>,
Expand Down Expand Up @@ -120,17 +119,17 @@ pub struct InventoryApprovals {

pub enum TxAction {
Transfer {
from: HumanAddr,
sender: Option<HumanAddr>,
recipient: HumanAddr,
from: String,
sender: Option<String>,
recipient: String,
},
Mint {
minter: HumanAddr,
recipient: HumanAddr,
minter: String,
recipient: String,
},
Burn {
owner: HumanAddr,
burner: Option<HumanAddr>,
owner: String,
burner: Option<String>,
},
}

Expand All @@ -149,7 +148,7 @@ pub struct TransactionHistory {
}

pub struct Minters {
pub minters: Vec<HumanAddr>,
pub minters: Vec<String>,
}

pub struct IsUnwrapped {
Expand All @@ -161,23 +160,26 @@ pub struct VerifyTransferApproval {
pub first_unapproved_token: Option<String>,
}
```

You can create a QueryMsg variant and call the `query` function to query a SNIP-721 token contract.

Or you can call the individual function for each query.

Example:

```ignore
let token_id = "TOKEN_ID".to_string();
let viewer = Some(ViewerInfo {
address: HumanAddr("VIEWER'S_ADDRESS".to_string()),
address: "VIEWER'S_ADDRESS".to_string(),
viewing_key: "VIEWER'S_KEY".to_string(),
});
let include_expired = None;
let block_size = 256;
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();

let nft_dossier =
nft_dossier_query(&deps.querier, token_id, viewer, include_expired, block_size, callback_code_hash, contract_addr)?;
nft_dossier_query(deps.querier, token_id, viewer, include_expired, block_size, callback_code_hash, contract_addr)?;
```

In this example, we are doing an NftDossier query on the token named "TOKEN_ID", supplying the address and viewing key of the querier, and storing the response in the nft_dossier variable, which is of the NftDossier type defined above. Because no `include_expired` was specified, the response defaults to only displaying approvals that have not expired, but approvals will only be displayed if the viewer is the owner of the token. The query message is padded to blocks of 256 bytes.
10 changes: 5 additions & 5 deletions packages/snip721/src/handle.rs
Expand Up @@ -1058,7 +1058,7 @@ mod tests {
let test_msg = approve_msg(
spender.clone(),
token_id.clone(),
expires.clone(),
expires,
padding.clone(),
256usize,
code_hash.clone(),
Expand Down Expand Up @@ -1123,7 +1123,7 @@ mod tests {

let test_msg = approve_all_msg(
operator.clone(),
expires.clone(),
expires,
padding.clone(),
256usize,
code_hash.clone(),
Expand Down Expand Up @@ -1189,7 +1189,7 @@ mod tests {
view_owner.clone(),
view_private_metadata.clone(),
transfer.clone(),
expires.clone(),
expires,
padding.clone(),
256usize,
code_hash.clone(),
Expand Down Expand Up @@ -1225,7 +1225,7 @@ mod tests {

let test_msg = register_receive_nft_msg(
code_hash.clone(),
also_implements_batch_receive_nft.clone(),
also_implements_batch_receive_nft,
padding.clone(),
256usize,
callback_code_hash.clone(),
Expand Down Expand Up @@ -1805,7 +1805,7 @@ mod tests {
token_id.clone(),
view_owner.clone(),
view_private_metadata.clone(),
expires.clone(),
expires,
padding.clone(),
256usize,
code_hash.clone(),
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "secret-toolkit-storage"
version = "0.6.0"
version = "0.6.1"
edition = "2018"
authors = ["SCRT Labs <info@scrtlabs.com>"]
license-file = "../../LICENSE"
Expand Down