Skip to content
Snippets Groups Projects

Resolve "TransactionDocument: replace Vec fields by SmallVec"

Files
25
@@ -37,6 +37,7 @@ use dubp_user_docs::documents::transaction::v10::{
use dup_crypto::hashs::Hash;
use dup_crypto::keys::*;
use durs_common_tools::{fatal_error, UsizeSer32};
use smallvec::{smallvec, SmallVec};
use unwrap::unwrap;
/// Wrap a Block document.
@@ -71,10 +72,10 @@ pub struct BlockDocumentV10 {
/// Currency.
pub currency: CurrencyName,
/// Document issuer (there should be only one).
pub issuers: Vec<PubKey>,
pub issuers: SmallVec<[PubKey; 4]>,
/// Document signature (there should be only one).
/// This vector is empty, when the block is generated but the proof of work has not yet started
pub signatures: Vec<Sig>,
pub signatures: SmallVec<[Sig; 4]>,
/// The hash is None, when the block is generated but the proof of work has not yet started
pub hash: Option<BlockHash>,
/// Currency parameters (only in genesis block)
@@ -317,7 +318,7 @@ Transactions:{transactions}
}
}
fn sign(&mut self, signator: &SignatorEnum) {
self.signatures = vec![signator.sign(self.compute_will_signed_string().as_bytes())];
self.signatures = smallvec![signator.sign(self.compute_will_signed_string().as_bytes())];
}
fn verify_inner_hash(&self) -> Result<(), VerifyBlockHashError> {
match self.inner_hash {
@@ -390,12 +391,12 @@ impl Document for BlockDocumentV10 {
}
#[inline]
fn issuers(&self) -> &Vec<PubKey> {
fn issuers(&self) -> &SmallVec<[Self::PublicKey; 4]> {
&self.issuers
}
#[inline]
fn signatures(&self) -> &Vec<Sig> {
fn signatures(&self) -> &SmallVec<[Sig; 4]> {
&self.signatures
}
@@ -615,8 +616,8 @@ mod tests {
issuers_frame: UsizeSer32(41),
issuers_frame_var: 0,
currency: CurrencyName(String::from("g1-test")),
issuers: vec![PubKey::Ed25519(unwrap!(ed25519::PublicKey::from_base58("39Fnossy1GrndwCnAXGDw3K5UYXhNXAFQe7yhYZp8ELP"), "Fail to build PublicKey from base58"))],
signatures: vec![Sig::Ed25519(unwrap!(ed25519::Signature::from_base64("lqXrNOopjM39oM7hgB7Vq13uIohdCuLlhh/q8RVVEZ5UVASphow/GXikCdhbWID19Bn0XrXzTbt/R7akbE9xAg=="), "Fail to build Signature from base64"))],
issuers: smallvec![PubKey::Ed25519(unwrap!(ed25519::PublicKey::from_base58("39Fnossy1GrndwCnAXGDw3K5UYXhNXAFQe7yhYZp8ELP"), "Fail to build PublicKey from base58"))],
signatures: smallvec![Sig::Ed25519(unwrap!(ed25519::Signature::from_base64("lqXrNOopjM39oM7hgB7Vq13uIohdCuLlhh/q8RVVEZ5UVASphow/GXikCdhbWID19Bn0XrXzTbt/R7akbE9xAg=="), "Fail to build Signature from base64"))],
hash: None,
parameters: None,
previous_hash: Some(Hash::from_hex("0000A7D4361B9EBF4CE974A521149A73E8A5DE9B73907AB3BC918726AED7D40A").expect("fail to parse previous_hash")),
@@ -716,8 +717,8 @@ a9PHPuSfw7jW8FRQHXFsGi/bnLjbtDnTYvEVgUC9u0WlR7GVofa+Xb+l5iy6NwuEXiwvueAkf08wPVY8
issuers_frame: UsizeSer32(211),
issuers_frame_var: 0,
currency: CurrencyName(String::from("g1")),
issuers: vec![PubKey::Ed25519(unwrap!(ed25519::PublicKey::from_base58("DA4PYtXdvQqk1nCaprXH52iMsK5Ahxs1nRWbWKLhpVkQ"), "Fail to build PublicKey from base58"))],
signatures: vec![Sig::Ed25519(unwrap!(ed25519::Signature::from_base64("92id58VmkhgVNee4LDqBGSm8u/ooHzAD67JM6fhAE/CV8LCz7XrMF1DvRl+eRpmlaVkp6I+Iy8gmZ1WUM5C8BA=="), "Fail to build Signature from base64"))],
issuers: smallvec![PubKey::Ed25519(unwrap!(ed25519::PublicKey::from_base58("DA4PYtXdvQqk1nCaprXH52iMsK5Ahxs1nRWbWKLhpVkQ"), "Fail to build PublicKey from base58"))],
signatures: smallvec![Sig::Ed25519(unwrap!(ed25519::Signature::from_base64("92id58VmkhgVNee4LDqBGSm8u/ooHzAD67JM6fhAE/CV8LCz7XrMF1DvRl+eRpmlaVkp6I+Iy8gmZ1WUM5C8BA=="), "Fail to build Signature from base64"))],
hash: None,
parameters: None,
previous_hash: Some(Hash::from_hex("000001144968D0C3516BE6225E4662F182E28956AF46DD7FB228E3D0F9413FEB").expect("fail to parse previous_hash")),
@@ -896,8 +897,8 @@ nxr4exGrt16jteN9ZX3XZPP9l+X0OUbZ1o/QjE1hbWQNtVU3HhH9SJoEvNj2iVl3gCRr9u2OA9uj9vCy
issuers_frame: UsizeSer32(186),
issuers_frame_var: 0,
currency: CurrencyName(String::from("g1")),
issuers: vec![PubKey::Ed25519(unwrap!(ed25519::PublicKey::from_base58("A4pc9Uuk4NXkWG8CibicjjPpEPdiup1mhjMoRWUZsonq"), "Fail to build PublicKey from base58"))],
signatures: vec![Sig::Ed25519(unwrap!(ed25519::Signature::from_base64("2Z/+9ADdZvHXs19YR8+qDzgfl8WJlBG5PcbFvBG9TOuUJbjAdxhcgxrFrSRIABGWcCrIgLkB805fZVLP8jOjBA=="), "Fail to build Signature from base64"))],
issuers: smallvec![PubKey::Ed25519(unwrap!(ed25519::PublicKey::from_base58("A4pc9Uuk4NXkWG8CibicjjPpEPdiup1mhjMoRWUZsonq"), "Fail to build PublicKey from base58"))],
signatures: smallvec![Sig::Ed25519(unwrap!(ed25519::Signature::from_base64("2Z/+9ADdZvHXs19YR8+qDzgfl8WJlBG5PcbFvBG9TOuUJbjAdxhcgxrFrSRIABGWcCrIgLkB805fZVLP8jOjBA=="), "Fail to build Signature from base64"))],
hash: None,
parameters: None,
previous_hash: Some(Hash::from_hex("000003E78FA4133F2C13B416F330C8DFB5A41EB87E37190615DB334F2C914A51").expect("fail to parse previous_hash")),
Loading