Skip to content

Commit

Permalink
fix(db)!: store Address instead of AliasAddress in Unlock (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
grtlr authored May 24, 2022
1 parent 7f21210 commit f3c52a6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 44 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/db/model/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ mod conflict_reason;
mod inclusion_state;
mod metadata;

pub use self::{
conflict_reason::ConflictReason,
inclusion_state::{LedgerInclusionState, UnexpectedLedgerInclusionState},
metadata::Metadata,
};
pub use self::{conflict_reason::*, inclusion_state::*, metadata::*};
7 changes: 4 additions & 3 deletions src/db/model/stardust/block/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ pub(crate) mod test {

use super::*;
use crate::db::model::stardust::block::output::{
feature::test::get_test_metadata_block, native_token::test::get_test_native_token,
unlock_condition::test::get_test_immut_alias_address_condition,
feature::test::get_test_metadata_block,
native_token::test::get_test_native_token,
unlock_condition::test::{get_test_alias_address_as_address, get_test_immut_alias_address_condition},
};

#[test]
Expand All @@ -95,7 +96,7 @@ pub(crate) mod test {
.unwrap()
.with_native_tokens(vec![get_test_native_token().try_into().unwrap()])
.with_unlock_conditions(vec![
get_test_immut_alias_address_condition(bee_test::rand::output::rand_alias_id().into())
get_test_immut_alias_address_condition(get_test_alias_address_as_address())
.try_into()
.unwrap(),
])
Expand Down
28 changes: 18 additions & 10 deletions src/db/model/stardust/block/output/unlock_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use bee_block_stardust::output::unlock_condition as bee;
use serde::{Deserialize, Serialize};

use super::AliasId;
use crate::db::model::stardust::block::Address;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -31,7 +30,7 @@ pub enum UnlockCondition {
#[serde(rename = "governor_address")]
GovernorAddress { address: Address },
#[serde(rename = "immutable_alias_address")]
ImmutableAliasAddress { alias_id: AliasId },
ImmutableAliasAddress { address: Address },
}

impl From<&bee::UnlockCondition> for UnlockCondition {
Expand Down Expand Up @@ -60,7 +59,7 @@ impl From<&bee::UnlockCondition> for UnlockCondition {
address: (*a.address()).into(),
},
bee::UnlockCondition::ImmutableAliasAddress(a) => Self::ImmutableAliasAddress {
alias_id: (*a.address().alias_id()).into(),
address: (*a.address()).into(),
},
}
}
Expand Down Expand Up @@ -96,10 +95,14 @@ impl TryFrom<UnlockCondition> for bee::UnlockCondition {
UnlockCondition::GovernorAddress { address } => {
Self::GovernorAddress(bee::GovernorAddressUnlockCondition::new(address.try_into()?))
}
UnlockCondition::ImmutableAliasAddress { alias_id } => {
Self::ImmutableAliasAddress(bee::ImmutableAliasAddressUnlockCondition::new(
bee_block_stardust::address::AliasAddress::new(alias_id.try_into()?),
))
UnlockCondition::ImmutableAliasAddress { address } => {
let bee_address = bee_block_stardust::address::Address::try_from(address)?;

if let bee_block_stardust::address::Address::Alias(alias_address) = bee_address {
Self::ImmutableAliasAddress(bee::ImmutableAliasAddressUnlockCondition::new(alias_address))
} else {
Err(bee_block_stardust::Error::InvalidAddressKind(bee_address.kind()))?
}
}
})
}
Expand Down Expand Up @@ -137,11 +140,16 @@ pub(crate) mod test {
let bson = to_bson(&block).unwrap();
assert_eq!(block, from_bson::<UnlockCondition>(bson).unwrap());

let block = get_test_immut_alias_address_condition(bee_test::rand::output::rand_alias_id().into());
let block = get_test_immut_alias_address_condition(get_test_alias_address_as_address());
let bson = to_bson(&block).unwrap();
assert_eq!(block, from_bson::<UnlockCondition>(bson).unwrap());
}

pub(crate) fn get_test_alias_address_as_address() -> Address {
use bee_block_stardust::address::{Address as BeeAddress, AliasAddress as BeeAliasAddress};
BeeAddress::from(BeeAliasAddress::new(bee_test::rand::output::rand_alias_id())).into()
}

pub(crate) fn get_test_address_condition(address: Address) -> UnlockCondition {
UnlockCondition::Address { address }
}
Expand Down Expand Up @@ -177,7 +185,7 @@ pub(crate) mod test {
UnlockCondition::GovernorAddress { address }
}

pub(crate) fn get_test_immut_alias_address_condition(alias_id: AliasId) -> UnlockCondition {
UnlockCondition::ImmutableAliasAddress { alias_id }
pub(crate) fn get_test_immut_alias_address_condition(address: Address) -> UnlockCondition {
UnlockCondition::ImmutableAliasAddress { address }
}
}

0 comments on commit f3c52a6

Please sign in to comment.