Skip to content

Commit

Permalink
fix: reuse common function
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Jan 22, 2025
1 parent a379fdc commit e9eb633
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 12 additions & 4 deletions crates/chain-config/src/config/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ impl GenesisCommitment for Coin {
pub mod coin_config_helpers {
use crate::CoinConfig;
use fuel_core_types::{
fuel_types::Address,
fuel_types::{
Address,
Bytes32,
},
fuel_vm::SecretKey,
};

Expand All @@ -137,17 +140,22 @@ pub mod coin_config_helpers {
count: CoinCount,
}

pub fn tx_id(count: CoinCount) -> Bytes32 {
let mut bytes = [0u8; 32];
bytes[..size_of::<CoinCount>()].copy_from_slice(&count.to_be_bytes());
bytes.into()
}

impl CoinConfigGenerator {
pub fn new() -> Self {
Self { count: 0 }
}

pub fn generate(&mut self) -> CoinConfig {
let mut bytes = [0u8; 32];
bytes[..size_of::<CoinCount>()].copy_from_slice(&self.count.to_be_bytes());
let tx_id = tx_id(self.count);

let config = CoinConfig {
tx_id: bytes.into(),
tx_id,
output_index: self.count,
..Default::default()
};
Expand Down
10 changes: 4 additions & 6 deletions crates/fuel-core/src/graphql_api/da_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,14 @@ where
&self,
c: fuel_core_types::fuel_tx::CompressedUtxoId,
) -> anyhow::Result<fuel_core_types::fuel_tx::UtxoId> {
#[cfg(feature = "test-helpers")]
if c.tx_pointer.block_height() == 0u32.into() {
// This is a genesis coin, which is handled differently.
// See CoinConfigGenerator::generate which generates the genesis coins.
let mut bytes = [0u8; 32];
bytes[..size_of::<u16>()].copy_from_slice(&c.output_index.to_be_bytes());
let tx_id =
fuel_core_chain_config::coin_config_helpers::tx_id(c.output_index);

let utxo_id = fuel_core_types::fuel_tx::UtxoId::new(
fuel_core_types::fuel_tx::TxId::from(bytes),
c.output_index,
);
let utxo_id = fuel_core_types::fuel_tx::UtxoId::new(tx_id, c.output_index);

return Ok(utxo_id);
}
Expand Down

0 comments on commit e9eb633

Please sign in to comment.