-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcb6407
commit a2f526f
Showing
16 changed files
with
133 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "original_owner_helper" | ||
version = "0.0.0" | ||
authors = ["MultiversX <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "=0.53.2" | ||
features = ["esdt-token-payment-legacy-decode"] | ||
|
||
[dependencies.common_structs] | ||
path = "../../common_structs" |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#![no_std] | ||
|
||
multiversx_sc::imports!(); | ||
|
||
use common_structs::{FarmToken, PaymentsVec}; | ||
|
||
#[multiversx_sc::module] | ||
pub trait OriginalOwnerHelperModule { | ||
fn check_and_return_original_owner<T: FarmToken<Self::Api> + TopDecode>( | ||
&self, | ||
payments: &PaymentsVec<Self::Api>, | ||
farm_token_mapper: &NonFungibleTokenMapper, | ||
) -> ManagedAddress { | ||
let mut original_owner = ManagedAddress::zero(); | ||
for payment in payments.iter() { | ||
let attributes: T = farm_token_mapper.get_token_attributes(payment.token_nonce); | ||
let payment_original_owner = attributes.get_original_owner(); | ||
|
||
if original_owner.is_zero() { | ||
original_owner = payment_original_owner; | ||
} else { | ||
require!( | ||
original_owner == payment_original_owner, | ||
"All position must have the same original owner" | ||
); | ||
} | ||
} | ||
|
||
require!( | ||
!original_owner.is_zero(), | ||
"Original owner could not be identified" | ||
); | ||
|
||
original_owner | ||
} | ||
|
||
fn check_additional_payments_original_owner<T: FarmToken<Self::Api> + TopDecode>( | ||
&self, | ||
user: &ManagedAddress, | ||
payments: &PaymentsVec<Self::Api>, | ||
farm_token_mapper: &NonFungibleTokenMapper, | ||
) { | ||
if payments.len() == 1 { | ||
return; | ||
} | ||
|
||
let farm_token_id = farm_token_mapper.get_token_id(); | ||
for payment in payments.into_iter() { | ||
if payment.token_identifier != farm_token_id { | ||
continue; | ||
} | ||
|
||
let attributes: T = farm_token_mapper.get_token_attributes(payment.token_nonce); | ||
let payment_original_owner = attributes.get_original_owner(); | ||
|
||
require!( | ||
user == &payment_original_owner, | ||
"Provided address is not the same as the original owner" | ||
); | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.