-
Notifications
You must be signed in to change notification settings - Fork 165
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
get stake interface in solidity #955
Open
open-junius
wants to merge
6
commits into
devnet-ready
Choose a base branch
from
feat/solidity-get-stake
base: devnet-ready
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b6431e
get stake interface in solidity
open-junius 9688e03
parse keys for stake map
open-junius 9f64385
fix clippy
open-junius 56b3365
Merge branch 'devnet-ready' into feat/solidity-get-stake
open-junius 8647528
revert payable attribute
open-junius 51c47b4
Merge branch 'devnet-ready' into feat/solidity-get-stake
open-junius 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,4 +42,16 @@ interface IStaking { | |||||
* - The existing stake amount must be not lower than specified amount | ||||||
*/ | ||||||
function removeStake(bytes32 hotkey, uint256 amount, uint16 netuid) external; | ||||||
|
||||||
/** | ||||||
* @dev Returns the stake amount associated with the specified `hotkey` and `coldkey`. | ||||||
* | ||||||
* This function retrieves the current stake amount linked to a specific hotkey and coldkey pair. | ||||||
* It is a view function, meaning it does not modify the state of the contract and is free to call. | ||||||
* | ||||||
* @param hotkey The hotkey public key (32 bytes). | ||||||
* @param coldkey The coldkey public key (32 bytes). | ||||||
* @return The current stake amount in uint64 format. | ||||||
*/ | ||||||
function getStake(bytes32 hotkey, bytes32 coldkey) external view returns (uint64); | ||||||
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.
Suggested change
|
||||||
} |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -59,6 +59,9 @@ impl StakingPrecompile { | |||||
id if id == get_method_id("removeStake(bytes32,uint256,uint16)") => { | ||||||
Self::remove_stake(handle, &method_input) | ||||||
} | ||||||
id if id == get_method_id("getStake(bytes32,bytes32)") => { | ||||||
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.
Suggested change
|
||||||
Self::get_stake(&method_input) | ||||||
} | ||||||
_ => Err(PrecompileFailure::Error { | ||||||
exit_status: ExitError::InvalidRange, | ||||||
}), | ||||||
|
@@ -101,6 +104,37 @@ impl StakingPrecompile { | |||||
Self::dispatch(handle, call) | ||||||
} | ||||||
|
||||||
fn get_stake(data: &[u8]) -> PrecompileResult { | ||||||
let (hotkey, coldkey) = Self::parse_hotkey_coldkey(data)?; | ||||||
|
||||||
let stake = pallet_subtensor::Pallet::<Runtime>::get_stake_for_coldkey_and_hotkey( | ||||||
&hotkey.into(), | ||||||
&coldkey.into(), | ||||||
); | ||||||
|
||||||
let stake_u256 = U256::from(stake); | ||||||
let mut result = [0_u8; 32]; | ||||||
U256::to_big_endian(&stake_u256, &mut result); | ||||||
|
||||||
Ok(PrecompileOutput { | ||||||
exit_status: ExitSucceed::Returned, | ||||||
output: result.into(), | ||||||
}) | ||||||
} | ||||||
|
||||||
fn parse_hotkey_coldkey(data: &[u8]) -> Result<([u8; 32], [u8; 32]), PrecompileFailure> { | ||||||
if data.len() < 64 { | ||||||
return Err(PrecompileFailure::Error { | ||||||
exit_status: ExitError::InvalidRange, | ||||||
}); | ||||||
} | ||||||
let mut hotkey = [0u8; 32]; | ||||||
hotkey.copy_from_slice(get_slice(data, 0, 32)?); | ||||||
let mut coldkey = [0u8; 32]; | ||||||
coldkey.copy_from_slice(get_slice(data, 32, 64)?); | ||||||
Ok((hotkey, coldkey)) | ||||||
} | ||||||
|
||||||
fn parse_hotkey(data: &[u8]) -> Result<[u8; 32], PrecompileFailure> { | ||||||
if data.len() < 32 { | ||||||
return Err(PrecompileFailure::Error { | ||||||
|
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.