Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
50562c0
stash precompile changes in other branch and push pallet changes leak…
amarsinghcodes Oct 20, 2022
9395e66
still leaking std
amarsinghcodes Oct 20, 2022
8ed14e7
using sp std phantomdata did not fix
amarsinghcodes Oct 21, 2022
315116a
ty @nanocryk for std leak fix
amarsinghcodes Oct 21, 2022
8f24362
init referenda precompile needs tryfrom u8 for origins
amarsinghcodes Oct 23, 2022
d83be8e
referenda submit precompile fn
amarsinghcodes Oct 23, 2022
21ffc60
signed extrinsics for referenda precompile
amarsinghcodes Oct 23, 2022
0eb6dc3
preimage precompile
amarsinghcodes Oct 24, 2022
09e90db
init conviction voting precompile
amarsinghcodes Oct 24, 2022
138a848
referenda delegate undelegate unlock
amarsinghcodes Oct 25, 2022
8e1a709
fixes
amarsinghcodes Oct 26, 2022
276d8a4
fix
amarsinghcodes Oct 26, 2022
a940199
clean
amarsinghcodes Oct 26, 2022
a9ab0e3
improve revert reasons for class and index inputs
amarsinghcodes Oct 26, 2022
9067ba0
clean
amarsinghcodes Oct 26, 2022
467e845
init accessors and clean
amarsinghcodes Nov 3, 2022
c6c8d1b
Merge branch 'master' into amar-gov2-precompiles
amarsinghcodes Nov 7, 2022
4d8f70a
referenda precompile
amarsinghcodes Nov 16, 2022
a234655
clean
amarsinghcodes Nov 16, 2022
def4e70
Merge branch 'master' into amar-gov2-precompiles
amarsinghcodes Nov 21, 2022
e86512c
clean and init referenda precompile interface
amarsinghcodes Nov 21, 2022
66e5164
into master
amarsinghcodes Jan 2, 2023
c389722
fix merge
amarsinghcodes Jan 4, 2023
5bb1673
try mock referenda precompile but did not succeed
amarsinghcodes Jan 4, 2023
e7c765b
save
amarsinghcodes Jan 6, 2023
c5e2220
fix referenda mock
nanocryk Jan 9, 2023
d05803f
add dot sol files for preimage and voting
amarsinghcodes Jan 9, 2023
b784aca
add to moonbase precompiles
amarsinghcodes Jan 9, 2023
f1c55b5
fix
amarsinghcodes Jan 10, 2023
58620ed
precompile existence test fix
amarsinghcodes Jan 10, 2023
6ed417f
update solidity addresses as per moonbase config
amarsinghcodes Jan 10, 2023
2fcef74
rename standard vote to vote in conviction voting pallet
amarsinghcodes Jan 11, 2023
8723589
start moving origins out of pallet and using additional generic instead
amarsinghcodes Jan 11, 2023
a1f469e
fix finish moving pallet custom origins back into runtime
amarsinghcodes Jan 11, 2023
3e4e868
into master
amarsinghcodes Jan 11, 2023
72f78a1
Merge branch 'master' into amar-gov2-precompiles
librelois Jan 12, 2023
e1f84ca
add opengov precompiles in proxy evm filter
librelois Jan 12, 2023
6064e97
SolidityConvert no longer necessary
amarsinghcodes Jan 12, 2023
19c2914
rm SolidityConvert and add Conviction enum
amarsinghcodes Jan 12, 2023
046a7ac
use trackId as input for submit instead of origin and convert from tr…
amarsinghcodes Jan 12, 2023
7839709
camelCase error msgs
amarsinghcodes Jan 12, 2023
3357394
Update precompiles/referenda/src/lib.rs
amarsinghcodes Jan 12, 2023
5efa9d5
fix conviction precompile interface
amarsinghcodes Jan 12, 2023
145f6f9
fix referenda precompile interface
amarsinghcodes Jan 12, 2023
694378d
test to ensure all tracks have min enactment period less than vote lo…
amarsinghcodes Jan 12, 2023
9bfd9ff
update tracks based on wiki
amarsinghcodes Jan 12, 2023
a11ee95
revert accidental commit
amarsinghcodes Jan 12, 2023
a1941ec
fix referenda precompile unit tests
amarsinghcodes Jan 12, 2023
6e99180
update config based on polkadot 6372 gov2 config tweaks
amarsinghcodes Jan 12, 2023
83e5a1c
fix
amarsinghcodes Jan 12, 2023
362fef7
Configure moonriver OpenGov (#2038)
amarsinghcodes Jan 17, 2023
af079a9
into master
amarsinghcodes Jan 17, 2023
db81510
remove TryFrom u8 impl for Origin unused
amarsinghcodes Jan 17, 2023
d3a8bda
split convictionVoting vote into voteYes and voteNo so can add voteAb…
amarsinghcodes Jan 17, 2023
4c3e81b
fix consistent conversion test
amarsinghcodes Jan 17, 2023
fd381a7
Merge branch 'master' into amar-gov2-precompiles
amarsinghcodes Jan 17, 2023
be79f7c
follow suggestions
amarsinghcodes Jan 17, 2023
dea9998
add doc note to removeOtherVote
amarsinghcodes Jan 17, 2023
052a56e
into master
amarsinghcodes Jan 17, 2023
d4782eb
fix
amarsinghcodes Jan 17, 2023
3cccdb4
Merge branch 'master' into amar-gov2-precompiles
crystalin Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean
  • Loading branch information
amarsinghcodes committed Oct 26, 2022
commit a940199cd35391c8c70badf6f477ca6cdfa888ff
104 changes: 49 additions & 55 deletions precompiles/conviction-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ where
vote_amount: U256,
conviction: SolidityConvert<U256, u8>,
) -> EvmResult {
let poll_index = poll_index.converted();
let poll_index: IndexOf<Runtime> = poll_index
.converted()
.try_into()
.map_err(|_| revert("Poll index does not match type"))?;
let vote_amount = Self::u256_to_amount(vote_amount).in_field("voteAmount")?;

let conviction: Conviction = conviction.converted().try_into().map_err(|_| {
Expand All @@ -104,13 +107,7 @@ where
);

let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = ConvictionVotingCall::<Runtime>::vote {
poll_index: poll_index
.try_into()
.map_err(|_| revert("Poll index does not match type"))?,
vote,
}
.into();
let call = ConvictionVotingCall::<Runtime>::vote { poll_index, vote }.into();

<RuntimeHelper<Runtime>>::try_dispatch(handle, Some(origin).into(), call)?;

Expand All @@ -122,21 +119,19 @@ where
handle: &mut impl PrecompileHandle,
poll_index: SolidityConvert<U256, u32>,
) -> EvmResult {
let poll_index: u32 = poll_index.converted();
let index: IndexOf<Runtime> = poll_index
.converted()
.try_into()
.map_err(|_| revert("Poll index does not match type"))?;

log::trace!(
target: "conviction-voting-precompile",
"Removing vote from poll {:?}",
poll_index
index
);

let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = ConvictionVotingCall::<Runtime>::remove_vote {
class: None,
index: poll_index
.try_into()
.map_err(|_| revert("Poll index does not match type"))?,
};
let call = ConvictionVotingCall::<Runtime>::remove_vote { class: None, index };

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;

Expand All @@ -149,26 +144,25 @@ where
class: SolidityConvert<U256, u16>,
poll_index: SolidityConvert<U256, u32>,
) -> EvmResult {
let class: u16 = class.converted();
let poll_index: u32 = poll_index.converted();
let class: Option<ClassOf<Runtime>> = Some(
class
.converted()
.try_into()
.map_err(|_| revert("Class does not match type"))?,
);
let index: IndexOf<Runtime> = poll_index
.converted()
.try_into()
.map_err(|_| revert("Poll index does not match type"))?;

log::trace!(
target: "conviction-voting-precompile",
"Removing vote from poll {:?}",
poll_index
index
);

let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = ConvictionVotingCall::<Runtime>::remove_vote {
class: Some(
class
.try_into()
.map_err(|_| revert("Class does not match type"))?,
),
index: poll_index
.try_into()
.map_err(|_| revert("Poll index does not match type"))?,
};
let call = ConvictionVotingCall::<Runtime>::remove_vote { class, index };

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;

Expand All @@ -181,8 +175,14 @@ where
class: SolidityConvert<U256, u16>,
poll_index: SolidityConvert<U256, u32>,
) -> EvmResult {
let class: u16 = class.converted();
let poll_index: u32 = poll_index.converted();
let class: ClassOf<Runtime> = class
.converted()
.try_into()
.map_err(|_| revert("Class does not match type"))?;
let index: IndexOf<Runtime> = poll_index
.converted()
.try_into()
.map_err(|_| revert("Poll index does not match type"))?;

let target = Runtime::AddressMapping::into_account_id(target.into());
let target: <Runtime::Lookup as StaticLookup>::Source =
Expand All @@ -191,18 +191,14 @@ where
log::trace!(
target: "conviction-voting-precompile",
"Removing other vote from poll {:?}",
poll_index
index
);

let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = ConvictionVotingCall::<Runtime>::remove_other_vote {
target,
class: class
.try_into()
.map_err(|_| revert("Class does not match type"))?,
index: poll_index
.try_into()
.map_err(|_| revert("Poll index does not match type"))?,
class,
index,
};

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;
Expand All @@ -217,7 +213,10 @@ where
conviction: SolidityConvert<U256, u8>,
amount: U256,
) -> EvmResult {
let class = class.converted();
let class: ClassOf<Runtime> = class
.converted()
.try_into()
.map_err(|_| revert("Class does not match type"))?;
let amount = Self::u256_to_amount(amount).in_field("amount")?;

let conviction: Conviction = conviction.converted().try_into().map_err(|_| {
Expand All @@ -235,9 +234,7 @@ where
Runtime::Lookup::unlookup(representative.clone());
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = ConvictionVotingCall::<Runtime>::delegate {
class: class
.try_into()
.map_err(|_| revert("Class does not match type"))?,
class,
to,
conviction,
balance: amount,
Expand All @@ -252,13 +249,12 @@ where
handle: &mut impl PrecompileHandle,
class: SolidityConvert<U256, u16>,
) -> EvmResult {
let class = class.converted();
let class: ClassOf<Runtime> = class
.converted()
.try_into()
.map_err(|_| revert("Class does not match type"))?;
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = ConvictionVotingCall::<Runtime>::undelegate {
class: class
.try_into()
.map_err(|_| revert("Class does not match type"))?,
};
let call = ConvictionVotingCall::<Runtime>::undelegate { class };

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;

Expand All @@ -270,7 +266,10 @@ where
class: SolidityConvert<U256, u16>,
target: Address,
) -> EvmResult {
let class = class.converted();
let class: ClassOf<Runtime> = class
.converted()
.try_into()
.map_err(|_| revert("Class does not match type"))?;
let target: H160 = target.into();
let target = Runtime::AddressMapping::into_account_id(target);
let target: <Runtime::Lookup as StaticLookup>::Source =
Expand All @@ -282,12 +281,7 @@ where
);

let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);
let call = ConvictionVotingCall::<Runtime>::unlock {
class: class
.try_into()
.map_err(|_| revert("Class does not match type"))?,
target,
};
let call = ConvictionVotingCall::<Runtime>::unlock { class, target };

RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?;

Expand Down
10 changes: 4 additions & 6 deletions precompiles/preimage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ where
/// * hash: The preimage cleared from the runtime storage
#[precompile::public("unnotePreimage(bytes32)")]
fn unnote_preimage(handle: &mut impl PrecompileHandle, hash: H256) -> EvmResult {
let hash: Runtime::Hash = hash
.try_into()
.map_err(|_| revert("H256 is Runtime::Hash"))?;
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);

let call = PreimageCall::<Runtime>::unnote_preimage {
hash: hash
.try_into()
.map_err(|_| revert("H256 is Runtime::Hash"))?,
}
.into();
let call = PreimageCall::<Runtime>::unnote_preimage { hash }.into();

<RuntimeHelper<Runtime>>::try_dispatch(handle, Some(origin).into(), call)?;

Expand Down
10 changes: 6 additions & 4 deletions precompiles/referenda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use sp_std::marker::PhantomData;
// #[cfg(test)]
// mod tests;

type OriginOf<Runtime> = <<Runtime as frame_system::Config>::Origin as OriginTrait>::PalletsOrigin;

/// A precompile to wrap the functionality from pallet-referenda.
pub struct ReferendaPrecompile<Runtime>(PhantomData<Runtime>);

Expand All @@ -40,8 +42,7 @@ where
Runtime: pallet_referenda::Config + pallet_evm::Config + frame_system::Config,
<<Runtime as pallet_referenda::Config>::Call as Dispatchable>::Origin:
From<Option<Runtime::AccountId>>,
<<Runtime as frame_system::Config>::Origin as OriginTrait>::PalletsOrigin:
From<pallet_governance_origins::Origin>,
OriginOf<Runtime>: From<pallet_governance_origins::Origin>,
<Runtime as frame_system::Config>::Hash: TryFrom<H256>,
<Runtime as frame_system::Config>::Call:
Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
Expand All @@ -64,9 +65,10 @@ where
at: bool,
block_number: u32,
) -> EvmResult {
let proposal_origin: pallet_governance_origins::Origin = proposal_origin
let gov_origin: pallet_governance_origins::Origin = proposal_origin
.try_into()
.map_err(|_| revert("Origin does not exist for u8"))?;
let proposal_origin: Box<OriginOf<Runtime>> = Box::new(gov_origin.into());
let proposal_hash: Runtime::Hash = proposal_hash
.try_into()
.map_err(|_| revert("Proposal hash input is not H256"))?;
Expand All @@ -79,7 +81,7 @@ where
let origin = Runtime::AddressMapping::into_account_id(handle.context().caller);

let call = ReferendaCall::<Runtime>::submit {
proposal_origin: Box::new(proposal_origin.into()),
proposal_origin,
proposal_hash,
enactment_moment,
}
Expand Down