Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
4967: Contract staking  r=darthsiroftardis a=EdHastingsCasperAssociation

This PR introduces support to delegate using a purse instead of a public key. This allows, among other things, a contract with an associated purse to delegate.


Co-authored-by: Ed Hastings <[email protected]>
Co-authored-by: Karan Dhareshwar <[email protected]>
  • Loading branch information
3 people authored Nov 23, 2024
2 parents 843b19e + 1adb141 commit 26943ed
Show file tree
Hide file tree
Showing 62 changed files with 4,258 additions and 1,564 deletions.
11 changes: 7 additions & 4 deletions binary_port/src/information_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use casper_types::{
account::AccountHash,
bytesrepr::{self, FromBytes, ToBytes, U8_SERIALIZED_LENGTH},
contracts::{ContractHash, ContractPackageHash},
system::auction::DelegatorKind,
BlockIdentifier, EntityAddr, GlobalStateIdentifier, PackageAddr, PublicKey, TransactionHash,
};

Expand Down Expand Up @@ -60,9 +61,9 @@ pub enum InformationRequest {
era_identifier: Option<EraIdentifier>,
/// Public key of the validator to get the reward for.
validator: Box<PublicKey>,
/// Public key of the delegator to get the reward for.
/// Identity of the delegator to get the reward for.
/// If `None`, the reward for the validator is returned.
delegator: Option<Box<PublicKey>>,
delegator: Option<Box<DelegatorKind>>,
},
/// Returns the current Casper protocol version.
ProtocolVersion,
Expand Down Expand Up @@ -152,7 +153,9 @@ impl InformationRequest {
InformationRequestTag::Reward => InformationRequest::Reward {
era_identifier: rng.gen::<bool>().then(|| EraIdentifier::random(rng)),
validator: PublicKey::random(rng).into(),
delegator: rng.gen::<bool>().then(|| PublicKey::random(rng).into()),
delegator: rng
.gen::<bool>()
.then(|| Box::new(DelegatorKind::PublicKey(PublicKey::random(rng)))),
},
InformationRequestTag::ProtocolVersion => InformationRequest::ProtocolVersion,
InformationRequestTag::Package => InformationRequest::Package {
Expand Down Expand Up @@ -341,7 +344,7 @@ impl TryFrom<(InformationRequestTag, &[u8])> for InformationRequest {
InformationRequestTag::Reward => {
let (era_identifier, remainder) = <Option<EraIdentifier>>::from_bytes(key_bytes)?;
let (validator, remainder) = PublicKey::from_bytes(remainder)?;
let (delegator, remainder) = <Option<PublicKey>>::from_bytes(remainder)?;
let (delegator, remainder) = <Option<DelegatorKind>>::from_bytes(remainder)?;
(
InformationRequest::Reward {
era_identifier,
Expand Down
4 changes: 2 additions & 2 deletions binary_port/src/key_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl ToBytes for KeyPrefix {
match self {
KeyPrefix::DelegatorBidAddrsByValidator(validator) => {
writer.push(KeyTag::BidAddr as u8);
writer.push(BidAddrTag::Delegator as u8);
writer.push(BidAddrTag::DelegatedAccount as u8);
validator.write_bytes(writer)?;
}
KeyPrefix::MessagesByEntity(entity) => {
Expand Down Expand Up @@ -134,7 +134,7 @@ impl FromBytes for KeyPrefix {
tag if tag == KeyTag::BidAddr as u8 => {
let (bid_addr_tag, remainder) = u8::from_bytes(remainder)?;
match bid_addr_tag {
tag if tag == BidAddrTag::Delegator as u8 => {
tag if tag == BidAddrTag::DelegatedAccount as u8 => {
let (validator, remainder) = AccountHash::from_bytes(remainder)?;
(
KeyPrefix::DelegatorBidAddrsByValidator(validator),
Expand Down
Loading

0 comments on commit 26943ed

Please sign in to comment.