-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bitcoin_move] process Babylon protocol when process Bitcoin tx
- Loading branch information
Showing
3 changed files
with
86 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module bitcoin_move::bbn_updater { | ||
|
||
use std::option::{Self, is_none, is_some}; | ||
|
||
use bitcoin_move::types; | ||
use bitcoin_move::bbn::{Self, BBNStakeSeal}; | ||
use bitcoin_move::bitcoin; | ||
|
||
const ErrorTransactionNotFound: u64 = 1; | ||
|
||
/// 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 | ||
public fun is_possible_bbn_tx(txid: address): bool { | ||
let block_height_opt = bitcoin::get_tx_height(txid); | ||
if (is_none(&block_height_opt)) { | ||
return false | ||
}; | ||
let block_height = option::destroy_some(block_height_opt); | ||
let tx_opt = bitcoin::get_tx(txid); | ||
if (is_none(&tx_opt)) { | ||
return false | ||
}; | ||
let tx = option::destroy_some(tx_opt); | ||
bbn::is_possible_bbn_transaction(block_height, &tx) | ||
} | ||
|
||
public entry fun process_bbn_tx_entry(txid: address){ | ||
process_bbn_tx(txid) | ||
} | ||
|
||
fun process_bbn_tx(txid: address) { | ||
let block_height_opt = bitcoin::get_tx_height(txid); | ||
assert!(is_some(&block_height_opt), ErrorTransactionNotFound); | ||
let block_height = option::destroy_some(block_height_opt); | ||
|
||
let tx_opt = bitcoin::get_tx(txid); | ||
assert!(is_some(&tx_opt), ErrorTransactionNotFound); | ||
|
||
let tx = option::destroy_some(tx_opt); | ||
bbn::process_bbn_transaction(block_height, &tx) | ||
} | ||
|
||
public fun is_expired(stake: &BBNStakeSeal): bool { | ||
let latest_block_opt = bitcoin::get_latest_block(); | ||
if (is_none(&latest_block_opt)) { | ||
return false | ||
}; | ||
let latest_block = option::destroy_some(latest_block_opt); | ||
let (current_block_height, _hash) = types::unpack_block_height_hash(latest_block); | ||
bbn::is_expired_at(stake, current_block_height) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters