mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Bitcoin Output/Transaction definitions
This commit is contained in:
@@ -10,7 +10,7 @@ use serai_db::{Get, DbTxn, create_db, db_channel};
|
||||
use serai_in_instructions_primitives::{InInstructionWithBalance, Batch};
|
||||
use serai_coins_primitives::OutInstructionWithBalance;
|
||||
|
||||
use primitives::{EncodableG, Address, ReceivedOutput};
|
||||
use primitives::{EncodableG, ReceivedOutput};
|
||||
|
||||
use crate::{
|
||||
lifetime::{LifetimeStage, Lifetime},
|
||||
@@ -49,7 +49,7 @@ impl<S: ScannerFeed> OutputWithInInstruction<S> {
|
||||
let mut opt = [0xff];
|
||||
reader.read_exact(&mut opt)?;
|
||||
assert!((opt[0] == 0) || (opt[0] == 1));
|
||||
(opt[0] == 1).then(|| AddressFor::<S>::read(reader)).transpose()?
|
||||
(opt[0] == 1).then(|| AddressFor::<S>::deserialize_reader(reader)).transpose()?
|
||||
};
|
||||
let in_instruction =
|
||||
InInstructionWithBalance::decode(&mut IoReader(reader)).map_err(io::Error::other)?;
|
||||
@@ -59,7 +59,7 @@ impl<S: ScannerFeed> OutputWithInInstruction<S> {
|
||||
self.output.write(writer)?;
|
||||
if let Some(return_address) = &self.return_address {
|
||||
writer.write_all(&[1])?;
|
||||
return_address.write(writer)?;
|
||||
return_address.serialize(writer)?;
|
||||
} else {
|
||||
writer.write_all(&[0])?;
|
||||
}
|
||||
@@ -278,7 +278,7 @@ impl<S: ScannerFeed> ScannerGlobalDb<S> {
|
||||
buf.read_exact(&mut opt).unwrap();
|
||||
assert!((opt[0] == 0) || (opt[0] == 1));
|
||||
|
||||
let address = (opt[0] == 1).then(|| AddressFor::<S>::read(&mut buf).unwrap());
|
||||
let address = (opt[0] == 1).then(|| AddressFor::<S>::deserialize_reader(&mut buf).unwrap());
|
||||
Some((address, InInstructionWithBalance::decode(&mut IoReader(buf)).unwrap()))
|
||||
}
|
||||
}
|
||||
@@ -338,7 +338,7 @@ impl<S: ScannerFeed> ScanToEventualityDb<S> {
|
||||
let mut buf = vec![];
|
||||
if let Some(address) = &forward.return_address {
|
||||
buf.write_all(&[1]).unwrap();
|
||||
address.write(&mut buf).unwrap();
|
||||
address.serialize(&mut buf).unwrap();
|
||||
} else {
|
||||
buf.write_all(&[0]).unwrap();
|
||||
}
|
||||
@@ -435,7 +435,8 @@ impl<S: ScannerFeed> Returnable<S> {
|
||||
reader.read_exact(&mut opt).unwrap();
|
||||
assert!((opt[0] == 0) || (opt[0] == 1));
|
||||
|
||||
let return_address = (opt[0] == 1).then(|| AddressFor::<S>::read(reader)).transpose()?;
|
||||
let return_address =
|
||||
(opt[0] == 1).then(|| AddressFor::<S>::deserialize_reader(reader)).transpose()?;
|
||||
|
||||
let in_instruction =
|
||||
InInstructionWithBalance::decode(&mut IoReader(reader)).map_err(io::Error::other)?;
|
||||
@@ -444,7 +445,7 @@ impl<S: ScannerFeed> Returnable<S> {
|
||||
fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
||||
if let Some(return_address) = &self.return_address {
|
||||
writer.write_all(&[1])?;
|
||||
return_address.write(writer)?;
|
||||
return_address.serialize(writer)?;
|
||||
} else {
|
||||
writer.write_all(&[0])?;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use std::{io, collections::HashMap};
|
||||
|
||||
use group::GroupEncoding;
|
||||
|
||||
use borsh::{BorshSerialize, BorshDeserialize};
|
||||
use serai_db::{Get, DbTxn, Db};
|
||||
|
||||
use serai_primitives::{NetworkId, Coin, Amount};
|
||||
@@ -179,12 +180,12 @@ pub struct Return<S: ScannerFeed> {
|
||||
|
||||
impl<S: ScannerFeed> Return<S> {
|
||||
pub(crate) fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
||||
self.address.write(writer)?;
|
||||
self.address.serialize(writer)?;
|
||||
self.output.write(writer)
|
||||
}
|
||||
|
||||
pub(crate) fn read(reader: &mut impl io::Read) -> io::Result<Self> {
|
||||
let address = AddressFor::<S>::read(reader)?;
|
||||
let address = AddressFor::<S>::deserialize_reader(reader)?;
|
||||
let output = OutputFor::<S>::read(reader)?;
|
||||
Ok(Return { address, output })
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ use std::io::{Read, Write};
|
||||
use group::GroupEncoding;
|
||||
|
||||
use scale::{Encode, Decode, IoReader};
|
||||
use borsh::{BorshSerialize, BorshDeserialize};
|
||||
use serai_db::{Get, DbTxn, create_db};
|
||||
|
||||
use serai_primitives::Balance;
|
||||
|
||||
use primitives::Address;
|
||||
|
||||
use crate::{ScannerFeed, KeyFor, AddressFor};
|
||||
|
||||
create_db!(
|
||||
@@ -92,7 +91,7 @@ impl<S: ScannerFeed> ReportDb<S> {
|
||||
for return_information in return_information {
|
||||
if let Some(ReturnInformation { address, balance }) = return_information {
|
||||
buf.write_all(&[1]).unwrap();
|
||||
address.write(&mut buf).unwrap();
|
||||
address.serialize(&mut buf).unwrap();
|
||||
balance.encode_to(&mut buf);
|
||||
} else {
|
||||
buf.write_all(&[0]).unwrap();
|
||||
@@ -115,7 +114,7 @@ impl<S: ScannerFeed> ReportDb<S> {
|
||||
assert!((opt[0] == 0) || (opt[0] == 1));
|
||||
|
||||
res.push((opt[0] == 1).then(|| {
|
||||
let address = AddressFor::<S>::read(&mut buf).unwrap();
|
||||
let address = AddressFor::<S>::deserialize_reader(&mut buf).unwrap();
|
||||
let balance = Balance::decode(&mut IoReader(&mut buf)).unwrap();
|
||||
ReturnInformation { address, balance }
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user