mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
msggen: Map arrays of hashes and add HtlcState enum
This commit is contained in:
parent
db843159ea
commit
0031f1160b
@ -38,6 +38,20 @@ enum ChannelState {
|
|||||||
DualopendAwaitingLockin = 10;
|
DualopendAwaitingLockin = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum HtlcState {
|
||||||
|
SentAddHtlc = 0;
|
||||||
|
SentAddCommit = 1;
|
||||||
|
RcvdAddRevocation = 2;
|
||||||
|
RcvdAddAckCommit = 3;
|
||||||
|
SentAddAckRevocation = 4;
|
||||||
|
RcvdAddAckRevocation = 5;
|
||||||
|
RcvdRemoveHtlc = 6;
|
||||||
|
RcvdRemoveCommit = 7;
|
||||||
|
SentRemoveRevocation = 8;
|
||||||
|
SentRemoveAckCommit = 9;
|
||||||
|
RcvdRemoveAckRevocation = 10;
|
||||||
|
}
|
||||||
|
|
||||||
message ChannelStateChangeCause {}
|
message ChannelStateChangeCause {}
|
||||||
|
|
||||||
message Outpoint {
|
message Outpoint {
|
||||||
|
@ -26,6 +26,22 @@ pub enum ChannelState {
|
|||||||
DUALOPEND_AWAITING_LOCKIN = 10,
|
DUALOPEND_AWAITING_LOCKIN = 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
pub enum HtlcState {
|
||||||
|
SENT_ADD_HTLC = 0,
|
||||||
|
SENT_ADD_COMMIT = 1,
|
||||||
|
RCVD_ADD_REVOCATION = 2,
|
||||||
|
RCVD_ADD_ACK_COMMIT = 3,
|
||||||
|
SENT_ADD_ACK_REVOCATION = 4,
|
||||||
|
RCVD_ADD_ACK_REVOCATION = 5,
|
||||||
|
RCVD_REMOVE_HTLC = 6,
|
||||||
|
RCVD_REMOVE_COMMIT = 7,
|
||||||
|
SENT_REMOVE_REVOCATION = 8,
|
||||||
|
SENT_REMOVE_ACK_COMMIT = 9,
|
||||||
|
RCVD_REMOVE_ACK_REVOCATION = 10,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
|
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
@ -289,6 +305,25 @@ impl TryFrom<i32> for ChannelState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<i32> for HtlcState {
|
||||||
|
fn from(value: i32) -> Self {
|
||||||
|
match value {
|
||||||
|
0 => HtlcState::SENT_ADD_HTLC,
|
||||||
|
1 => HtlcState::SENT_ADD_COMMIT,
|
||||||
|
2 => HtlcState::RCVD_ADD_REVOCATION,
|
||||||
|
3 => HtlcState::RCVD_ADD_ACK_COMMIT,
|
||||||
|
4 => HtlcState::SENT_ADD_ACK_REVOCATION,
|
||||||
|
5 => HtlcState::RCVD_ADD_ACK_REVOCATION,
|
||||||
|
6 => HtlcState::RCVD_REMOVE_HTLC,
|
||||||
|
7 => HtlcState::RCVD_REMOVE_COMMIT,
|
||||||
|
8 => HtlcState::SENT_REMOVE_REVOCATION,
|
||||||
|
9 => HtlcState::SENT_REMOVE_ACK_COMMIT,
|
||||||
|
10 => HtlcState::RCVD_REMOVE_ACK_REVOCATION,
|
||||||
|
n => panic!("Unmapped HtlcState variant: {}", n),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Amount {
|
impl<'de> Deserialize<'de> for Amount {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
|
@ -268,8 +268,10 @@ class GrpcConverterGenerator(IGenerator):
|
|||||||
mapping = {
|
mapping = {
|
||||||
'hex': f'hex::decode(i).unwrap()',
|
'hex': f'hex::decode(i).unwrap()',
|
||||||
'secret': f'i.to_vec()',
|
'secret': f'i.to_vec()',
|
||||||
|
'hash': f'i.to_vec()',
|
||||||
}.get(typ, f'i.into()')
|
}.get(typ, f'i.into()')
|
||||||
|
|
||||||
|
self.write(f"// Field: {f.path}\n", numindent=3)
|
||||||
if not f.optional:
|
if not f.optional:
|
||||||
self.write(f"{name}: c.{name}.into_iter().map(|i| {mapping}).collect(), // Rule #3 for type {typ}\n", numindent=3)
|
self.write(f"{name}: c.{name}.into_iter().map(|i| {mapping}).collect(), // Rule #3 for type {typ}\n", numindent=3)
|
||||||
else:
|
else:
|
||||||
@ -423,7 +425,8 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator):
|
|||||||
mapping = {
|
mapping = {
|
||||||
'hex': f'hex::encode(s)',
|
'hex': f'hex::encode(s)',
|
||||||
'u32': f's',
|
'u32': f's',
|
||||||
'secret': f's.try_into().unwrap()'
|
'secret': f's.try_into().unwrap()',
|
||||||
|
'hash': f'Sha256::from_slice(&s).unwrap()',
|
||||||
}.get(typ, f's.into()')
|
}.get(typ, f's.into()')
|
||||||
|
|
||||||
# TODO fix properly
|
# TODO fix properly
|
||||||
|
@ -154,9 +154,7 @@ class OverridePatch(Patch):
|
|||||||
'ListClosedChannels.closedchannels[].channel_type',
|
'ListClosedChannels.closedchannels[].channel_type',
|
||||||
'ListPeerChannels.channels[].channel_type',
|
'ListPeerChannels.channels[].channel_type',
|
||||||
'ListPeerChannels.channels[].features[]',
|
'ListPeerChannels.channels[].features[]',
|
||||||
'ListPeerChannels.channels[].htlcs[].state',
|
|
||||||
'ListPeerChannels.channels[].state_changes[]',
|
'ListPeerChannels.channels[].state_changes[]',
|
||||||
'ListPeers.peers[].channels[].htlcs[].state',
|
|
||||||
'ListPeers.peers[].channels[].state_changes[]',
|
'ListPeers.peers[].channels[].state_changes[]',
|
||||||
'ListTransactions.transactions[].type[]',
|
'ListTransactions.transactions[].type[]',
|
||||||
]
|
]
|
||||||
@ -176,6 +174,8 @@ class OverridePatch(Patch):
|
|||||||
'ListPeers.peers[].channels[].state_changes[].cause': "ChannelStateChangeCause",
|
'ListPeers.peers[].channels[].state_changes[].cause': "ChannelStateChangeCause",
|
||||||
'ListPeers.peers[].channels[].state_changes[].old_state': "ChannelState",
|
'ListPeers.peers[].channels[].state_changes[].old_state': "ChannelState",
|
||||||
'ListPeers.peers[].channels[].state_changes[].old_state': "ChannelState",
|
'ListPeers.peers[].channels[].state_changes[].old_state': "ChannelState",
|
||||||
|
'ListPeers.peers[].channels[].htlcs[].state': "HtlcState",
|
||||||
|
'ListPeerChannels.channels[].htlcs[].state': "HtlcState",
|
||||||
}
|
}
|
||||||
|
|
||||||
def visit(self, f: model.Field) -> None:
|
def visit(self, f: model.Field) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user