Skip to content

Commit

Permalink
Check if a transaction has a standard auth field which enable token-t…
Browse files Browse the repository at this point in the history
…ransfer payloads
  • Loading branch information
neithanmo committed Jun 18, 2020
1 parent c2160be commit ee7e1fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/rust/src/parser/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ impl<'a> Transaction<'a> {
TransactionPayload::from_bytes,
))(bytes)
{
Ok(tx) => Ok(Self::from(tx.1)),
Ok(tx) => {
// Note that if a transaction contains a token-transfer payload,
// it MUST have only a standard authorization field. It cannot be sponsored.
if (tx.1).6.is_token_transfer_payload() && !(tx.1).2.is_standard_auth() {
return Err(ParserError::parser_invalid_transaction_payload);
}
Ok(Self::from(tx.1))
}
Err(_e) => Err(ParserError::parser_unexpected_error),
}
}
Expand Down
7 changes: 7 additions & 0 deletions app/rust/src/parser/transaction_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ impl<'a> TransactionAuth<'a> {
let sponsored = TransactionSpendingCondition::from_bytes(standard.0)?;
Ok((sponsored.0, Self::Sponsored(standard.1, sponsored.1)))
}

pub fn is_standard_auth(&self) -> bool {
match *self {
Self::Standard(_) => true,
_ => false,
}
}
}

#[cfg(test)]
Expand Down
7 changes: 7 additions & 0 deletions app/rust/src/parser/transaction_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ impl<'a> TransactionPayload<'a> {
};
Ok(res)
}

pub fn is_token_transfer_payload(&self) -> bool {
match *self {
Self::TokenTransfer(_) => true,
_ => false,
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit ee7e1fa

Please sign in to comment.