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

Upgrade MerkleNFTDistributor::register to v2 #196

Merged
merged 4 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified build/StarcoinFramework/bytecode_modules/Genesis.mv
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/GenesisNFT.mv
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/MerkleNFTDistributor.mv
Binary file not shown.
2 changes: 0 additions & 2 deletions build/StarcoinFramework/docs/Genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ The module for init Genesis
<a href="GenesisNFT.md#0x1_GenesisNFT_initialize">GenesisNFT::initialize</a>(&genesis_account, merkle_root, 1639u64, image);
};
<a href="Config.md#0x1_Config_publish_new_config">Config::publish_new_config</a>(&genesis_account, <a href="LanguageVersion.md#0x1_LanguageVersion_new">LanguageVersion::new</a>(4));
// upgrade genesis <a href="NFT.md#0x1_NFT">NFT</a>
<a href="GenesisNFT.md#0x1_GenesisNFT_upgrade_to_nft_type_info_v2">GenesisNFT::upgrade_to_nft_type_info_v2</a>(&genesis_account);

//v11 -&gt; v12
<a href="Block.md#0x1_Block_checkpoints_init">Block::checkpoints_init</a>();
Expand Down
50 changes: 49 additions & 1 deletion build/StarcoinFramework/docs/MerkleNFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Resource `MerkleNFTDistribution`](#0x1_MerkleNFTDistributor_MerkleNFTDistribution)
- [Constants](#@Constants_0)
- [Function `register`](#0x1_MerkleNFTDistributor_register)
- [Function `register_v2`](#0x1_MerkleNFTDistributor_register_v2)
- [Function `mint_with_cap`](#0x1_MerkleNFTDistributor_mint_with_cap)
- [Function `encode_leaf`](#0x1_MerkleNFTDistributor_encode_leaf)
- [Function `set_minted_`](#0x1_MerkleNFTDistributor_set_minted_)
Expand Down Expand Up @@ -96,6 +97,7 @@

## Function `register`

Deprecated, use <code>register_v2</code> instead.


<pre><code><b>public</b> <b>fun</b> <a href="MerkleNFT.md#0x1_MerkleNFTDistributor_register">register</a>&lt;NFTMeta: <b>copy</b>, drop, store, Info: <b>copy</b>, drop, store&gt;(signer: &signer, merkle_root: vector&lt;u8&gt;, leafs: u64, info: Info, meta: <a href="NFT.md#0x1_NFT_Metadata">NFT::Metadata</a>): <a href="NFT.md#0x1_NFT_MintCapability">NFT::MintCapability</a>&lt;NFTMeta&gt;
Expand All @@ -107,7 +109,13 @@
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="MerkleNFT.md#0x1_MerkleNFTDistributor_register">register</a>&lt;NFTMeta: <b>copy</b> + store + drop, Info: <b>copy</b> + store + drop&gt;(signer: &signer, merkle_root: vector&lt;u8&gt;, leafs: u64, info: Info, meta: Metadata): MintCapability&lt;NFTMeta&gt; {
<pre><code><b>public</b> <b>fun</b> <a href="MerkleNFT.md#0x1_MerkleNFTDistributor_register">register</a>&lt;NFTMeta: <b>copy</b> + store + drop, Info: <b>copy</b> + store + drop&gt;(
signer: &signer,
merkle_root: vector&lt;u8&gt;,
leafs: u64,
info: Info,
meta: Metadata
): MintCapability&lt;NFTMeta&gt; {
<b>let</b> bitmap_count = leafs / 128;
<b>if</b> (bitmap_count * 128 &lt; leafs) {
bitmap_count = bitmap_count + 1;
Expand All @@ -130,6 +138,46 @@



</details>

<a name="0x1_MerkleNFTDistributor_register_v2"></a>

## Function `register_v2`



<pre><code><b>public</b> <b>fun</b> <a href="MerkleNFT.md#0x1_MerkleNFTDistributor_register_v2">register_v2</a>&lt;NFTMeta: <b>copy</b>, drop, store&gt;(signer: &signer, merkle_root: vector&lt;u8&gt;, leafs: u64, meta: <a href="NFT.md#0x1_NFT_Metadata">NFT::Metadata</a>): <a href="NFT.md#0x1_NFT_MintCapability">NFT::MintCapability</a>&lt;NFTMeta&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="MerkleNFT.md#0x1_MerkleNFTDistributor_register_v2">register_v2</a>&lt;NFTMeta: <b>copy</b> + store + drop&gt;(signer: &signer, merkle_root: vector&lt;u8&gt;, leafs: u64, meta: Metadata): MintCapability&lt;NFTMeta&gt; {
<b>let</b> bitmap_count = leafs / 128;
<b>if</b> (bitmap_count * 128 &lt; leafs) {
bitmap_count = bitmap_count + 1;
};
<b>let</b> claimed_bitmap = <a href="Vector.md#0x1_Vector_empty">Vector::empty</a>();
<b>let</b> j = 0;
<b>while</b> (j &lt; bitmap_count) {
<a href="Vector.md#0x1_Vector_push_back">Vector::push_back</a>( &<b>mut</b> claimed_bitmap, 0u128);
j = j + 1;
};
<b>let</b> distribution = <a href="MerkleNFT.md#0x1_MerkleNFTDistributor_MerkleNFTDistribution">MerkleNFTDistribution</a>&lt;NFTMeta&gt;{
merkle_root,
claimed_bitmap
};
<a href="NFT.md#0x1_NFT_register_v2">NFT::register_v2</a>&lt;NFTMeta&gt;(signer, meta);
<b>move_to</b>(signer, distribution);
<a href="NFT.md#0x1_NFT_remove_mint_capability">NFT::remove_mint_capability</a>&lt;NFTMeta&gt;(signer)
}
</code></pre>



</details>

<a name="0x1_MerkleNFTDistributor_mint_with_cap"></a>
Expand Down
Binary file modified build/StarcoinFramework/source_maps/Genesis.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/GenesisNFT.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/GenesisNFTScripts.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/MerkleNFTDistributor.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/MerkleProof.mvsm
Binary file not shown.
2 changes: 0 additions & 2 deletions sources/Genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@ module StarcoinFramework::Genesis {
GenesisNFT::initialize(&genesis_account, merkle_root, 1639u64, image);
};
Config::publish_new_config(&genesis_account, LanguageVersion::new(4));
// upgrade genesis NFT
GenesisNFT::upgrade_to_nft_type_info_v2(&genesis_account);

//v11 -> v12
Block::checkpoints_init();
Expand Down
3 changes: 1 addition & 2 deletions sources/GenesisNFT.move
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ module StarcoinFramework::GenesisNFT {
public fun initialize(sender: &signer, merkle_root: vector<u8>, leafs: u64, image: vector<u8>){
CoreAddresses::assert_genesis_address(sender);
let metadata = NFT::new_meta_with_image(b"StarcoinGenesisNFT", image, b"The starcoin genesis NFT");
let nft_info = GenesisNFTInfo{merkle_root: *&merkle_root, total_supply: leafs};
let cap = MerkleNFTDistributor::register<GenesisNFTMeta, GenesisNFTInfo>(sender, merkle_root, leafs, nft_info, metadata);
let cap = MerkleNFTDistributor::register_v2<GenesisNFTMeta>(sender, merkle_root, leafs, metadata);
move_to(sender, GenesisNFTMintCapability{cap});
}

Expand Down
29 changes: 28 additions & 1 deletion sources/MerkleNFT.move
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ module StarcoinFramework::MerkleNFTDistributor {
claimed_bitmap: vector<u128>,
}

public fun register<NFTMeta: copy + store + drop, Info: copy + store + drop>(signer: &signer, merkle_root: vector<u8>, leafs: u64, info: Info, meta: Metadata): MintCapability<NFTMeta> {
/// Deprecated, use `register_v2` instead.
public fun register<NFTMeta: copy + store + drop, Info: copy + store + drop>(
signer: &signer,
merkle_root: vector<u8>,
leafs: u64,
info: Info,
meta: Metadata
): MintCapability<NFTMeta> {
let bitmap_count = leafs / 128;
if (bitmap_count * 128 < leafs) {
bitmap_count = bitmap_count + 1;
Expand All @@ -67,6 +74,26 @@ module StarcoinFramework::MerkleNFTDistributor {
NFT::remove_mint_capability<NFTMeta>(signer)
}

public fun register_v2<NFTMeta: copy + store + drop>(signer: &signer, merkle_root: vector<u8>, leafs: u64, meta: Metadata): MintCapability<NFTMeta> {
let bitmap_count = leafs / 128;
if (bitmap_count * 128 < leafs) {
bitmap_count = bitmap_count + 1;
};
let claimed_bitmap = Vector::empty();
let j = 0;
while (j < bitmap_count) {
Vector::push_back( &mut claimed_bitmap, 0u128);
j = j + 1;
};
let distribution = MerkleNFTDistribution<NFTMeta>{
merkle_root,
claimed_bitmap
};
NFT::register_v2<NFTMeta>(signer, meta);
move_to(signer, distribution);
NFT::remove_mint_capability<NFTMeta>(signer)
}

public fun mint_with_cap<NFTMeta: copy + store + drop, NFTBody: store, Info: copy + store + drop>(sender: &signer, cap:&mut MintCapability<NFTMeta>, creator: address, index: u64, base_meta: Metadata, type_meta: NFTMeta, body: NFTBody, merkle_proof:vector<vector<u8>>): NFT<NFTMeta, NFTBody>
acquires MerkleNFTDistribution {
let addr = Signer::address_of(sender);
Expand Down