Skip to content

Commit

Permalink
[framework] oracle and fix bcs and refactor utxo event (#2512)
Browse files Browse the repository at this point in the history
* [framework] oracle and fix bcs and refactor utxo event

* fix: add test for bcs and refactor sort function

* fix: doc

* fix: remove entry for submit_data

* fix: framework v8

* fix: remove archive_data entry

---------

Co-authored-by: mx819812523 <mx819812523@gamil.com>
  • Loading branch information
mx819812523 and mx819812523 committed Aug 27, 2024
1 parent 98367ad commit 20efb48
Show file tree
Hide file tree
Showing 27 changed files with 1,040 additions and 266 deletions.
40 changes: 32 additions & 8 deletions frameworks/bitcoin-move/doc/bitcoin.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
- [Struct `UTXONotExistsEvent`](#0x4_bitcoin_UTXONotExistsEvent)
- [Struct `RepeatCoinbaseTxEvent`](#0x4_bitcoin_RepeatCoinbaseTxEvent)
- [Resource `BitcoinBlockStore`](#0x4_bitcoin_BitcoinBlockStore)
- [Struct `TransferUTXOEvent`](#0x4_bitcoin_TransferUTXOEvent)
- [Struct `SpendUTXOEvent`](#0x4_bitcoin_SpendUTXOEvent)
- [Struct `ReceiveUTXOEvent`](#0x4_bitcoin_ReceiveUTXOEvent)
- [Constants](#@Constants_0)
- [Function `genesis_init`](#0x4_bitcoin_genesis_init)
- [Function `get_tx`](#0x4_bitcoin_get_tx)
Expand All @@ -21,7 +22,8 @@
- [Function `get_latest_block`](#0x4_bitcoin_get_latest_block)
- [Function `get_bitcoin_time`](#0x4_bitcoin_get_bitcoin_time)
- [Function `contains_header`](#0x4_bitcoin_contains_header)
- [Function `unpack_transfer_utxo_event`](#0x4_bitcoin_unpack_transfer_utxo_event)
- [Function `unpack_spend_utxo_event`](#0x4_bitcoin_unpack_spend_utxo_event)
- [Function `unpack_receive_utxo_event`](#0x4_bitcoin_unpack_receive_utxo_event)


<pre><code><b>use</b> <a href="">0x1::option</a>;
Expand Down Expand Up @@ -81,13 +83,24 @@



<a name="0x4_bitcoin_TransferUTXOEvent"></a>
<a name="0x4_bitcoin_SpendUTXOEvent"></a>

## Struct `TransferUTXOEvent`
## Struct `SpendUTXOEvent`



<pre><code><b>struct</b> <a href="bitcoin.md#0x4_bitcoin_TransferUTXOEvent">TransferUTXOEvent</a> <b>has</b> <b>copy</b>, drop, store
<pre><code><b>struct</b> <a href="bitcoin.md#0x4_bitcoin_SpendUTXOEvent">SpendUTXOEvent</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Struct `ReceiveUTXOEvent`



<pre><code><b>struct</b> <a href="bitcoin.md#0x4_bitcoin_ReceiveUTXOEvent">ReceiveUTXOEvent</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>


Expand Down Expand Up @@ -280,11 +293,22 @@ Get the bitcoin time in seconds



<a name="0x4_bitcoin_unpack_transfer_utxo_event"></a>
<a name="0x4_bitcoin_unpack_spend_utxo_event"></a>

## Function `unpack_spend_utxo_event`



<pre><code><b>public</b> <b>fun</b> <a href="bitcoin.md#0x4_bitcoin_unpack_spend_utxo_event">unpack_spend_utxo_event</a>(<a href="">event</a>: <a href="bitcoin.md#0x4_bitcoin_SpendUTXOEvent">bitcoin::SpendUTXOEvent</a>): (<b>address</b>, <b>address</b>, <a href="_Option">option::Option</a>&lt;<b>address</b>&gt;, u64)
</code></pre>



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

## Function `unpack_transfer_utxo_event`
## Function `unpack_receive_utxo_event`



<pre><code><b>public</b> <b>fun</b> <a href="bitcoin.md#0x4_bitcoin_unpack_transfer_utxo_event">unpack_transfer_utxo_event</a>(<a href="">event</a>: <a href="bitcoin.md#0x4_bitcoin_TransferUTXOEvent">bitcoin::TransferUTXOEvent</a>): (<b>address</b>, <a href="_Option">option::Option</a>&lt;<b>address</b>&gt;, <b>address</b>, u64)
<pre><code><b>public</b> <b>fun</b> <a href="bitcoin.md#0x4_bitcoin_unpack_receive_utxo_event">unpack_receive_utxo_event</a>(<a href="">event</a>: <a href="bitcoin.md#0x4_bitcoin_ReceiveUTXOEvent">bitcoin::ReceiveUTXOEvent</a>): (<b>address</b>, <a href="_Option">option::Option</a>&lt;<b>address</b>&gt;, <b>address</b>, u64)
</code></pre>
31 changes: 24 additions & 7 deletions frameworks/bitcoin-move/sources/bitcoin.move
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ module bitcoin_move::bitcoin{
}


struct TransferUTXOEvent has drop, store, copy {
struct SpendUTXOEvent has drop, store, copy {
txid: address,
sender: address,
receiver: Option<address>,
value: u64
}

struct ReceiveUTXOEvent has drop, store, copy {
txid: address,
sender: Option<address>,
receiver: address,
Expand Down Expand Up @@ -237,7 +244,7 @@ module bitcoin_move::bitcoin{
let owner_address = types::txout_object_address(txout);
utxo::transfer(utxo_obj, owner_address);
if (owner_address != @bitcoin_move){
event_queue::emit(to_string(&owner_address), TransferUTXOEvent{
event_queue::emit(to_string(&owner_address), ReceiveUTXOEvent {
txid,
sender,
receiver: owner_address,
Expand All @@ -246,10 +253,15 @@ module bitcoin_move::bitcoin{
};
if (option::is_some(&sender)){
let sender_address = option::extract(&mut sender);
event_queue::emit(to_string(&sender_address), TransferUTXOEvent{
let receiver_address = if (owner_address != @bitcoin_move) {
option::some(owner_address)
}else {
option::none<address>()
};
event_queue::emit(to_string(&sender_address), SpendUTXOEvent {
txid,
sender,
receiver: owner_address,
sender: sender_address,
receiver: receiver_address,
value
});
};
Expand Down Expand Up @@ -420,8 +432,13 @@ module bitcoin_move::bitcoin{
execute_l1_tx(block_hash, types::tx_id(&coinbase_tx));
}

public fun unpack_transfer_utxo_event(event: TransferUTXOEvent): (address, Option<address>, address, u64) {
let TransferUTXOEvent { txid, sender, receiver, value } = event;
public fun unpack_spend_utxo_event(event: SpendUTXOEvent): (address, address, Option<address>, u64) {
let SpendUTXOEvent { txid, sender, receiver, value } = event;
(txid, sender, receiver, value)
}

public fun unpack_receive_utxo_event(event: ReceiveUTXOEvent): (address, Option<address>, address, u64) {
let ReceiveUTXOEvent { txid, sender, receiver, value } = event;
(txid, sender, receiver, value)
}

Expand Down
Binary file modified frameworks/framework-release/released/8/stdlib
Binary file not shown.
1 change: 1 addition & 0 deletions frameworks/moveos-stdlib/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This is the reference documentation of the MoveOS standard library.
- [`0x2::compare`](compare.md#0x2_compare)
- [`0x2::copyable_any`](copyable_any.md#0x2_copyable_any)
- [`0x2::core_addresses`](core_addresses.md#0x2_core_addresses)
- [`0x2::decimal_value`](decimal_value.md#0x2_decimal_value)
- [`0x2::display`](display.md#0x2_display)
- [`0x2::event`](event.md#0x2_event)
- [`0x2::event_queue`](event_queue.md#0x2_event_queue)
Expand Down
4 changes: 2 additions & 2 deletions frameworks/moveos-stdlib/doc/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The length of an address, in bytes



<pre><code><b>const</b> <a href="address.md#0x2_address_MAX">MAX</a>: u256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
<pre><code><b>const</b> <a href="address.md#0x2_address_MAX">MAX</a>: <a href="">u256</a> = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
</code></pre>


Expand Down Expand Up @@ -207,7 +207,7 @@ Length of a Rooch address in bytes
Largest possible address


<pre><code><b>public</b> <b>fun</b> <a href="address.md#0x2_address_max">max</a>(): u256
<pre><code><b>public</b> <b>fun</b> <a href="address.md#0x2_address_max">max</a>(): <a href="">u256</a>
</code></pre>


Expand Down
12 changes: 6 additions & 6 deletions frameworks/moveos-stdlib/doc/bcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ Read <code>u128</code> value from bcs-serialized bytes.

## Function `peel_u256`

Read <code>u256</code> value from bcs-serialized bytes.
Read <code><a href="">u256</a></code> value from bcs-serialized bytes.


<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x2_bcs_peel_u256">peel_u256</a>(<a href="">bcs</a>: &<b>mut</b> bcs::BCS): u256
<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x2_bcs_peel_u256">peel_u256</a>(<a href="">bcs</a>: &<b>mut</b> bcs::BCS): <a href="">u256</a>
</code></pre>


Expand Down Expand Up @@ -435,10 +435,10 @@ Peel a vector of <code>u128</code> from serialized bytes.

## Function `peel_vec_u256`

Peel a vector of <code>u256</code> from serialized bytes.
Peel a vector of <code><a href="">u256</a></code> from serialized bytes.


<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x2_bcs_peel_vec_u256">peel_vec_u256</a>(<a href="">bcs</a>: &<b>mut</b> bcs::BCS): <a href="">vector</a>&lt;u256&gt;
<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x2_bcs_peel_vec_u256">peel_vec_u256</a>(<a href="">bcs</a>: &<b>mut</b> bcs::BCS): <a href="">vector</a>&lt;<a href="">u256</a>&gt;
</code></pre>


Expand Down Expand Up @@ -531,10 +531,10 @@ Peel <code>Option&lt;u128&gt;</code> from serialized bytes.

## Function `peel_option_u256`

Peel <code>Option&lt;u256&gt;</code> from serialized bytes.
Peel <code>Option&lt;<a href="">u256</a>&gt;</code> from serialized bytes.


<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x2_bcs_peel_option_u256">peel_option_u256</a>(<a href="">bcs</a>: &<b>mut</b> bcs::BCS): <a href="_Option">option::Option</a>&lt;u256&gt;
<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x2_bcs_peel_option_u256">peel_option_u256</a>(<a href="">bcs</a>: &<b>mut</b> bcs::BCS): <a href="_Option">option::Option</a>&lt;<a href="">u256</a>&gt;
</code></pre>


Expand Down
2 changes: 2 additions & 0 deletions frameworks/moveos-stdlib/doc/compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Utilities for comparing Move values

<pre><code><b>use</b> <a href="">0x1::compare</a>;
<b>use</b> <a href="">0x1::type_name</a>;
<b>use</b> <a href="">0x1::u256</a>;
<b>use</b> <a href="bcs.md#0x2_bcs">0x2::bcs</a>;
<b>use</b> <a href="decimal_value.md#0x2_decimal_value">0x2::decimal_value</a>;
</code></pre>


Expand Down
58 changes: 58 additions & 0 deletions frameworks/moveos-stdlib/doc/decimal_value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

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

# Module `0x2::decimal_value`



- [Struct `DecimalValue`](#0x2_decimal_value_DecimalValue)
- [Function `new`](#0x2_decimal_value_new)
- [Function `value`](#0x2_decimal_value_value)
- [Function `decimal`](#0x2_decimal_value_decimal)


<pre><code></code></pre>



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

## Struct `DecimalValue`



<pre><code><b>struct</b> <a href="decimal_value.md#0x2_decimal_value_DecimalValue">DecimalValue</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



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

## Function `new`



<pre><code><b>public</b> <b>fun</b> <a href="decimal_value.md#0x2_decimal_value_new">new</a>(value: u64, decimal: u8): <a href="decimal_value.md#0x2_decimal_value_DecimalValue">decimal_value::DecimalValue</a>
</code></pre>



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

## Function `value`



<pre><code><b>public</b> <b>fun</b> <a href="decimal_value.md#0x2_decimal_value_value">value</a>(self: &<a href="decimal_value.md#0x2_decimal_value_DecimalValue">decimal_value::DecimalValue</a>): u64
</code></pre>



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

## Function `decimal`



<pre><code><b>public</b> <b>fun</b> <a href="decimal_value.md#0x2_decimal_value_decimal">decimal</a>(self: &<a href="decimal_value.md#0x2_decimal_value_DecimalValue">decimal_value::DecimalValue</a>): u8
</code></pre>
4 changes: 2 additions & 2 deletions frameworks/moveos-stdlib/doc/move_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Replace given u64 constant to the new ones
Replace given u256 constant to the new ones


<pre><code><b>public</b> <b>fun</b> <a href="move_module.md#0x2_move_module_replace_constant_u256">replace_constant_u256</a>(modules: <a href="">vector</a>&lt;<a href="move_module.md#0x2_move_module_MoveModule">move_module::MoveModule</a>&gt;, old_u256s: <a href="">vector</a>&lt;u256&gt;, new_u256s: <a href="">vector</a>&lt;u256&gt;): <a href="">vector</a>&lt;<a href="move_module.md#0x2_move_module_MoveModule">move_module::MoveModule</a>&gt;
<pre><code><b>public</b> <b>fun</b> <a href="move_module.md#0x2_move_module_replace_constant_u256">replace_constant_u256</a>(modules: <a href="">vector</a>&lt;<a href="move_module.md#0x2_move_module_MoveModule">move_module::MoveModule</a>&gt;, old_u256s: <a href="">vector</a>&lt;<a href="">u256</a>&gt;, new_u256s: <a href="">vector</a>&lt;<a href="">u256</a>&gt;): <a href="">vector</a>&lt;<a href="move_module.md#0x2_move_module_MoveModule">move_module::MoveModule</a>&gt;
</code></pre>


Expand Down Expand Up @@ -393,5 +393,5 @@ Native function to replace constant u256 in module binary where the length of
<code>old_u256s</code> must equal to that of <code>new_u256s</code>.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="move_module.md#0x2_move_module_replace_u256_constant">replace_u256_constant</a>(bytes: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, old_u256s: <a href="">vector</a>&lt;u256&gt;, new_u256s: <a href="">vector</a>&lt;u256&gt;): <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="move_module.md#0x2_move_module_replace_u256_constant">replace_u256_constant</a>(bytes: <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;, old_u256s: <a href="">vector</a>&lt;<a href="">u256</a>&gt;, new_u256s: <a href="">vector</a>&lt;<a href="">u256</a>&gt;): <a href="">vector</a>&lt;<a href="">vector</a>&lt;u8&gt;&gt;
</code></pre>
10 changes: 5 additions & 5 deletions frameworks/moveos-stdlib/doc/string_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_u256_option">parse_u256_option</a>(s: &<a href="_String">string::String</a>): <a href="_Option">option::Option</a>&lt;u256&gt;
<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_u256_option">parse_u256_option</a>(s: &<a href="_String">string::String</a>): <a href="_Option">option::Option</a>&lt;<a href="">u256</a>&gt;
</code></pre>


Expand All @@ -127,7 +127,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_u256">parse_u256</a>(s: &<a href="_String">string::String</a>): u256
<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_u256">parse_u256</a>(s: &<a href="_String">string::String</a>): <a href="">u256</a>
</code></pre>


Expand All @@ -138,7 +138,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_decimal_option">parse_decimal_option</a>(s: &<a href="_String">string::String</a>, decimal: u64): <a href="_Option">option::Option</a>&lt;u256&gt;
<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_decimal_option">parse_decimal_option</a>(s: &<a href="_String">string::String</a>, decimal: u64): <a href="_Option">option::Option</a>&lt;<a href="">u256</a>&gt;
</code></pre>


Expand All @@ -149,7 +149,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_decimal">parse_decimal</a>(s: &<a href="_String">string::String</a>, decimal: u64): u256
<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_parse_decimal">parse_decimal</a>(s: &<a href="_String">string::String</a>, decimal: u64): <a href="">u256</a>
</code></pre>


Expand Down Expand Up @@ -182,7 +182,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_to_string_u256">to_string_u256</a>(n: u256): <a href="_String">string::String</a>
<pre><code><b>public</b> <b>fun</b> <a href="string_utils.md#0x2_string_utils_to_string_u256">to_string_u256</a>(n: <a href="">u256</a>): <a href="_String">string::String</a>
</code></pre>


Expand Down
Loading

0 comments on commit 20efb48

Please sign in to comment.