Skip to content

Commit

Permalink
macros: Move them to their own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Jun 11, 2024
1 parent 2f398d6 commit 807a5ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
26 changes: 26 additions & 0 deletions src/ledger/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! # Macros
//!
//! Useful macros for Ledger crate.
/// Adds a new item to a `Vec` member, guarded by a `Cell`.
#[macro_export]
macro_rules! add_item {
($member:expr, $item:expr) => {
// Update item list.
let mut items = $member.take();
items.push($item);

// Commit new change.
$member.set(items);
};
}
/// Returns item `Vec` of a member, guarded by a `Cell`.
#[macro_export]
macro_rules! get_item {
($member:expr) => {
let items = $member.take();
$member.set(items.clone());

return items;
};
}
25 changes: 2 additions & 23 deletions src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! This crate is designed to be used as immutable, because of the `RpcApi`'s
//! immutable nature.
use crate::{add_item, get_item};
use bitcoin::{Address, Transaction, TxOut};
use bitcoin_simulator::database::Database;
use std::{
Expand All @@ -13,31 +14,9 @@ use std::{
};

mod errors;
mod macros;
mod transactions;

/// Adds a new item to a `Vec` member, guarded by a `Cell`.
#[macro_export]
macro_rules! add_item {
($member:expr, $item:expr) => {
// Update item list.
let mut items = $member.take();
items.push($item);

// Commit new change.
$member.set(items);
};
}
/// Returns item `Vec` of a member, guarded by a `Cell`.
#[macro_export]
macro_rules! get_item {
($member:expr) => {
let items = $member.take();
$member.set(items.clone());

return items;
};
}

/// Mock Bitcoin ledger.
pub struct Ledger {
/// Private database interface. Data will be written to this temporary
Expand Down

0 comments on commit 807a5ec

Please sign in to comment.