Skip to content

Commit

Permalink
[bitcoin_move] process Babylon protocol when processing Bitcoin trans…
Browse files Browse the repository at this point in the history
…actions (rooch-network#2988)

* [bitcoin_move] process Babylon protocol when process Bitcoin tx

* [bbn] Init BBN Cap 3 global parameters

* [bbn] Unbunding bbn stake when UTXO spent

* update docs

* [bbn] Remove assert in process_bbn_transaction
  • Loading branch information
jolestar authored and steelgeek091 committed Dec 22, 2024
1 parent f429275 commit 59b24dc
Show file tree
Hide file tree
Showing 7 changed files with 516 additions and 53 deletions.
1 change: 1 addition & 0 deletions frameworks/bitcoin-move/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is the reference documentation of the Bitcoin Move Framework.


- [`0x4::bbn`](bbn.md#0x4_bbn)
- [`0x4::bbn_updater`](bbn_updater.md#0x4_bbn_updater)
- [`0x4::bitcoin`](bitcoin.md#0x4_bitcoin)
- [`0x4::bitcoin_hash`](bitcoin_hash.md#0x4_bitcoin_hash)
- [`0x4::bitcoin_multisign_validator`](bitcoin_multisign_validator.md#0x4_bitcoin_multisign_validator)
Expand Down
159 changes: 155 additions & 4 deletions frameworks/bitcoin-move/doc/bbn.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
- [Struct `BBNScriptPaths`](#0x4_bbn_BBNScriptPaths)
- [Struct `BBNStakingEvent`](#0x4_bbn_BBNStakingEvent)
- [Struct `BBNStakingFailedEvent`](#0x4_bbn_BBNStakingFailedEvent)
- [Struct `BBNStakingUnbondingEvent`](#0x4_bbn_BBNStakingUnbondingEvent)
- [Struct `TempStateDropEvent`](#0x4_bbn_TempStateDropEvent)
- [Constants](#@Constants_0)
- [Function `genesis_init`](#0x4_bbn_genesis_init)
- [Function `init_for_upgrade`](#0x4_bbn_init_for_upgrade)
- [Function `init_bbn_global_param_v2`](#0x4_bbn_init_bbn_global_param_v2)
- [Function `is_possible_bbn_tx`](#0x4_bbn_is_possible_bbn_tx)
- [Function `is_possible_bbn_transaction`](#0x4_bbn_is_possible_bbn_transaction)
- [Function `process_bbn_tx_entry`](#0x4_bbn_process_bbn_tx_entry)
- [Function `process_bbn_transaction`](#0x4_bbn_process_bbn_transaction)
- [Function `on_utxo_spend`](#0x4_bbn_on_utxo_spend)
- [Function `remove_bbn_seal`](#0x4_bbn_remove_bbn_seal)
- [Function `add_temp_state`](#0x4_bbn_add_temp_state)
- [Function `contains_temp_state`](#0x4_bbn_contains_temp_state)
- [Function `borrow_temp_state`](#0x4_bbn_borrow_temp_state)
Expand All @@ -34,19 +41,20 @@
- [Function `staking_time`](#0x4_bbn_staking_time)
- [Function `staking_value`](#0x4_bbn_staking_value)
- [Function `is_expired`](#0x4_bbn_is_expired)
- [Function `is_expired_at`](#0x4_bbn_is_expired_at)


<pre><code><b>use</b> <a href="">0x1::option</a>;
<b>use</b> <a href="">0x1::string</a>;
<b>use</b> <a href="">0x1::vector</a>;
<b>use</b> <a href="">0x2::bcs</a>;
<b>use</b> <a href="">0x2::event</a>;
<b>use</b> <a href="">0x2::event_queue</a>;
<b>use</b> <a href="">0x2::object</a>;
<b>use</b> <a href="">0x2::result</a>;
<b>use</b> <a href="">0x2::sort</a>;
<b>use</b> <a href="">0x2::type_info</a>;
<b>use</b> <a href="">0x3::bitcoin_address</a>;
<b>use</b> <a href="bitcoin.md#0x4_bitcoin">0x4::bitcoin</a>;
<b>use</b> <a href="opcode.md#0x4_opcode">0x4::opcode</a>;
<b>use</b> <a href="script_buf.md#0x4_script_buf">0x4::script_buf</a>;
<b>use</b> <a href="taproot_builder.md#0x4_taproot_builder">0x4::taproot_builder</a>;
Expand Down Expand Up @@ -156,6 +164,31 @@



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

## Struct `BBNStakingUnbondingEvent`



<pre><code><b>struct</b> <a href="bbn.md#0x4_bbn_BBNStakingUnbondingEvent">BBNStakingUnbondingEvent</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Struct `TempStateDropEvent`

Event emitted when the temporary state of a BBNStakeSeal is dropped
The temporary state is dropped when the UTXO is spent
The event is onchain event, and the event_queue name is type_name of the temporary state


<pre><code><b>struct</b> <a href="bbn.md#0x4_bbn_TempStateDropEvent">TempStateDropEvent</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Constants
Expand All @@ -179,6 +212,51 @@



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



<pre><code><b>const</b> <a href="bbn.md#0x4_bbn_BBN_V1_ACTIVATION_HEIGHT">BBN_V1_ACTIVATION_HEIGHT</a>: u64 = 864790;
</code></pre>



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



<pre><code><b>const</b> <a href="bbn.md#0x4_bbn_BBN_V1_CAP_HEIGHT">BBN_V1_CAP_HEIGHT</a>: u64 = 864799;
</code></pre>



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



<pre><code><b>const</b> <a href="bbn.md#0x4_bbn_BBN_V2_ACTIVATION_HEIGHT">BBN_V2_ACTIVATION_HEIGHT</a>: u64 = 874088;
</code></pre>



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



<pre><code><b>const</b> <a href="bbn.md#0x4_bbn_BBN_V2_CAP_HEIGHT">BBN_V2_CAP_HEIGHT</a>: u64 = 875087;
</code></pre>



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



<pre><code><b>const</b> <a href="bbn.md#0x4_bbn_DeprecatedFunction">DeprecatedFunction</a>: u64 = 16;
</code></pre>



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


Expand Down Expand Up @@ -336,15 +414,40 @@



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

## Function `init_bbn_global_param_v2`

BBN global param version 2 initialization


<pre><code>entry <b>fun</b> <a href="bbn.md#0x4_bbn_init_bbn_global_param_v2">init_bbn_global_param_v2</a>()
</code></pre>



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

## Function `is_possible_bbn_tx`

Deprecated function
Use <code><a href="bbn_updater.md#0x4_bbn_updater_is_possible_bbn_tx">bbn_updater::is_possible_bbn_tx</a></code> instead


<pre><code><b>public</b> <b>fun</b> <a href="bbn.md#0x4_bbn_is_possible_bbn_tx">is_possible_bbn_tx</a>(_txid: <b>address</b>): bool
</code></pre>



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

## Function `is_possible_bbn_transaction`

Check if the transaction is a possible Babylon transaction
If the transaction contains an OP_RETURN output with the correct tag, it is considered a possible Babylon transaction


<pre><code><b>public</b> <b>fun</b> <a href="bbn.md#0x4_bbn_is_possible_bbn_tx">is_possible_bbn_tx</a>(txid: <b>address</b>): bool
<pre><code><b>public</b> <b>fun</b> <a href="bbn.md#0x4_bbn_is_possible_bbn_transaction">is_possible_bbn_transaction</a>(block_height: u64, tx: &<a href="types.md#0x4_types_Transaction">types::Transaction</a>): bool
</code></pre>


Expand All @@ -353,9 +456,44 @@ If the transaction contains an OP_RETURN output with the correct tag, it is cons

## Function `process_bbn_tx_entry`

Deprecated function
Use <code><a href="bbn_updater.md#0x4_bbn_updater_process_bbn_tx_entry">bbn_updater::process_bbn_tx_entry</a></code> instead


<pre><code><b>public</b> entry <b>fun</b> <a href="bbn.md#0x4_bbn_process_bbn_tx_entry">process_bbn_tx_entry</a>(_txid: <b>address</b>)
</code></pre>



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

## Function `process_bbn_transaction`



<pre><code><b>public</b> entry <b>fun</b> <a href="bbn.md#0x4_bbn_process_bbn_tx_entry">process_bbn_tx_entry</a>(txid: <b>address</b>)
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="bbn.md#0x4_bbn_process_bbn_transaction">process_bbn_transaction</a>(block_height: u64, tx: &<a href="types.md#0x4_types_Transaction">types::Transaction</a>)
</code></pre>



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

## Function `on_utxo_spend`



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="bbn.md#0x4_bbn_on_utxo_spend">on_utxo_spend</a>(<a href="utxo.md#0x4_utxo">utxo</a>: &<b>mut</b> <a href="utxo.md#0x4_utxo_UTXO">utxo::UTXO</a>)
</code></pre>



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

## Function `remove_bbn_seal`



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="bbn.md#0x4_bbn_remove_bbn_seal">remove_bbn_seal</a>(seal_obj_id: <a href="_ObjectID">object::ObjectID</a>)
</code></pre>


Expand Down Expand Up @@ -521,7 +659,20 @@ If the transaction contains an OP_RETURN output with the correct tag, it is cons

## Function `is_expired`

Deprecated function
Use <code><a href="bbn_updater.md#0x4_bbn_updater_is_expired">bbn_updater::is_expired</a></code> instead


<pre><code><b>public</b> <b>fun</b> <a href="bbn.md#0x4_bbn_is_expired">is_expired</a>(_stake: &<a href="bbn.md#0x4_bbn_BBNStakeSeal">bbn::BBNStakeSeal</a>): bool
</code></pre>



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

## Function `is_expired_at`



<pre><code><b>public</b> <b>fun</b> <a href="bbn.md#0x4_bbn_is_expired">is_expired</a>(stake: &<a href="bbn.md#0x4_bbn_BBNStakeSeal">bbn::BBNStakeSeal</a>): bool
<pre><code><b>public</b> <b>fun</b> <a href="bbn.md#0x4_bbn_is_expired_at">is_expired_at</a>(stake: &<a href="bbn.md#0x4_bbn_BBNStakeSeal">bbn::BBNStakeSeal</a>, current_block_height: u64): bool
</code></pre>
81 changes: 81 additions & 0 deletions frameworks/bitcoin-move/doc/bbn_updater.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

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

# Module `0x4::bbn_updater`



- [Constants](#@Constants_0)
- [Function `is_possible_bbn_tx`](#0x4_bbn_updater_is_possible_bbn_tx)
- [Function `process_bbn_tx_entry`](#0x4_bbn_updater_process_bbn_tx_entry)
- [Function `is_expired`](#0x4_bbn_updater_is_expired)
- [Function `clear_unbonded_stakes`](#0x4_bbn_updater_clear_unbonded_stakes)


<pre><code><b>use</b> <a href="">0x1::option</a>;
<b>use</b> <a href="">0x2::object</a>;
<b>use</b> <a href="bbn.md#0x4_bbn">0x4::bbn</a>;
<b>use</b> <a href="bitcoin.md#0x4_bitcoin">0x4::bitcoin</a>;
<b>use</b> <a href="types.md#0x4_types">0x4::types</a>;
<b>use</b> <a href="utxo.md#0x4_utxo">0x4::utxo</a>;
</code></pre>



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

## Constants


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



<pre><code><b>const</b> <a href="bbn_updater.md#0x4_bbn_updater_ErrorTransactionNotFound">ErrorTransactionNotFound</a>: u64 = 1;
</code></pre>



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

## Function `is_possible_bbn_tx`

Check if the transaction is a possible Babylon transaction
If the transaction contains an OP_RETURN output with the correct tag, it is considered a possible Babylon transaction


<pre><code><b>public</b> <b>fun</b> <a href="bbn_updater.md#0x4_bbn_updater_is_possible_bbn_tx">is_possible_bbn_tx</a>(txid: <b>address</b>): bool
</code></pre>



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

## Function `process_bbn_tx_entry`



<pre><code><b>public</b> entry <b>fun</b> <a href="bbn_updater.md#0x4_bbn_updater_process_bbn_tx_entry">process_bbn_tx_entry</a>(txid: <b>address</b>)
</code></pre>



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

## Function `is_expired`



<pre><code><b>public</b> <b>fun</b> <a href="bbn_updater.md#0x4_bbn_updater_is_expired">is_expired</a>(stake: &<a href="bbn.md#0x4_bbn_BBNStakeSeal">bbn::BBNStakeSeal</a>): bool
</code></pre>



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

## Function `clear_unbonded_stakes`



<pre><code><b>public</b> entry <b>fun</b> <a href="bbn_updater.md#0x4_bbn_updater_clear_unbonded_stakes">clear_unbonded_stakes</a>(seal_obj_id: <a href="_ObjectID">object::ObjectID</a>)
</code></pre>
1 change: 1 addition & 0 deletions frameworks/bitcoin-move/doc/bitcoin.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<b>use</b> <a href="">0x3::address_mapping</a>;
<b>use</b> <a href="">0x3::bitcoin_address</a>;
<b>use</b> <a href="">0x3::chain_id</a>;
<b>use</b> <a href="bbn.md#0x4_bbn">0x4::bbn</a>;
<b>use</b> <a href="inscription_updater.md#0x4_inscription_updater">0x4::inscription_updater</a>;
<b>use</b> <a href="network.md#0x4_network">0x4::network</a>;
<b>use</b> <a href="pending_block.md#0x4_pending_block">0x4::pending_block</a>;
Expand Down
Loading

0 comments on commit 59b24dc

Please sign in to comment.