Skip to content

Commit

Permalink
[framework] add unpack_transfer_utxo_event function (#2502)
Browse files Browse the repository at this point in the history
Co-authored-by: mx819812523 <mx819812523@gamil.com>
  • Loading branch information
mx819812523 and mx819812523 authored Aug 25, 2024
1 parent ade1518 commit eec9225
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
15 changes: 13 additions & 2 deletions frameworks/bitcoin-move/doc/bitcoin.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
- [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)


<pre><code><b>use</b> <a href="">0x1::debug</a>;
<b>use</b> <a href="">0x1::option</a>;
<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::address</a>;
Expand Down Expand Up @@ -270,3 +270,14 @@ Get the bitcoin time in seconds

<pre><code><b>public</b> <b>fun</b> <a href="bitcoin.md#0x4_bitcoin_contains_header">contains_header</a>(block_header: &<a href="types.md#0x4_types_Header">types::Header</a>): bool
</code></pre>



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

## Function `unpack_transfer_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)
</code></pre>
12 changes: 8 additions & 4 deletions frameworks/bitcoin-move/sources/bitcoin.move
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ module bitcoin_move::bitcoin{
txid: types::tx_id(tx),
message: string::utf8(b"utxo not exists"),
});
std::debug::print(&outpoint);
//We allow the utxo not exists in the utxo store, because we may not sync the block from genesis
//But we should not allow the utxo not exists in the mainnet
if(chain_id::is_main()){
Expand Down Expand Up @@ -330,12 +329,12 @@ module bitcoin_move::bitcoin{
let block = bcs::from_bytes<Block>(block_bytes);
let block_header = types::header(&block);
let time = types::time(block_header);
pending_block::add_pending_block(block_height, block_hash, block);
pending_block::add_pending_block(block_height, block_hash, block);
//We directly update the global time do not wait the pending block to be confirmed
//The reorg do not affect the global time
let timestamp_seconds = (time as u64);
let module_signer = signer::module_signer<BitcoinBlockStore>();
timestamp::try_update_global_time(&module_signer, timestamp::seconds_to_milliseconds(timestamp_seconds));
timestamp::try_update_global_time(&module_signer, timestamp::seconds_to_milliseconds(timestamp_seconds));
}

/// This is the execute_l1_tx entry point
Expand All @@ -356,7 +355,7 @@ module bitcoin_move::bitcoin{
vector::append(flotsams, tx_flotsams);
pending_block::finish_pending_tx(inprocess_block);
};
}
}

public fun get_tx(txid: address): Option<Transaction>{
let btc_block_store_obj = borrow_block_store();
Expand Down Expand Up @@ -491,4 +490,9 @@ 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;
(txid, sender, receiver, value)
}

}

0 comments on commit eec9225

Please sign in to comment.