-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement rust logics for permissioned signer
- Loading branch information
1 parent
6ddb481
commit 906c7c7
Showing
3 changed files
with
143 additions
and
0 deletions.
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
106 changes: 106 additions & 0 deletions
106
aptos-move/framework/src/natives/permissioned_signer.rs
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,106 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use aptos_native_interface::{ | ||
safely_pop_arg, RawSafeNative, SafeNativeBuilder, SafeNativeContext, SafeNativeError, | ||
SafeNativeResult, | ||
}; | ||
use move_vm_runtime::native_functions::NativeFunction; | ||
use move_vm_types::{ | ||
loaded_data::runtime_types::Type, | ||
values::{StructRef, Value, SignerRef}, | ||
}; | ||
use smallvec::{smallvec, SmallVec}; | ||
use std::collections::VecDeque; | ||
|
||
/*************************************************************************************************** | ||
* native fun is_permissioned_signer | ||
* | ||
* Returns true if the signer passed in is a permissioned signer | ||
* gas cost: base_cost | ||
* | ||
**************************************************************************************************/ | ||
fn native_is_permissioned_signer( | ||
_context: &mut SafeNativeContext, | ||
_ty_args: Vec<Type>, | ||
mut arguments: VecDeque<Value>, | ||
) -> SafeNativeResult<SmallVec<[Value; 1]>> { | ||
debug_assert!(arguments.len() == 1); | ||
|
||
let s_arg = safely_pop_arg!(arguments, SignerRef); | ||
|
||
// context.charge()?; | ||
let result = s_arg.is_permissioned()?; | ||
|
||
|
||
Ok(smallvec![Value::bool(result)]) | ||
} | ||
|
||
/*************************************************************************************************** | ||
* native fun permission_signer | ||
* | ||
* Returns the permission signer if the signer passed in is a permissioned signer | ||
* gas cost: base_cost | ||
* | ||
**************************************************************************************************/ | ||
fn native_permission_signer( | ||
_context: &mut SafeNativeContext, | ||
_ty_args: Vec<Type>, | ||
mut arguments: VecDeque<Value>, | ||
) -> SafeNativeResult<SmallVec<[Value; 1]>> { | ||
debug_assert!(arguments.len() == 1); | ||
|
||
let s_arg = safely_pop_arg!(arguments, SignerRef); | ||
|
||
// context.charge()?; | ||
if !s_arg.is_permissioned()? { | ||
return Err(SafeNativeError::Abort { abort_code: 3 }); | ||
} | ||
|
||
Ok(smallvec![s_arg.permissioned_signer()?]) | ||
} | ||
|
||
/*************************************************************************************************** | ||
* native fun signer_from_permissioned | ||
* | ||
* Returns the permission signer from a master signer. | ||
* gas cost: base_cost | ||
* | ||
**************************************************************************************************/ | ||
fn native_signer_from_permissioned( | ||
_context: &mut SafeNativeContext, | ||
_ty_args: Vec<Type>, | ||
mut arguments: VecDeque<Value>, | ||
) -> SafeNativeResult<SmallVec<[Value; 1]>> { | ||
debug_assert!(arguments.len() == 1); | ||
|
||
let s_arg = safely_pop_arg!(arguments, StructRef); | ||
|
||
// context.charge()?; | ||
|
||
Ok(smallvec![s_arg.read_ref()?]) | ||
} | ||
|
||
/*************************************************************************************************** | ||
* module | ||
* | ||
**************************************************************************************************/ | ||
pub fn make_all( | ||
builder: &SafeNativeBuilder, | ||
) -> impl Iterator<Item = (String, NativeFunction)> + '_ { | ||
let natives = [ | ||
( | ||
"is_permissioned_signer", | ||
native_is_permissioned_signer as RawSafeNative, | ||
), | ||
( | ||
"permission_signer", | ||
native_permission_signer | ||
), | ||
( | ||
"signer_from_permissioned_impl", | ||
native_signer_from_permissioned | ||
), | ||
]; | ||
|
||
builder.make_named_natives(natives) | ||
} |
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