Skip to content

Commit

Permalink
feat: test pack_inscribe_output_args
Browse files Browse the repository at this point in the history
  • Loading branch information
yubing744 committed Jun 15, 2024
1 parent 72bb89a commit 2ebb959
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 18 deletions.
3 changes: 1 addition & 2 deletions frameworks/moveos-stdlib/doc/cbor.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,5 @@ If the field type is primitive type, it will be parsed to bytes, array or object
Serialize a value of type T to CBOR bytes.


<pre><code>#[data_struct(#[T])]
<b>public</b> <b>fun</b> <a href="cbor.md#0x2_cbor_to_cbor">to_cbor</a>&lt;T: drop&gt;(value: &T): <a href="">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="cbor.md#0x2_cbor_to_cbor">to_cbor</a>&lt;T&gt;(value: &T): <a href="">vector</a>&lt;u8&gt;
</code></pre>
3 changes: 1 addition & 2 deletions frameworks/moveos-stdlib/sources/cbor.move
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ module moveos_std::cbor {
option::destroy_some(opt_result)
}

#[data_struct(T)]
/// Serialize a value of type T to CBOR bytes.
public fun to_cbor<T: drop>(value: &T): vector<u8> {
public fun to_cbor<T>(value: &T): vector<u8> {
native_to_cbor(value)
}

Expand Down
26 changes: 25 additions & 1 deletion frameworks/rooch-nursery/doc/bitseed.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- [Struct `BitseedCoinInfo`](#0xa_bitseed_BitseedCoinInfo)
- [Resource `BitseedStore`](#0xa_bitseed_BitseedStore)
- [Struct `InscribeGenerateArgs`](#0xa_bitseed_InscribeGenerateArgs)
- [Struct `InscribeContent`](#0xa_bitseed_InscribeContent)
- [Struct `InscribeGenerateOutput`](#0xa_bitseed_InscribeGenerateOutput)
- [Constants](#@Constants_0)
- [Function `genesis_init`](#0xa_bitseed_genesis_init)
- [Function `bitseed_deploy_key`](#0xa_bitseed_bitseed_deploy_key)
Expand Down Expand Up @@ -92,6 +94,28 @@



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

## Struct `InscribeContent`



<pre><code><b>struct</b> <a href="bitseed.md#0xa_bitseed_InscribeContent">InscribeContent</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Struct `InscribeGenerateOutput`



<pre><code><b>struct</b> <a href="bitseed.md#0xa_bitseed_InscribeGenerateOutput">InscribeGenerateOutput</a> <b>has</b> store
</code></pre>



<a name="@Constants_0"></a>

## Constants
Expand Down Expand Up @@ -262,7 +286,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="bitseed.md#0xa_bitseed_inscribe_verify">inscribe_verify</a>(wasm_bytes: <a href="">vector</a>&lt;u8&gt;, deploy_args: <a href="">vector</a>&lt;u8&gt;, seed: <a href="">vector</a>&lt;u8&gt;, user_input: <a href="">vector</a>&lt;u8&gt;, attributes_output: <a href="">vector</a>&lt;u8&gt;): (bool, <a href="_Option">option::Option</a>&lt;<a href="_String">string::String</a>&gt;)
<pre><code><b>public</b> <b>fun</b> <a href="bitseed.md#0xa_bitseed_inscribe_verify">inscribe_verify</a>(wasm_bytes: <a href="">vector</a>&lt;u8&gt;, deploy_args: <a href="">vector</a>&lt;u8&gt;, seed: <a href="">vector</a>&lt;u8&gt;, user_input: <a href="">vector</a>&lt;u8&gt;, metadata: &<a href="_SimpleMap">simple_map::SimpleMap</a>&lt;<a href="_String">string::String</a>, <a href="">vector</a>&lt;u8&gt;&gt;, content_type: <a href="_Option">option::Option</a>&lt;<a href="_String">string::String</a>&gt;, body: <a href="">vector</a>&lt;u8&gt;): (bool, <a href="_Option">option::Option</a>&lt;<a href="_String">string::String</a>&gt;)
</code></pre>


Expand Down
70 changes: 57 additions & 13 deletions frameworks/rooch-nursery/sources/bitseed.move
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ module rooch_nursery::bitseed {
(true, option::none<String>())
}

fun is_valid_bitseed_mint(metadata: &SimpleMap<String,vector<u8>>, seed: vector<u8>) : (bool, Option<String>) {
fun is_valid_bitseed_mint(metadata: &SimpleMap<String,vector<u8>>, seed: vector<u8>, content_type: Option<String>, body: vector<u8>) : (bool, Option<String>) {
let (is_valid, reason) = is_valid_bitseed(metadata);
if (!is_valid) {
return (false, reason)
Expand Down Expand Up @@ -423,7 +423,7 @@ module rooch_nursery::bitseed {



let (is_valid, reason) = inscribe_verify(wasm_bytes, deploy_args, seed, user_input, metadata);
let (is_valid, reason) = inscribe_verify(wasm_bytes, deploy_args, seed, user_input, metadata, content_type, body);
if (!is_valid) {
simple_map::drop(attributes);
return (false, reason)
Expand All @@ -434,7 +434,8 @@ module rooch_nursery::bitseed {
}

public fun inscribe_verify(wasm_bytes: vector<u8>, deploy_args: vector<u8>,
seed: vector<u8>, user_input: vector<u8>, metadata: &SimpleMap<String,vector<u8>>, body: &vector<u8>): (bool, Option<String>) {
seed: vector<u8>, user_input: vector<u8>, metadata: &SimpleMap<String,vector<u8>>,
content_type: Option<String>, body: vector<u8>): (bool, Option<String>) {
let wasm_instance_option = wasm::create_wasm_instance_option(wasm_bytes);
if (option::is_none(&wasm_instance_option)) {
option::destroy_none(wasm_instance_option);
Expand All @@ -447,14 +448,12 @@ module rooch_nursery::bitseed {
let buffer = pack_inscribe_generate_args(deploy_args, seed, user_input);
let arg_with_length = wasm::add_length_with_data(buffer);

let output_buffer = pack_inscribe_output_args(metadata, content_type, body);

let arg_list = vector::empty<vector<u8>>();
vector::push_back(&mut arg_list, arg_with_length);
vector::push_back(&mut arg_list, attributes_output);
vector::push_back(&mut arg_list, output_buffer);

let amount = simple_map::borrow(metadata, &string::utf8(b"amount"));
let attributes_bytes = simple_map::borrow(metadata, &string::utf8(b"attributes"));
let content_type_bytes = simple_map::borrow(metadata, &string::utf8(b"content_type"));
let output_bytes = make_output(amount, attributes_bytes, content_type_bytes, body);

let memory_args_list = wasm::create_memory_wasm_args(&mut wasm_instance, function_name, arg_list);

Expand Down Expand Up @@ -501,6 +500,40 @@ module rooch_nursery::bitseed {
cbor::to_cbor(&args)
}

struct InscribeContent has copy, drop, store {
content_type: Option<String>,
body: vector<u8>,
}

struct InscribeGenerateOutput has store {
amount: u64,
attributes: SimpleMap<String,vector<u8>>,
content: InscribeContent,
}

fun pack_inscribe_output_args(metadata: &SimpleMap<String,vector<u8>>, content_type: Option<String>, body: vector<u8>): vector<u8>{
let amount = get_SFT_amount(metadata);
let attributes = get_SFT_attributes(metadata);

let content = InscribeContent{
content_type: content_type,
body: body,
};

let output = InscribeGenerateOutput{
amount: amount,
attributes: attributes,
content: content,
};

let output_bytes = cbor::to_cbor(&output);

let InscribeGenerateOutput{amount:_, attributes, content:_}=output;
simple_map::drop(attributes);

output_bytes
}

fun generate_seed_from_inscription(inscription: &Inscription): vector<u8> {
let inscription_txid = ord::txid(inscription);
let tx_option = bitcoin::get_tx(inscription_txid);
Expand Down Expand Up @@ -576,7 +609,10 @@ module rooch_nursery::bitseed {
ord::seal_metaprotocol_validity<Bitseed>(inscription_id, true, option::none());
} else if (option::borrow(&op) == &string::utf8(b"mint")) {
let seed = generate_seed_from_inscription(inscription);
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed);
let content_type = ord::content_type(inscription);
let body = ord::body(inscription);

let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed, content_type, body);
ord::seal_metaprotocol_validity<Bitseed>(inscription_id, is_valid, reason);
} else if (option::borrow(&op) == &string::utf8(b"split")) {
ord::seal_metaprotocol_validity<Bitseed>(inscription_id, true, option::none());
Expand Down Expand Up @@ -824,7 +860,9 @@ module rooch_nursery::bitseed {
let metadata_bytes = x"a4626f70666465706c6f79647469636b646d6f766566616d6f756e74016a61747472696275746573a16967656e657261746f72784f2f696e736372697074696f6e2f373764666332666535393834313962303036343163323936313831613936636631363934333639376635373334383062303233623737636365383261646132316930";
let metadata = cbor::to_map(metadata_bytes);
let seed = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed);
let content_type = option::none();
let body = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed, content_type, body);
simple_map::drop(metadata);

assert!(!is_valid, 1);
Expand Down Expand Up @@ -854,7 +892,9 @@ module rooch_nursery::bitseed {
let metadata_bytes = x"a4626f70646d696e74647469636b646d6f766566616d6f756e7418646a61747472696275746573a16967656e657261746f72784f2f696e736372697074696f6e2f377864666332666535393834313962303036343163323936313831613936636631363934333639376635373334383062303233623737636365383261646132316930";
let metadata = cbor::to_map(metadata_bytes);
let seed = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed);
let content_type = option::none();
let body = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed, content_type, body);
simple_map::drop(metadata);

assert!(!is_valid, 1);
Expand Down Expand Up @@ -884,7 +924,9 @@ module rooch_nursery::bitseed {
let metadata_bytes = x"a4626f70646d696e74647469636b646d6f766566616d6f756e7418646a61747472696275746573a16967656e657261746f72784f2f696e736372697074696f6e2f377864666332666535393834313962303036343163323936313831613936636631363934333639376635373334383062303233623737636365383261646132316930";
let metadata = cbor::to_map(metadata_bytes);
let seed = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed);
let content_type = option::none();
let body = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed, content_type, body);
simple_map::drop(metadata);

assert!(!is_valid, 1);
Expand Down Expand Up @@ -916,7 +958,9 @@ module rooch_nursery::bitseed {
let metadata_bytes = x"a4626f70646d696e74647469636b646d6f766566616d6f756e74016a61747472696275746573a16a757365725f696e70757463787878";
let metadata = cbor::to_map(metadata_bytes);
let seed = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed);
let content_type = option::none();
let body = vector::empty();
let (is_valid, reason) = is_valid_bitseed_mint(&metadata, seed, content_type, body);
simple_map::drop(metadata);

assert!(!is_valid, 1);
Expand Down

0 comments on commit 2ebb959

Please sign in to comment.