pub struct Stake {
pub public_key: PublicKeyBytes,
pub deposit: bool,
pub amount: u128,
pub fee: u128,
pub timestamp: u32,
pub signature: SignatureBytes,
}Fields§
§public_key: PublicKeyBytes§deposit: bool§amount: u128§fee: u128§timestamp: u32§signature: SignatureBytesImplementations§
source§impl Stake
impl Stake
pub fn new(deposit: bool, amount: u128, fee: u128, timestamp: u32) -> Stake
sourcepub fn hash(&self) -> Hash
pub fn hash(&self) -> Hash
Examples found in repository?
src/lib.rs (line 41)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#![allow(dead_code)]
#[derive(Debug)]
struct Stake {
hash: String,
public_key: String,
deposit: bool,
amount: u128,
fee: u128,
timestamp: u32,
signature: String,
}
write!(
f,
"{:?}",
Stake {
hash: hex::encode(self.hash()),
public_key: pea_address::public::encode(&self.public_key),
deposit: self.deposit,
amount: self.amount,
fee: self.fee,
timestamp: self.timestamp,
signature: hex::encode(self.signature),
}
)
}
}
impl Stake {
pub fn new(deposit: bool, amount: u128, fee: u128, timestamp: u32) -> Stake {
Stake {
public_key: [0; 32],
deposit,
amount: pea_int::floor(amount),
fee: pea_int::floor(fee),
timestamp,
signature: [0; 64],
}
}
pub fn hash(&self) -> types::Hash {
util::hash(&bincode::serialize(&self.header()).unwrap())
}
pub fn sign(&mut self, key: &Key) {
self.public_key = key.public_key();
self.signature = key.sign(&self.hash());
}
pub fn verify(&self) -> Result<(), Box<dyn Error>> {
Key::verify(&self.public_key, &self.hash(), &self.signature)
}pub fn sign(&mut self, key: &Key)
sourcepub fn verify(&self) -> Result<(), Box<dyn Error>>
pub fn verify(&self) -> Result<(), Box<dyn Error>>
Examples found in repository?
src/lib.rs (line 83)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
pub fn validate(&self) -> Result<(), Box<dyn Error>> {
if self.verify().is_err() {
return Err("stake signature".into());
}
if self.amount == 0 {
return Err("stake amount zero".into());
}
if self.fee == 0 {
return Err("stake fee zero".into());
}
if self.amount != pea_int::floor(self.amount) {
return Err("stake amount floor".into());
}
if self.fee != pea_int::floor(self.fee) {
return Err("stake fee floor".into());
}
Ok(())
}
pub fn validate_mint(&self) -> Result<(), Box<dyn Error>> {
if self.verify().is_err() {
return Err("stake mint signature".into());
}
if self.amount != MIN_STAKE {
return Err("stake mint amount not MIN_STAKE".into());
}
if self.fee != 0 {
return Err("stake mint fee not zero".into());
}
if !self.deposit {
return Err("stake mint deposit".into());
}
Ok(())
}pub fn validate(&self) -> Result<(), Box<dyn Error>>
pub fn validate_mint(&self) -> Result<(), Box<dyn Error>>
Trait Implementations§
source§impl<'de> Deserialize<'de> for Stake
impl<'de> Deserialize<'de> for Stake
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more