partial.rs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. use std::io;
  2. use super::TransactionOutput;
  3. use crate::{
  4. crypto::{keypair::PublicKey, spend_proof::SpendRevealedValues, Proof},
  5. error::Result,
  6. impl_vec,
  7. serial::{Decodable, Encodable, VarInt},
  8. types::{DrkTokenId, DrkValueBlind},
  9. };
  10. pub struct PartialTransaction {
  11. pub clear_inputs: Vec<PartialTransactionClearInput>,
  12. pub inputs: Vec<PartialTransactionInput>,
  13. pub outputs: Vec<TransactionOutput>,
  14. }
  15. pub struct PartialTransactionClearInput {
  16. pub value: u64,
  17. pub token_id: DrkTokenId,
  18. pub value_blind: DrkValueBlind,
  19. pub token_blind: DrkValueBlind,
  20. pub signature_public: PublicKey,
  21. }
  22. pub struct PartialTransactionInput {
  23. pub spend_proof: Proof,
  24. pub revealed: SpendRevealedValues,
  25. }
  26. impl Encodable for PartialTransaction {
  27. fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
  28. let mut len = 0;
  29. len += self.clear_inputs.encode(&mut s)?;
  30. len += self.inputs.encode(&mut s)?;
  31. len += self.outputs.encode(s)?;
  32. Ok(len)
  33. }
  34. }
  35. impl Decodable for PartialTransaction {
  36. fn decode<D: io::Read>(mut d: D) -> Result<Self> {
  37. Ok(Self {
  38. clear_inputs: Decodable::decode(&mut d)?,
  39. inputs: Decodable::decode(&mut d)?,
  40. outputs: Decodable::decode(d)?,
  41. })
  42. }
  43. }
  44. impl Encodable for PartialTransactionClearInput {
  45. fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
  46. let mut len = 0;
  47. len += self.value.encode(&mut s)?;
  48. len += self.token_id.encode(&mut s)?;
  49. len += self.value_blind.encode(&mut s)?;
  50. len += self.token_blind.encode(&mut s)?;
  51. len += self.signature_public.encode(&mut s)?;
  52. Ok(len)
  53. }
  54. }
  55. impl Decodable for PartialTransactionClearInput {
  56. fn decode<D: io::Read>(mut d: D) -> Result<Self> {
  57. Ok(Self {
  58. value: Decodable::decode(&mut d)?,
  59. token_id: Decodable::decode(&mut d)?,
  60. value_blind: Decodable::decode(&mut d)?,
  61. token_blind: Decodable::decode(&mut d)?,
  62. signature_public: Decodable::decode(&mut d)?,
  63. })
  64. }
  65. }
  66. impl Encodable for PartialTransactionInput {
  67. fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
  68. let mut len = 0;
  69. len += self.spend_proof.encode(&mut s)?;
  70. len += self.revealed.encode(s)?;
  71. Ok(len)
  72. }
  73. }
  74. impl Decodable for PartialTransactionInput {
  75. fn decode<D: io::Read>(mut d: D) -> Result<Self> {
  76. Ok(Self { spend_proof: Decodable::decode(&mut d)?, revealed: Decodable::decode(d)? })
  77. }
  78. }
  79. impl_vec!(PartialTransactionClearInput);
  80. impl_vec!(PartialTransactionInput);