-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EthTransaction: impl TopDecode/TopEncode #163
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ multiversx_sc::imports!(); | |
multiversx_sc::derive_imports!(); | ||
|
||
use eth_address::EthAddress; | ||
use multiversx_sc::codec::{EncodeErrorHandler, NestedDecodeInput, TopEncodeOutput}; | ||
// use multiversx_sc::codec::{DecodeErrorHandler, EncodeErrorHandler, NestedDecodeInput, TopDecodeInput, TopEncodeOutput}; | ||
|
||
pub mod transaction_status; | ||
|
||
|
@@ -26,7 +28,7 @@ pub type TxAsMultiValue<M> = MultiValue6< | |
pub type PaymentsVec<M> = ManagedVec<M, EsdtTokenPayment<M>>; | ||
pub type TxBatchSplitInFields<M> = MultiValue2<u64, MultiValueEncoded<M, TxAsMultiValue<M>>>; | ||
|
||
#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, Clone, ManagedVecItem)] | ||
#[derive(NestedEncode, NestedDecode, TypeAbi, Clone, ManagedVecItem)] | ||
pub struct EthTransaction<M: ManagedTypeApi> { | ||
pub from: EthAddress<M>, | ||
pub to: ManagedAddress<M>, | ||
|
@@ -38,6 +40,159 @@ pub struct EthTransaction<M: ManagedTypeApi> { | |
pub args: ManagedVec<M, ManagedBuffer<M>>, | ||
} | ||
|
||
impl<M: ManagedTypeApi> TopEncode for EthTransaction<M> { | ||
fn top_encode_or_handle_err<O, H>(&self, output: O, h: H) -> Result<(), H::HandledErr> | ||
where | ||
O: TopEncodeOutput, | ||
H: EncodeErrorHandler, | ||
{ | ||
let mut nested_buffer = output.start_nested_encode(); | ||
self.from.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
self.to.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
self.token_id | ||
.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
self.amount | ||
.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
self.tx_nonce | ||
.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
self.data.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
self.gas_limit | ||
.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
for arg in &self.args { | ||
arg.dep_encode_or_handle_err(&mut nested_buffer, h)?; | ||
} | ||
output.finalize_nested_encode(nested_buffer); | ||
Result::Ok(()) | ||
} | ||
} | ||
|
||
impl<M: ManagedTypeApi> TopDecode for EthTransaction<M> { | ||
fn top_decode_or_handle_err<I, H>(input: I, h: H) -> Result<Self, H::HandledErr> | ||
where | ||
I: codec::TopDecodeInput, | ||
H: codec::DecodeErrorHandler, | ||
{ | ||
let mut nested_buffer = input.into_nested_buffer(); | ||
let from = EthAddress::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
let to = ManagedAddress::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
let token_id = TokenIdentifier::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
let amount = BigUint::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
let tx_nonce = TxNonce::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
let data = ManagedBuffer::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
let gas_limit = u64::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
let mut args = ManagedVec::new(); | ||
|
||
while !nested_buffer.is_depleted() { | ||
args.push(ManagedBuffer::dep_decode_or_handle_err( | ||
&mut nested_buffer, | ||
h, | ||
)?); | ||
} | ||
|
||
Result::Ok(EthTransaction { | ||
from, | ||
to, | ||
token_id, | ||
amount, | ||
tx_nonce, | ||
data, | ||
gas_limit, | ||
args, | ||
}) | ||
} | ||
} | ||
|
||
// impl<M: ManagedTypeApi> codec::TopEncode for EthTransaction<M> { | ||
// fn top_encode_or_handle_err<O, H>( | ||
// &self, | ||
// output: O, | ||
// h: H, | ||
// ) -> core::result::Result<(), H::HandledErr> | ||
// where | ||
// O: codec::TopEncodeOutput, | ||
// H: codec::EncodeErrorHandler, | ||
// { | ||
// self { | ||
|
||
// } | ||
// match self.args. { | ||
// TokenMapperState::NotSet => codec::TopEncode::top_encode_or_handle_err(&"", output, h), | ||
// TokenMapperState::Pending => { | ||
// codec::TopEncode::top_encode_or_handle_err(&"pending", output, h) | ||
// }, | ||
// TokenMapperState::Token(token) => { | ||
// codec::TopEncode::top_encode_or_handle_err(&token, output, h) | ||
// }, | ||
// } | ||
// } | ||
// } | ||
|
||
// impl<M: ManagedTypeApi> TopDecode for EthTransaction<M> { | ||
// fn top_decode_or_handle_err<I, H>(top_input: I, h: H) -> Result<Self, H::HandledErr> | ||
// where | ||
// I: codec::TopDecodeInput, | ||
// H: codec::DecodeErrorHandler, | ||
// { | ||
// let mut nested_buffer = top_input.into_nested_buffer(); | ||
// let result = Self::dep_decode_or_handle_err(&mut nested_buffer, h)?; | ||
// if !codec::NestedDecodeInput::is_depleted(&nested_buffer) { | ||
// return Err(h.handle_error(codec::DecodeError::INPUT_TOO_LONG)); | ||
// } | ||
// Ok(result) | ||
// } | ||
// } | ||
|
||
// impl<M: ManagedTypeApi> codec::TopDecode for EthTransaction<M> { | ||
// fn top_decode_or_handle_err<I, H>(input: I, h: H) -> core::result::Result<Self, H::HandledErr> | ||
// where | ||
// I: codec::TopDecodeInput, | ||
// H: codec::DecodeErrorHandler, | ||
// { | ||
// let decoded_input = ManagedBuffer::top_decode_or_handle_err(input, h)?; | ||
// if decoded_input.is_empty() { | ||
// Ok(TokenMapperState::NotSet) | ||
// } else if decoded_input == PENDING_ENCODING { | ||
// Ok(TokenMapperState::Pending) | ||
// } else { | ||
// let token_id = TokenIdentifier::from_esdt_bytes(decoded_input); | ||
// Ok(TokenMapperState::Token(token_id)) | ||
// } | ||
// } | ||
// } | ||
|
||
// impl<T: NestedDecode, M: ManagedTypeApi> TopDecode for EthTransaction<M> { | ||
// fn top_decode_or_handle_err<I, H>(input: I, h: H) -> Result<Self, H::HandledErr> | ||
// where | ||
// I: codec::TopDecodeInput, | ||
// H: codec::DecodeErrorHandler, | ||
// { | ||
// let mut result: EthTransaction<T, M> = EthTransaction::new(); | ||
// let mut nested_arg = input.into_nested_buffer(); | ||
// while !nested_arg.is_depleted() { | ||
// if let Err(capacity_error) = | ||
// result.try_push(T::dep_decode_or_handle_err(&mut nested_arg, h)?) | ||
// { | ||
// return Err(h.handle_error(DecodeError::from(capacity_error))); | ||
// } | ||
// } | ||
// if !nested_arg.is_depleted() { | ||
// if let Err(capacity_error) = | ||
// result.try_push(T::dep_decode_or_handle_err(&mut nested_arg, h)?) | ||
// { | ||
// return Err(h.handle_error(DecodeError::from(capacity_error))); | ||
// } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented code |
||
// } | ||
// Ok(result) | ||
// } | ||
|
||
// fn top_decode<I>(input: I) -> Result<Self, DecodeError> | ||
// where | ||
// I: TopDecodeInput, | ||
// { | ||
// Self::top_decode_or_handle_err(input, codec::DefaultErrorHandler) | ||
// } | ||
// } | ||
|
||
pub type EthTxAsMultiValue<M> = MultiValue8< | ||
EthAddress<M>, | ||
ManagedAddress<M>, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete commented code ?