-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move helper traits to new pkg plasm-support (#268)
* initial * downgrade log package * fix formatter * plasm version updates to 1.7.0
- Loading branch information
Showing
11 changed files
with
912 additions
and
835 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "pallet-plasm-support" | ||
version = "1.7.0" | ||
authors = ["Stake Technologies <devops@stake.co.jp>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
homepage = "https://docs.plasmnet.io/" | ||
repository = "https://github.com/staketechnologies/Plasm/" | ||
description = "FRAME support pallet for Plasm traits" | ||
|
||
[dependencies] | ||
sp-runtime = { version = "2.0.0", default_features = false } | ||
frame-support = { version = "2.0.0", default_features = false } | ||
sp-std = { version = "2.0.0", default_features = false } | ||
|
||
|
||
[dev-dependencies] | ||
|
||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"sp-runtime/std", | ||
"frame-support/std", | ||
"sp-std/std", | ||
] |
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,50 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use frame_support::Parameter; | ||
use sp_runtime::DispatchError; | ||
use sp_std::prelude::*; | ||
|
||
pub trait ContractFinder<AccountId, Parameter> { | ||
fn is_exists_contract(contract_id: &AccountId) -> bool; | ||
fn operator(contract_id: &AccountId) -> Option<AccountId>; | ||
fn parameters(contract_id: &AccountId) -> Option<Parameter>; | ||
} | ||
|
||
pub trait OperatorFinder<AccountId: Parameter> { | ||
fn contracts(operator_id: &AccountId) -> Vec<AccountId>; | ||
} | ||
|
||
pub trait TransferOperator<AccountId: Parameter>: OperatorFinder<AccountId> { | ||
/// Changes an operator for identified contracts with verify. | ||
fn transfer_operator( | ||
current_operator: AccountId, | ||
contracts: Vec<AccountId>, | ||
new_operator: AccountId, | ||
) -> Result<(), DispatchError> { | ||
Self::verify_transfer_operator(¤t_operator, &contracts)?; | ||
Self::force_transfer_operator(current_operator, contracts, new_operator); | ||
Ok(()) | ||
} | ||
|
||
fn verify_transfer_operator( | ||
current_operator: &AccountId, | ||
contracts: &Vec<AccountId>, | ||
) -> Result<(), DispatchError> { | ||
let operate_contracts = Self::contracts(current_operator); | ||
|
||
// check the actually operate the contract. | ||
if !contracts.iter().all(|c| operate_contracts.contains(c)) { | ||
Err(DispatchError::Other( | ||
"The sender don't operate the contracts address.", | ||
))? | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Force Changes an operator for identified contracts without verify. | ||
fn force_transfer_operator( | ||
current_operator: AccountId, | ||
contracts: Vec<AccountId>, | ||
new_operator: AccountId, | ||
); | ||
} |
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