Skip to content

Commit

Permalink
rename RemoveTlcFail to TlcErrPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Oct 13, 2024
1 parent 8cfb17f commit 0240cea
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 96 deletions.
10 changes: 5 additions & 5 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
fiber::{
fee::calculate_tlc_forward_fee,
network::{get_chain_hash, SendOnionPacketCommand},
types::{ChannelUpdate, RemoveTlcFail, TlcErr, TlcErrorCode},
types::{ChannelUpdate, TlcErr, TlcErrPacket, TlcErrorCode},
},
invoice::InvoiceStore,
};
Expand Down Expand Up @@ -120,7 +120,7 @@ pub enum ChannelCommand {
CommitmentSigned(),
AddTlc(
AddTlcCommand,
RpcReplyPort<Result<AddTlcResponse, RemoveTlcFail>>,
RpcReplyPort<Result<AddTlcResponse, TlcErrPacket>>,
),
RemoveTlc(RemoveTlcCommand, RpcReplyPort<Result<(), String>>),
Shutdown(ShutdownCommand, RpcReplyPort<Result<(), String>>),
Expand Down Expand Up @@ -501,7 +501,7 @@ where
channel_id: state.get_id(),
tlc_id,
reason: RemoveTlcReason::RemoveTlcFail(
RemoveTlcFail::new(error_detail),
TlcErrPacket::new(error_detail),
),
}),
),
Expand Down Expand Up @@ -864,7 +864,7 @@ where
onion_packet: Vec<u8>,
added_tlc_id: u64,
) -> Result<(), ProcessingChannelError> {
let (send, recv) = oneshot::channel::<Result<u64, RemoveTlcFail>>();
let (send, recv) = oneshot::channel::<Result<u64, TlcErrPacket>>();
let rpc_reply = RpcReplyPort::from(send);
self.network
.send_message(NetworkActorMessage::Command(
Expand Down Expand Up @@ -1350,7 +1350,7 @@ where
}
Err(err) => {
let error_detail = self.get_tlc_detail_error(state, &err).await;
let _ = reply.send(Err(RemoveTlcFail::new(error_detail)));
let _ = reply.send(Err(TlcErrPacket::new(error_detail)));
Err(err)
}
}
Expand Down
114 changes: 57 additions & 57 deletions src/fiber/gen/fiber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9496,8 +9496,8 @@ impl molecule::prelude::Builder for RemoveTlcFulfillBuilder {
}
}
#[derive(Clone)]
pub struct RemoveTlcFail(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for RemoveTlcFail {
pub struct TlcErrPacket(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for TlcErrPacket {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
Expand All @@ -9506,12 +9506,12 @@ impl ::core::fmt::LowerHex for RemoveTlcFail {
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for RemoveTlcFail {
impl ::core::fmt::Debug for TlcErrPacket {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for RemoveTlcFail {
impl ::core::fmt::Display for TlcErrPacket {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "onion_packet", self.onion_packet())?;
Expand All @@ -9522,13 +9522,13 @@ impl ::core::fmt::Display for RemoveTlcFail {
write!(f, " }}")
}
}
impl ::core::default::Default for RemoveTlcFail {
impl ::core::default::Default for TlcErrPacket {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
RemoveTlcFail::new_unchecked(v)
TlcErrPacket::new_unchecked(v)
}
}
impl RemoveTlcFail {
impl TlcErrPacket {
const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
Expand Down Expand Up @@ -9557,15 +9557,15 @@ impl RemoveTlcFail {
Bytes::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> RemoveTlcFailReader<'r> {
RemoveTlcFailReader::new_unchecked(self.as_slice())
pub fn as_reader<'r>(&'r self) -> TlcErrPacketReader<'r> {
TlcErrPacketReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for RemoveTlcFail {
type Builder = RemoveTlcFailBuilder;
const NAME: &'static str = "RemoveTlcFail";
impl molecule::prelude::Entity for TlcErrPacket {
type Builder = TlcErrPacketBuilder;
const NAME: &'static str = "TlcErrPacket";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
RemoveTlcFail(data)
TlcErrPacket(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
Expand All @@ -9574,10 +9574,10 @@ impl molecule::prelude::Entity for RemoveTlcFail {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
RemoveTlcFailReader::from_slice(slice).map(|reader| reader.to_entity())
TlcErrPacketReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
RemoveTlcFailReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
TlcErrPacketReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
Expand All @@ -9587,8 +9587,8 @@ impl molecule::prelude::Entity for RemoveTlcFail {
}
}
#[derive(Clone, Copy)]
pub struct RemoveTlcFailReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for RemoveTlcFailReader<'r> {
pub struct TlcErrPacketReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for TlcErrPacketReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
Expand All @@ -9597,12 +9597,12 @@ impl<'r> ::core::fmt::LowerHex for RemoveTlcFailReader<'r> {
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for RemoveTlcFailReader<'r> {
impl<'r> ::core::fmt::Debug for TlcErrPacketReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for RemoveTlcFailReader<'r> {
impl<'r> ::core::fmt::Display for TlcErrPacketReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "onion_packet", self.onion_packet())?;
Expand All @@ -9613,7 +9613,7 @@ impl<'r> ::core::fmt::Display for RemoveTlcFailReader<'r> {
write!(f, " }}")
}
}
impl<'r> RemoveTlcFailReader<'r> {
impl<'r> TlcErrPacketReader<'r> {
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
Expand Down Expand Up @@ -9642,14 +9642,14 @@ impl<'r> RemoveTlcFailReader<'r> {
}
}
}
impl<'r> molecule::prelude::Reader<'r> for RemoveTlcFailReader<'r> {
type Entity = RemoveTlcFail;
const NAME: &'static str = "RemoveTlcFailReader";
impl<'r> molecule::prelude::Reader<'r> for TlcErrPacketReader<'r> {
type Entity = TlcErrPacket;
const NAME: &'static str = "TlcErrPacketReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
RemoveTlcFailReader(slice)
TlcErrPacketReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
Expand Down Expand Up @@ -9693,19 +9693,19 @@ impl<'r> molecule::prelude::Reader<'r> for RemoveTlcFailReader<'r> {
}
}
#[derive(Clone, Debug, Default)]
pub struct RemoveTlcFailBuilder {
pub struct TlcErrPacketBuilder {
pub(crate) onion_packet: Bytes,
}
impl RemoveTlcFailBuilder {
impl TlcErrPacketBuilder {
pub const FIELD_COUNT: usize = 1;
pub fn onion_packet(mut self, v: Bytes) -> Self {
self.onion_packet = v;
self
}
}
impl molecule::prelude::Builder for RemoveTlcFailBuilder {
type Entity = RemoveTlcFail;
const NAME: &'static str = "RemoveTlcFailBuilder";
impl molecule::prelude::Builder for TlcErrPacketBuilder {
type Entity = TlcErrPacket;
const NAME: &'static str = "TlcErrPacketBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.onion_packet.as_slice().len()
}
Expand All @@ -9725,7 +9725,7 @@ impl molecule::prelude::Builder for RemoveTlcFailBuilder {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
RemoveTlcFail::new_unchecked(inner.into())
TlcErrPacket::new_unchecked(inner.into())
}
}
#[derive(Clone)]
Expand Down Expand Up @@ -9770,7 +9770,7 @@ impl RemoveTlcReason {
let inner = self.0.slice(molecule::NUMBER_SIZE..);
match self.item_id() {
0 => RemoveTlcFulfill::new_unchecked(inner).into(),
1 => RemoveTlcFail::new_unchecked(inner).into(),
1 => TlcErrPacket::new_unchecked(inner).into(),
_ => panic!("{}: invalid data", Self::NAME),
}
}
Expand Down Expand Up @@ -9835,7 +9835,7 @@ impl<'r> RemoveTlcReasonReader<'r> {
let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
match self.item_id() {
0 => RemoveTlcFulfillReader::new_unchecked(inner).into(),
1 => RemoveTlcFailReader::new_unchecked(inner).into(),
1 => TlcErrPacketReader::new_unchecked(inner).into(),
_ => panic!("{}: invalid data", Self::NAME),
}
}
Expand All @@ -9862,7 +9862,7 @@ impl<'r> molecule::prelude::Reader<'r> for RemoveTlcReasonReader<'r> {
let inner_slice = &slice[molecule::NUMBER_SIZE..];
match item_id {
0 => RemoveTlcFulfillReader::verify(inner_slice, compatible),
1 => RemoveTlcFailReader::verify(inner_slice, compatible),
1 => TlcErrPacketReader::verify(inner_slice, compatible),
_ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
}?;
Ok(())
Expand Down Expand Up @@ -9900,12 +9900,12 @@ impl molecule::prelude::Builder for RemoveTlcReasonBuilder {
#[derive(Debug, Clone)]
pub enum RemoveTlcReasonUnion {
RemoveTlcFulfill(RemoveTlcFulfill),
RemoveTlcFail(RemoveTlcFail),
TlcErrPacket(TlcErrPacket),
}
#[derive(Debug, Clone, Copy)]
pub enum RemoveTlcReasonUnionReader<'r> {
RemoveTlcFulfill(RemoveTlcFulfillReader<'r>),
RemoveTlcFail(RemoveTlcFailReader<'r>),
TlcErrPacket(TlcErrPacketReader<'r>),
}
impl ::core::default::Default for RemoveTlcReasonUnion {
fn default() -> Self {
Expand All @@ -9918,8 +9918,8 @@ impl ::core::fmt::Display for RemoveTlcReasonUnion {
RemoveTlcReasonUnion::RemoveTlcFulfill(ref item) => {
write!(f, "{}::{}({})", Self::NAME, RemoveTlcFulfill::NAME, item)
}
RemoveTlcReasonUnion::RemoveTlcFail(ref item) => {
write!(f, "{}::{}({})", Self::NAME, RemoveTlcFail::NAME, item)
RemoveTlcReasonUnion::TlcErrPacket(ref item) => {
write!(f, "{}::{}({})", Self::NAME, TlcErrPacket::NAME, item)
}
}
}
Expand All @@ -9930,8 +9930,8 @@ impl<'r> ::core::fmt::Display for RemoveTlcReasonUnionReader<'r> {
RemoveTlcReasonUnionReader::RemoveTlcFulfill(ref item) => {
write!(f, "{}::{}({})", Self::NAME, RemoveTlcFulfill::NAME, item)
}
RemoveTlcReasonUnionReader::RemoveTlcFail(ref item) => {
write!(f, "{}::{}({})", Self::NAME, RemoveTlcFail::NAME, item)
RemoveTlcReasonUnionReader::TlcErrPacket(ref item) => {
write!(f, "{}::{}({})", Self::NAME, TlcErrPacket::NAME, item)
}
}
}
Expand All @@ -9940,15 +9940,15 @@ impl RemoveTlcReasonUnion {
pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
RemoveTlcReasonUnion::RemoveTlcFulfill(ref item) => write!(f, "{}", item),
RemoveTlcReasonUnion::RemoveTlcFail(ref item) => write!(f, "{}", item),
RemoveTlcReasonUnion::TlcErrPacket(ref item) => write!(f, "{}", item),
}
}
}
impl<'r> RemoveTlcReasonUnionReader<'r> {
pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
RemoveTlcReasonUnionReader::RemoveTlcFulfill(ref item) => write!(f, "{}", item),
RemoveTlcReasonUnionReader::RemoveTlcFail(ref item) => write!(f, "{}", item),
RemoveTlcReasonUnionReader::TlcErrPacket(ref item) => write!(f, "{}", item),
}
}
}
Expand All @@ -9957,51 +9957,51 @@ impl ::core::convert::From<RemoveTlcFulfill> for RemoveTlcReasonUnion {
RemoveTlcReasonUnion::RemoveTlcFulfill(item)
}
}
impl ::core::convert::From<RemoveTlcFail> for RemoveTlcReasonUnion {
fn from(item: RemoveTlcFail) -> Self {
RemoveTlcReasonUnion::RemoveTlcFail(item)
impl ::core::convert::From<TlcErrPacket> for RemoveTlcReasonUnion {
fn from(item: TlcErrPacket) -> Self {
RemoveTlcReasonUnion::TlcErrPacket(item)
}
}
impl<'r> ::core::convert::From<RemoveTlcFulfillReader<'r>> for RemoveTlcReasonUnionReader<'r> {
fn from(item: RemoveTlcFulfillReader<'r>) -> Self {
RemoveTlcReasonUnionReader::RemoveTlcFulfill(item)
}
}
impl<'r> ::core::convert::From<RemoveTlcFailReader<'r>> for RemoveTlcReasonUnionReader<'r> {
fn from(item: RemoveTlcFailReader<'r>) -> Self {
RemoveTlcReasonUnionReader::RemoveTlcFail(item)
impl<'r> ::core::convert::From<TlcErrPacketReader<'r>> for RemoveTlcReasonUnionReader<'r> {
fn from(item: TlcErrPacketReader<'r>) -> Self {
RemoveTlcReasonUnionReader::TlcErrPacket(item)
}
}
impl RemoveTlcReasonUnion {
pub const NAME: &'static str = "RemoveTlcReasonUnion";
pub fn as_bytes(&self) -> molecule::bytes::Bytes {
match self {
RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_bytes(),
RemoveTlcReasonUnion::RemoveTlcFail(item) => item.as_bytes(),
RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_bytes(),
}
}
pub fn as_slice(&self) -> &[u8] {
match self {
RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_slice(),
RemoveTlcReasonUnion::RemoveTlcFail(item) => item.as_slice(),
RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_slice(),
}
}
pub fn item_id(&self) -> molecule::Number {
match self {
RemoveTlcReasonUnion::RemoveTlcFulfill(_) => 0,
RemoveTlcReasonUnion::RemoveTlcFail(_) => 1,
RemoveTlcReasonUnion::TlcErrPacket(_) => 1,
}
}
pub fn item_name(&self) -> &str {
match self {
RemoveTlcReasonUnion::RemoveTlcFulfill(_) => "RemoveTlcFulfill",
RemoveTlcReasonUnion::RemoveTlcFail(_) => "RemoveTlcFail",
RemoveTlcReasonUnion::TlcErrPacket(_) => "TlcErrPacket",
}
}
pub fn as_reader<'r>(&'r self) -> RemoveTlcReasonUnionReader<'r> {
match self {
RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_reader().into(),
RemoveTlcReasonUnion::RemoveTlcFail(item) => item.as_reader().into(),
RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_reader().into(),
}
}
}
Expand All @@ -10010,19 +10010,19 @@ impl<'r> RemoveTlcReasonUnionReader<'r> {
pub fn as_slice(&self) -> &'r [u8] {
match self {
RemoveTlcReasonUnionReader::RemoveTlcFulfill(item) => item.as_slice(),
RemoveTlcReasonUnionReader::RemoveTlcFail(item) => item.as_slice(),
RemoveTlcReasonUnionReader::TlcErrPacket(item) => item.as_slice(),
}
}
pub fn item_id(&self) -> molecule::Number {
match self {
RemoveTlcReasonUnionReader::RemoveTlcFulfill(_) => 0,
RemoveTlcReasonUnionReader::RemoveTlcFail(_) => 1,
RemoveTlcReasonUnionReader::TlcErrPacket(_) => 1,
}
}
pub fn item_name(&self) -> &str {
match self {
RemoveTlcReasonUnionReader::RemoveTlcFulfill(_) => "RemoveTlcFulfill",
RemoveTlcReasonUnionReader::RemoveTlcFail(_) => "RemoveTlcFail",
RemoveTlcReasonUnionReader::TlcErrPacket(_) => "TlcErrPacket",
}
}
}
Expand All @@ -10031,8 +10031,8 @@ impl From<RemoveTlcFulfill> for RemoveTlcReason {
Self::new_builder().set(value).build()
}
}
impl From<RemoveTlcFail> for RemoveTlcReason {
fn from(value: RemoveTlcFail) -> Self {
impl From<TlcErrPacket> for RemoveTlcReason {
fn from(value: TlcErrPacket) -> Self {
Self::new_builder().set(value).build()
}
}
Expand Down
Loading

0 comments on commit 0240cea

Please sign in to comment.