Skip to content

Commit

Permalink
[Bitcoin] Implement brc20 progress (rooch-network#1197)
Browse files Browse the repository at this point in the history
* [moveos_std] Implement string_utils and support json parse option

* [Bitcoin] Implement brc20 progress

* fixup

* [indexer] Change log level to trace

* fixup

* fixup
  • Loading branch information
jolestar authored Dec 2, 2023
1 parent 397cea2 commit 890bc93
Show file tree
Hide file tree
Showing 21 changed files with 1,414 additions and 72 deletions.
6 changes: 4 additions & 2 deletions crates/rooch-framework-tests/src/tests/ord_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::binding_test;
use bitcoin::consensus::{deserialize, Decodable};
use bitcoin::Block;
use hex::FromHex;
use moveos_types::state::MoveState;
use moveos_types::transaction::MoveAction;
use rooch_key::keystore::account_keystore::AccountKeystore;
use rooch_key::keystore::memory_keystore::InMemKeystore;
Expand All @@ -25,8 +26,9 @@ fn test_from_transaction() {
rooch_framework::natives::rooch_framework::bitcoin::ord::from_transaction(&btc_tx);
//print!("{:?}", inscriptions);
let ord_module = binding_test.as_module_bundle::<rooch_types::framework::ord::OrdModule>();

let inscriptions_from_move = ord_module.from_transaction(&btc_tx.into()).unwrap();
let move_btc_tx: rooch_types::framework::bitcoin_types::Transaction = btc_tx.into();
//println!("tx_hex: {}", hex::encode(move_btc_tx.to_bytes()));
let inscriptions_from_move = ord_module.from_transaction(&move_btc_tx).unwrap();
assert_eq!(inscriptions.len(), inscriptions_from_move.len());
for (inscription, inscription_from_move) in inscriptions.into_iter().zip(inscriptions_from_move)
{
Expand Down
1 change: 1 addition & 0 deletions crates/rooch-framework/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This is the reference documentation of the Rooch Framework.
- [`0x3::bitcoin_opcode`](bitcoin_opcode.md#0x3_bitcoin_opcode)
- [`0x3::bitcoin_script_buf`](bitcoin_script_buf.md#0x3_bitcoin_script_buf)
- [`0x3::bitcoin_types`](bitcoin_types.md#0x3_bitcoin_types)
- [`0x3::brc20`](brc20.md#0x3_brc20)
- [`0x3::builtin_validators`](builtin_validators.md#0x3_builtin_validators)
- [`0x3::chain_id`](chain_id.md#0x3_chain_id)
- [`0x3::coin`](coin.md#0x3_coin)
Expand Down
257 changes: 257 additions & 0 deletions crates/rooch-framework/doc/brc20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@

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

# Module `0x3::brc20`



- [Struct `BRC20CoinInfo`](#0x3_brc20_BRC20CoinInfo)
- [Resource `BRC20Store`](#0x3_brc20_BRC20Store)
- [Struct `Op`](#0x3_brc20_Op)
- [Struct `DeployOp`](#0x3_brc20_DeployOp)
- [Struct `MintOp`](#0x3_brc20_MintOp)
- [Struct `TransferOp`](#0x3_brc20_TransferOp)
- [Function `genesis_init`](#0x3_brc20_genesis_init)
- [Function `is_brc20`](#0x3_brc20_is_brc20)
- [Function `is_deploy`](#0x3_brc20_is_deploy)
- [Function `as_deploy`](#0x3_brc20_as_deploy)
- [Function `is_mint`](#0x3_brc20_is_mint)
- [Function `as_mint`](#0x3_brc20_as_mint)
- [Function `is_transfer`](#0x3_brc20_is_transfer)
- [Function `as_transfer`](#0x3_brc20_as_transfer)
- [Function `from_inscription`](#0x3_brc20_from_inscription)
- [Function `remaining_inscription_count`](#0x3_brc20_remaining_inscription_count)
- [Function `progress_brc20_ops`](#0x3_brc20_progress_brc20_ops)


<pre><code><b>use</b> <a href="">0x1::debug</a>;
<b>use</b> <a href="">0x1::option</a>;
<b>use</b> <a href="">0x1::string</a>;
<b>use</b> <a href="">0x2::context</a>;
<b>use</b> <a href="">0x2::json</a>;
<b>use</b> <a href="">0x2::object</a>;
<b>use</b> <a href="">0x2::simple_map</a>;
<b>use</b> <a href="">0x2::string_utils</a>;
<b>use</b> <a href="">0x2::table</a>;
<b>use</b> <a href="">0x2::table_vec</a>;
<b>use</b> <a href="bitcoin_address.md#0x3_bitcoin_address">0x3::bitcoin_address</a>;
<b>use</b> <a href="ord.md#0x3_ord">0x3::ord</a>;
</code></pre>



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

## Struct `BRC20CoinInfo`



<pre><code><b>struct</b> <a href="brc20.md#0x3_brc20_BRC20CoinInfo">BRC20CoinInfo</a> <b>has</b> store
</code></pre>



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

## Resource `BRC20Store`



<pre><code><b>struct</b> <a href="brc20.md#0x3_brc20_BRC20Store">BRC20Store</a> <b>has</b> key
</code></pre>



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

## Struct `Op`

The brc20 operation


<pre><code><b>struct</b> <a href="brc20.md#0x3_brc20_Op">Op</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Struct `DeployOp`

The brc20 deploy operation
https://domo-2.gitbook.io/brc-20-experiment/
```json
{
"p": "brc-20",
"op": "deploy",
"tick": "ordi",
"max": "21000000",
"lim": "1000"
}
```


<pre><code><b>struct</b> <a href="brc20.md#0x3_brc20_DeployOp">DeployOp</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Struct `MintOp`

The brc20 mint operation
https://domo-2.gitbook.io/brc-20-experiment/
```json
{
"p": "brc-20",
"op": "mint",
"tick": "ordi",
"amt": "1000"
}
```


<pre><code><b>struct</b> <a href="brc20.md#0x3_brc20_MintOp">MintOp</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Struct `TransferOp`

The brc20 transfer operation
https://domo-2.gitbook.io/brc-20-experiment/
```json
{
"p": "brc-20",
"op": "transfer",
"tick": "ordi",
"amt": "100"
}


<pre><code><b>struct</b> <a href="brc20.md#0x3_brc20_TransferOp">TransferOp</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Function `genesis_init`



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="brc20.md#0x3_brc20_genesis_init">genesis_init</a>(ctx: &<b>mut</b> <a href="_Context">context::Context</a>, _genesis_account: &<a href="">signer</a>)
</code></pre>



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

## Function `is_brc20`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_is_brc20">is_brc20</a>(self: &<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>): bool
</code></pre>



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

## Function `is_deploy`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_is_deploy">is_deploy</a>(self: &<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>): bool
</code></pre>



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

## Function `as_deploy`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_as_deploy">as_deploy</a>(self: &<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>): <a href="_Option">option::Option</a>&lt;<a href="brc20.md#0x3_brc20_DeployOp">brc20::DeployOp</a>&gt;
</code></pre>



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

## Function `is_mint`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_is_mint">is_mint</a>(self: &<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>): bool
</code></pre>



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

## Function `as_mint`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_as_mint">as_mint</a>(self: &<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>): <a href="_Option">option::Option</a>&lt;<a href="brc20.md#0x3_brc20_MintOp">brc20::MintOp</a>&gt;
</code></pre>



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

## Function `is_transfer`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_is_transfer">is_transfer</a>(self: &<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>): bool
</code></pre>



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

## Function `as_transfer`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_as_transfer">as_transfer</a>(self: &<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>): <a href="_Option">option::Option</a>&lt;<a href="brc20.md#0x3_brc20_TransferOp">brc20::TransferOp</a>&gt;
</code></pre>



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

## Function `from_inscription`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_from_inscription">from_inscription</a>(inscription: &<a href="ord.md#0x3_ord_Inscription">ord::Inscription</a>): <a href="_Option">option::Option</a>&lt;<a href="brc20.md#0x3_brc20_Op">brc20::Op</a>&gt;
</code></pre>



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

## Function `remaining_inscription_count`



<pre><code><b>public</b> <b>fun</b> <a href="brc20.md#0x3_brc20_remaining_inscription_count">remaining_inscription_count</a>(inscription_store_obj: &<a href="_Object">object::Object</a>&lt;<a href="ord.md#0x3_ord_InscriptionStore">ord::InscriptionStore</a>&gt;, brc20_store_obj: &<a href="_Object">object::Object</a>&lt;<a href="brc20.md#0x3_brc20_BRC20Store">brc20::BRC20Store</a>&gt;): u64
</code></pre>



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

## Function `progress_brc20_ops`



<pre><code>entry <b>fun</b> <a href="brc20.md#0x3_brc20_progress_brc20_ops">progress_brc20_ops</a>(inscription_store_obj: &<a href="_Object">object::Object</a>&lt;<a href="ord.md#0x3_ord_InscriptionStore">ord::InscriptionStore</a>&gt;, brc20_store_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="brc20.md#0x3_brc20_BRC20Store">brc20::BRC20Store</a>&gt;, batch_size: u64)
</code></pre>
1 change: 1 addition & 0 deletions crates/rooch-framework/doc/genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<b>use</b> <a href="address_mapping.md#0x3_address_mapping">0x3::address_mapping</a>;
<b>use</b> <a href="auth_validator_registry.md#0x3_auth_validator_registry">0x3::auth_validator_registry</a>;
<b>use</b> <a href="bitcoin_light_client.md#0x3_bitcoin_light_client">0x3::bitcoin_light_client</a>;
<b>use</b> <a href="brc20.md#0x3_brc20">0x3::brc20</a>;
<b>use</b> <a href="builtin_validators.md#0x3_builtin_validators">0x3::builtin_validators</a>;
<b>use</b> <a href="chain_id.md#0x3_chain_id">0x3::chain_id</a>;
<b>use</b> <a href="coin.md#0x3_coin">0x3::coin</a>;
Expand Down
Loading

0 comments on commit 890bc93

Please sign in to comment.