Skip to content

Commit

Permalink
First draft
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 8, 2023
1 parent 0b7f6ae commit 78bdad3
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
@@ -15,13 +15,17 @@ use crate::types::{
block::{
address::{AccountAddress, Address},
output::{
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
feature::{
verify_allowed_features, BlockIssuerFeature, BlockIssuerKey, BlockIssuerKeys, Ed25519BlockIssuerKey,
Feature, FeatureFlags, Features,
},
unlock_condition::{
verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions,
verify_allowed_unlock_conditions, AddressUnlockCondition, UnlockCondition, UnlockConditionFlags,
UnlockConditions,
},
verify_output_amount_min, verify_output_amount_packable, verify_output_amount_supply, ChainId, NativeToken,
NativeTokens, Output, OutputBuilderAmount, OutputId, Rent, RentStructure, StateTransitionError,
StateTransitionVerifier,
verify_output_amount_min, verify_output_amount_packable, verify_output_amount_supply, BasicOutput, ChainId,
NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId, Rent, RentStructure,
StateTransitionError, StateTransitionVerifier,
},
payload::signed_transaction::TransactionCapabilityFlag,
protocol::ProtocolParameters,
@@ -48,7 +52,11 @@ impl From<&OutputId> for AccountId {
impl AccountId {
///
pub fn or_from_output_id(self, output_id: &OutputId) -> Self {
if self.is_null() { Self::from(output_id) } else { self }
if self.is_null() {
Self::from(output_id)
} else {
self
}
}
}

@@ -97,6 +105,22 @@ impl AccountOutputBuilder {
}
}

pub fn from_implicit_account(output: &BasicOutput, output_id: &OutputId) -> Result<Self, Error> {
if !output.is_implicit_account() {
panic!()
}

Ok(Self::new_with_amount(output.amount(), AccountId::from(output_id))
.with_mana(output.mana())
.with_unlock_conditions([AddressUnlockCondition::from(output.address().clone())])
.with_features([BlockIssuerFeature::new(
0,
BlockIssuerKeys::from_vec([BlockIssuerKey::from(Ed25519BlockIssuerKey::from(
output.address().as_implicit_account_creation(),
))])?,
)]))
}

/// Sets the amount to the provided value.
#[inline(always)]
pub fn with_amount(mut self, amount: u64) -> Self {
@@ -331,7 +355,10 @@ impl AccountOutput {
/// The set of allowed [`UnlockCondition`]s for an [`AccountOutput`].
pub const ALLOWED_UNLOCK_CONDITIONS: UnlockConditionFlags = UnlockConditionFlags::ADDRESS;
/// The set of allowed [`Feature`]s for an [`AccountOutput`].
pub const ALLOWED_FEATURES: FeatureFlags = FeatureFlags::SENDER.union(FeatureFlags::METADATA);
pub const ALLOWED_FEATURES: FeatureFlags = FeatureFlags::SENDER
.union(FeatureFlags::METADATA)
.union(FeatureFlags::BLOCK_ISSUER)
.union(FeatureFlags::STAKING);
/// The set of allowed immutable [`Feature`]s for an [`AccountOutput`].
pub const ALLOWED_IMMUTABLE_FEATURES: FeatureFlags = FeatureFlags::ISSUER.union(FeatureFlags::METADATA);

0 comments on commit 78bdad3

Please sign in to comment.