Skip to content

Commit

Permalink
Add implicit accounts to input chains
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 21, 2023
1 parent ed565bf commit e450a2e
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions sdk/src/types/block/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use primitive_types::U256;
use crate::types::block::{
address::{Address, AddressCapabilityFlag},
output::{
AnchorOutput, ChainId, FoundryId, NativeTokens, Output, OutputId, StateTransitionError, TokenId,
AccountId, AnchorOutput, ChainId, FoundryId, NativeTokens, Output, OutputId, StateTransitionError, TokenId,
UnlockCondition,
},
payload::signed_transaction::{Transaction, TransactionCapabilityFlag, TransactionId, TransactionSigningHash},
Expand Down Expand Up @@ -216,6 +216,32 @@ impl<'a> SemanticValidationContext<'a> {
inputs: &'a [(&'a OutputId, &'a Output)],
unlocks: &'a Unlocks,
) -> Self {
let input_chains = inputs
.iter()
.filter_map(|(output_id, input)| {
if input.is_implicit_account() {
Some((ChainId::from(AccountId::from(*output_id)), *input))
} else {
input
.chain_id()
.map(|chain_id| (chain_id.or_from_output_id(output_id), *input))
}
})
.collect();
let output_chains = transaction
.outputs()
.iter()
.enumerate()
.filter_map(|(index, output)| {
output.chain_id().map(|chain_id| {
(
chain_id.or_from_output_id(&OutputId::new(*transaction_id, index as u16).unwrap()),
output,
)
})
})
.collect();

Self {
transaction,
transaction_signing_hash: transaction.signing_hash(),
Expand All @@ -224,30 +250,11 @@ impl<'a> SemanticValidationContext<'a> {
input_amount: 0,
input_mana: 0,
input_native_tokens: BTreeMap::<TokenId, U256>::new(),
input_chains: inputs
.iter()
.filter_map(|(output_id, input)| {
input
.chain_id()
.map(|chain_id| (chain_id.or_from_output_id(output_id), *input))
})
.collect(),
input_chains,
output_amount: 0,
output_mana: 0,
output_native_tokens: BTreeMap::<TokenId, U256>::new(),
output_chains: transaction
.outputs()
.iter()
.enumerate()
.filter_map(|(index, output)| {
output.chain_id().map(|chain_id| {
(
chain_id.or_from_output_id(&OutputId::new(*transaction_id, index as u16).unwrap()),
output,
)
})
})
.collect(),
output_chains,
unlocked_addresses: HashSet::new(),
storage_deposit_returns: HashMap::new(),
simple_deposits: HashMap::new(),
Expand Down

0 comments on commit e450a2e

Please sign in to comment.