partial.rs 2.6 KB

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