mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
support add/read multiple arbitrary tx data (#189)
* support add/read multiple arbitrary tx data * fix clippy errors * resolve pr issues
This commit is contained in:
@@ -73,7 +73,7 @@ pub struct Metadata {
|
||||
// have this making it simplest for it to be as-is.
|
||||
pub payment_id: [u8; 8],
|
||||
/// Arbitrary data encoded in TX extra.
|
||||
pub arbitrary_data: Option<Vec<u8>>,
|
||||
pub arbitrary_data: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
@@ -82,11 +82,11 @@ impl Metadata {
|
||||
res.extend(self.subaddress.0.to_le_bytes());
|
||||
res.extend(self.subaddress.1.to_le_bytes());
|
||||
res.extend(self.payment_id);
|
||||
if let Some(data) = self.arbitrary_data.as_ref() {
|
||||
res.extend([1, u8::try_from(data.len()).unwrap()]);
|
||||
res.extend(data);
|
||||
} else {
|
||||
res.extend([0]);
|
||||
|
||||
res.extend(u32::try_from(self.arbitrary_data.len()).unwrap().to_le_bytes());
|
||||
for part in &self.arbitrary_data {
|
||||
res.extend([u8::try_from(part.len()).unwrap()]);
|
||||
res.extend(part);
|
||||
}
|
||||
res
|
||||
}
|
||||
@@ -96,12 +96,12 @@ impl Metadata {
|
||||
subaddress: (read_u32(r)?, read_u32(r)?),
|
||||
payment_id: read_bytes(r)?,
|
||||
arbitrary_data: {
|
||||
if read_byte(r)? == 1 {
|
||||
let mut data = vec![];
|
||||
for _ in 0 .. read_u32(r)? {
|
||||
let len = read_byte(r)?;
|
||||
Some(read_raw_vec(read_byte, usize::from(len), r)?)
|
||||
} else {
|
||||
None
|
||||
data.push(read_raw_vec(read_byte, usize::from(len), r)?);
|
||||
}
|
||||
data
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -128,6 +128,10 @@ impl ReceivedOutput {
|
||||
self.data.commitment.clone()
|
||||
}
|
||||
|
||||
pub fn arbitrary_data(&self) -> &[Vec<u8>] {
|
||||
&self.metadata.arbitrary_data
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
let mut serialized = self.absolute.serialize();
|
||||
serialized.extend(&self.data.serialize());
|
||||
|
||||
Reference in New Issue
Block a user