Skip to content

Commit f0fa15b

Browse files
authored
Merge pull request #66 from srdtrk/cw-v1.0-storage
v0.7 Upgrade with Storage and Readme Updates (for Cosmwasm v1.0)
2 parents 38d320e + 55bb431 commit f0fa15b

File tree

14 files changed

+2546
-765
lines changed

14 files changed

+2546
-765
lines changed

Releases.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
## v0.7.0
44

5-
This release changes the internal toolkit package to be part of the workspace - this fixes default-features flags in some of the
6-
crates. In addition, crates used by the toolkit have been bumped, and the edition of the toolkit crates has been bumped to 2021
5+
- This release changes the internal toolkit package to be part of the workspace - this fixes default-features flags in some of the crates. In addition, crates used by the toolkit have been bumped, and the edition of the toolkit crates has been bumped to 2021.
6+
7+
- Added the `Keyset` storage object (A hashset like storage object).
8+
- 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.
9+
- `::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.
10+
- Minor performance upgrades to `Keymap`, `AppendStore`, and `DequeStore`.
711

812
### Breaking
913

packages/incubator/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ assert_eq!(heap_store.remove(), Ok(Tx{
9696

9797
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.
9898

99-
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.
99+
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.
100100

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

packages/incubator/src/generational_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ mod tests {
881881
assert_eq!(gen_store.get(delta.clone()), Some(String::from("Delta")));
882882
// check that the generation has updated
883883
assert_ne!(
884-
delta.clone(),
884+
delta,
885885
Index {
886886
index: 1,
887887
generation: 0

packages/snip20/Readme.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ You can create a HandleMsg variant and call the `to_cosmos_msg` function to gene
1111
Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.
1212

1313
Example:
14+
1415
```ignore
15-
let recipient = HumanAddr("ADDRESS_TO_TRANSFER_TO".to_string());
16+
let recipient = "ADDRESS_TO_TRANSFER_TO".to_string();
1617
let amount = Uint128(10000);
1718
let padding = None;
1819
let block_size = 256;
1920
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
20-
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
21+
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();
2122
2223
let cosmos_msg = transfer_msg(
2324
recipient,
@@ -28,19 +29,17 @@ Example:
2829
contract_addr,
2930
)?;
3031
31-
Ok(HandleResponse {
32-
messages: vec![cosmos_msg],
33-
log: vec![],
34-
data: None,
35-
})
32+
Ok(Response::new().add_message(cosmos_msg))
3633
```
34+
3735
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.
3836

3937
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.
4038

4139
## Queries
4240

4341
These are the types that SNIP20 tokens can return from queries
42+
4443
```ignore
4544
pub struct TokenInfo {
4645
pub name: String,
@@ -56,8 +55,8 @@ pub struct ExchangeRate {
5655
}
5756
5857
pub struct Allowance {
59-
pub spender: HumanAddr,
60-
pub owner: HumanAddr,
58+
pub spender: String,
59+
pub owner: String,
6160
pub allowance: Uint128,
6261
#[serde(skip_serializing_if = "Option::is_none")]
6362
pub expiration: Option<u64>,
@@ -69,9 +68,9 @@ pub struct Balance {
6968
7069
pub struct Tx {
7170
pub id: u64,
72-
pub from: HumanAddr,
73-
pub sender: HumanAddr,
74-
pub receiver: HumanAddr,
71+
pub from: String,
72+
pub sender: String,
73+
pub receiver: String,
7574
pub coins: Coin,
7675
#[serde(skip_serializing_if = "Option::is_none")]
7776
pub memo: Option<String>,
@@ -87,17 +86,17 @@ pub struct TransferHistory {
8786
#[serde(rename_all = "snake_case")]
8887
pub enum TxAction {
8988
Transfer {
90-
from: HumanAddr,
91-
sender: HumanAddr,
92-
recipient: HumanAddr,
89+
from: String,
90+
sender: String,
91+
recipient: String,
9392
},
9493
Mint {
95-
minter: HumanAddr,
96-
recipient: HumanAddr,
94+
minter: String,
95+
recipient: String,
9796
},
9897
Burn {
99-
burner: HumanAddr,
100-
owner: HumanAddr,
98+
burner: String,
99+
owner: String,
101100
},
102101
Deposit {},
103102
Redeem {},
@@ -119,22 +118,25 @@ pub struct TransactionHistory {
119118
}
120119
121120
pub struct Minters {
122-
pub minters: Vec<HumanAddr>,
121+
pub minters: Vec<String>,
123122
}
124123
```
124+
125125
You can create a QueryMsg variant and call the `query` function to query a SNIP20 token contract.
126126

127127
Or you can call the individual function for each query.
128128

129129
Example:
130+
130131
```ignore
131-
let address = HumanAddr("ADDRESS_WHOSE_BALANCE_IS_BEING_REQUESTED".to_string());
132+
let address = "ADDRESS_WHOSE_BALANCE_IS_BEING_REQUESTED".to_string();
132133
let key = "THE_VIEWING_KEY_PREVIOUSLY_SET_BY_THE_ADDRESS".to_string();
133134
let block_size = 256;
134135
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
135-
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
136+
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();
136137
137138
let balance =
138-
balance_query(&deps.querier, address, key, block_size, callback_code_hash, contract_addr)?;
139+
balance_query(deps.querier, address, key, block_size, callback_code_hash, contract_addr)?;
139140
```
141+
140142
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.

packages/snip721/Readme.md

100755100644
Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ You can create a HandleMsg variant and call the `to_cosmos_msg` function to gene
1111
Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.
1212

1313
Example:
14+
1415
```ignore
15-
let recipient = HumanAddr("ADDRESS_TO_TRANSFER_TO".to_string());
16+
let recipient = "ADDRESS_TO_TRANSFER_TO".to_string();
1617
let token_id = "TOKEN_ID".to_string();
1718
let memo = Some("TRANSFER_MEMO".to_string());
1819
let padding = None;
1920
let block_size = 256;
2021
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
21-
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
22+
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();
2223
2324
let cosmos_msg = transfer_nft_msg(
2425
recipient,
@@ -30,19 +31,17 @@ Example:
3031
contract_addr,
3132
)?;
3233
33-
Ok(HandleResponse {
34-
messages: vec![cosmos_msg],
35-
log: vec![],
36-
data: None,
37-
})
34+
Ok(Response::new().add_message(cosmos_msg))
3835
```
36+
3937
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.
4038

4139
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.
4240

4341
## Queries
4442

4543
These are the types that the SNIP-721 toolkit queries can return
44+
4645
```ignore
4746
pub struct ContractInfo {
4847
pub name: String,
@@ -58,12 +57,12 @@ pub struct TokenList {
5857
}
5958
6059
pub struct Cw721Approval {
61-
pub spender: HumanAddr,
60+
pub spender: String,
6261
pub expires: Expiration,
6362
}
6463
6564
pub struct OwnerOf {
66-
pub owner: Option<HumanAddr>,
65+
pub owner: Option<String>,
6766
pub approvals: Vec<Cw721Approval>,
6867
}
6968
@@ -79,14 +78,14 @@ pub struct AllNftInfo {
7978
}
8079
8180
pub struct Snip721Approval {
82-
pub address: HumanAddr,
81+
pub address: String,
8382
pub view_owner_expiration: Option<Expiration>,
8483
pub view_private_metadata_expiration: Option<Expiration>,
8584
pub transfer_expiration: Option<Expiration>,
8685
}
8786
8887
pub struct NftDossier {
89-
pub owner: Option<HumanAddr>,
88+
pub owner: Option<String>,
9089
pub public_metadata: Option<Metadata>,
9190
pub private_metadata: Option<Metadata>,
9291
pub display_private_metadata_error: Option<String>,
@@ -120,17 +119,17 @@ pub struct InventoryApprovals {
120119
121120
pub enum TxAction {
122121
Transfer {
123-
from: HumanAddr,
124-
sender: Option<HumanAddr>,
125-
recipient: HumanAddr,
122+
from: String,
123+
sender: Option<String>,
124+
recipient: String,
126125
},
127126
Mint {
128-
minter: HumanAddr,
129-
recipient: HumanAddr,
127+
minter: String,
128+
recipient: String,
130129
},
131130
Burn {
132-
owner: HumanAddr,
133-
burner: Option<HumanAddr>,
131+
owner: String,
132+
burner: Option<String>,
134133
},
135134
}
136135
@@ -149,7 +148,7 @@ pub struct TransactionHistory {
149148
}
150149
151150
pub struct Minters {
152-
pub minters: Vec<HumanAddr>,
151+
pub minters: Vec<String>,
153152
}
154153
155154
pub struct IsUnwrapped {
@@ -161,23 +160,26 @@ pub struct VerifyTransferApproval {
161160
pub first_unapproved_token: Option<String>,
162161
}
163162
```
163+
164164
You can create a QueryMsg variant and call the `query` function to query a SNIP-721 token contract.
165165

166166
Or you can call the individual function for each query.
167167

168168
Example:
169+
169170
```ignore
170171
let token_id = "TOKEN_ID".to_string();
171172
let viewer = Some(ViewerInfo {
172-
address: HumanAddr("VIEWER'S_ADDRESS".to_string()),
173+
address: "VIEWER'S_ADDRESS".to_string(),
173174
viewing_key: "VIEWER'S_KEY".to_string(),
174175
});
175176
let include_expired = None;
176177
let block_size = 256;
177178
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string();
178-
let contract_addr = HumanAddr("TOKEN_CONTRACT_ADDRESS".to_string());
179+
let contract_addr = "TOKEN_CONTRACT_ADDRESS".to_string();
179180
180181
let nft_dossier =
181-
nft_dossier_query(&deps.querier, token_id, viewer, include_expired, block_size, callback_code_hash, contract_addr)?;
182+
nft_dossier_query(deps.querier, token_id, viewer, include_expired, block_size, callback_code_hash, contract_addr)?;
182183
```
184+
183185
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.

packages/snip721/src/handle.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ mod tests {
10581058
let test_msg = approve_msg(
10591059
spender.clone(),
10601060
token_id.clone(),
1061-
expires.clone(),
1061+
expires,
10621062
padding.clone(),
10631063
256usize,
10641064
code_hash.clone(),
@@ -1123,7 +1123,7 @@ mod tests {
11231123

11241124
let test_msg = approve_all_msg(
11251125
operator.clone(),
1126-
expires.clone(),
1126+
expires,
11271127
padding.clone(),
11281128
256usize,
11291129
code_hash.clone(),
@@ -1189,7 +1189,7 @@ mod tests {
11891189
view_owner.clone(),
11901190
view_private_metadata.clone(),
11911191
transfer.clone(),
1192-
expires.clone(),
1192+
expires,
11931193
padding.clone(),
11941194
256usize,
11951195
code_hash.clone(),
@@ -1225,7 +1225,7 @@ mod tests {
12251225

12261226
let test_msg = register_receive_nft_msg(
12271227
code_hash.clone(),
1228-
also_implements_batch_receive_nft.clone(),
1228+
also_implements_batch_receive_nft,
12291229
padding.clone(),
12301230
256usize,
12311231
callback_code_hash.clone(),
@@ -1805,7 +1805,7 @@ mod tests {
18051805
token_id.clone(),
18061806
view_owner.clone(),
18071807
view_private_metadata.clone(),
1808-
expires.clone(),
1808+
expires,
18091809
padding.clone(),
18101810
256usize,
18111811
code_hash.clone(),

0 commit comments

Comments
 (0)