msggen: add multiwithdraw method

Changelog-None
This commit is contained in:
daywalker90 2024-04-17 13:09:02 +02:00 committed by Christian Decker
parent f83732f990
commit 21446c3401
9 changed files with 606 additions and 396 deletions

View file

@ -2578,6 +2578,16 @@
"multifundchannel.tx": 1, "multifundchannel.tx": 1,
"multifundchannel.txid": 2 "multifundchannel.txid": 2
}, },
"MultiwithdrawRequest": {
"MultiWithdraw.feerate": 2,
"MultiWithdraw.minconf": 3,
"MultiWithdraw.outputs[]": 1,
"MultiWithdraw.utxos[]": 4
},
"MultiwithdrawResponse": {
"MultiWithdraw.tx": 1,
"MultiWithdraw.txid": 2
},
"NewaddrRequest": { "NewaddrRequest": {
"NewAddr.addresstype": 1 "NewAddr.addresstype": 1
}, },
@ -9274,6 +9284,34 @@
"added": "pre-v0.10.1", "added": "pre-v0.10.1",
"deprecated": false "deprecated": false
}, },
"MultiWithdraw": {
"added": "pre-v0.10.1",
"deprecated": null
},
"MultiWithdraw.feerate": {
"added": "pre-v0.10.1",
"deprecated": false
},
"MultiWithdraw.minconf": {
"added": "pre-v0.10.1",
"deprecated": false
},
"MultiWithdraw.outputs[]": {
"added": "pre-v0.10.1",
"deprecated": false
},
"MultiWithdraw.tx": {
"added": "pre-v0.10.1",
"deprecated": false
},
"MultiWithdraw.txid": {
"added": "pre-v0.10.1",
"deprecated": false
},
"MultiWithdraw.utxos[]": {
"added": "pre-v0.10.1",
"deprecated": false
},
"NewAddr": { "NewAddr": {
"added": "pre-v0.10.1", "added": "pre-v0.10.1",
"deprecated": null "deprecated": null

View file

@ -77,6 +77,7 @@ service Node {
rpc ListPays(ListpaysRequest) returns (ListpaysResponse) {} rpc ListPays(ListpaysRequest) returns (ListpaysResponse) {}
rpc ListHtlcs(ListhtlcsRequest) returns (ListhtlcsResponse) {} rpc ListHtlcs(ListhtlcsRequest) returns (ListhtlcsResponse) {}
rpc MultiFundChannel(MultifundchannelRequest) returns (MultifundchannelResponse) {} rpc MultiFundChannel(MultifundchannelRequest) returns (MultifundchannelResponse) {}
rpc MultiWithdraw(MultiwithdrawRequest) returns (MultiwithdrawResponse) {}
rpc Offer(OfferRequest) returns (OfferResponse) {} rpc Offer(OfferRequest) returns (OfferResponse) {}
rpc OpenChannel_Abort(Openchannel_abortRequest) returns (Openchannel_abortResponse) {} rpc OpenChannel_Abort(Openchannel_abortRequest) returns (Openchannel_abortResponse) {}
rpc OpenChannel_Bump(Openchannel_bumpRequest) returns (Openchannel_bumpResponse) {} rpc OpenChannel_Bump(Openchannel_bumpRequest) returns (Openchannel_bumpResponse) {}
@ -2270,6 +2271,18 @@ message MultifundchannelFailedError {
string message = 2; string message = 2;
} }
message MultiwithdrawRequest {
repeated OutputDesc outputs = 1;
optional Feerate feerate = 2;
optional uint32 minconf = 3;
repeated Outpoint utxos = 4;
}
message MultiwithdrawResponse {
bytes tx = 1;
bytes txid = 2;
}
message OfferRequest { message OfferRequest {
string amount = 1; string amount = 1;
string description = 2; string description = 2;

View file

@ -2113,6 +2113,16 @@ impl From<responses::MultifundchannelResponse> for pb::MultifundchannelResponse
} }
} }
#[allow(unused_variables)]
impl From<responses::MultiwithdrawResponse> for pb::MultiwithdrawResponse {
fn from(c: responses::MultiwithdrawResponse) -> Self {
Self {
tx: hex::decode(&c.tx).unwrap(), // Rule #2 for type hex
txid: hex::decode(&c.txid).unwrap(), // Rule #2 for type txid
}
}
}
#[allow(unused_variables)] #[allow(unused_variables)]
impl From<responses::OfferResponse> for pb::OfferResponse { impl From<responses::OfferResponse> for pb::OfferResponse {
fn from(c: responses::OfferResponse) -> Self { fn from(c: responses::OfferResponse) -> Self {
@ -4737,6 +4747,20 @@ impl From<requests::MultifundchannelRequest> for pb::MultifundchannelRequest {
} }
} }
#[allow(unused_variables)]
impl From<requests::MultiwithdrawRequest> for pb::MultiwithdrawRequest {
fn from(c: requests::MultiwithdrawRequest) -> Self {
Self {
feerate: c.feerate.map(|o|o.into()), // Rule #2 for type feerate?
minconf: c.minconf, // Rule #2 for type u32?
// Field: MultiWithdraw.outputs[]
outputs: c.outputs.into_iter().map(|i| i.into()).collect(), // Rule #3 for type outputdesc
// Field: MultiWithdraw.utxos[]
utxos: c.utxos.map(|arr| arr.into_iter().map(|i| i.into()).collect()).unwrap_or(vec![]), // Rule #3
}
}
}
#[allow(unused_variables)] #[allow(unused_variables)]
impl From<requests::OfferRequest> for pb::OfferRequest { impl From<requests::OfferRequest> for pb::OfferRequest {
fn from(c: requests::OfferRequest) -> Self { fn from(c: requests::OfferRequest) -> Self {
@ -6070,6 +6094,18 @@ impl From<pb::MultifundchannelRequest> for requests::MultifundchannelRequest {
} }
} }
#[allow(unused_variables)]
impl From<pb::MultiwithdrawRequest> for requests::MultiwithdrawRequest {
fn from(c: pb::MultiwithdrawRequest) -> Self {
Self {
feerate: c.feerate.map(|a| a.into()), // Rule #1 for type feerate?
minconf: c.minconf, // Rule #1 for type u32?
outputs: c.outputs.into_iter().map(|s| s.into()).collect(), // Rule #4
utxos: Some(c.utxos.into_iter().map(|s| s.into()).collect()), // Rule #4
}
}
}
#[allow(unused_variables)] #[allow(unused_variables)]
impl From<pb::OfferRequest> for requests::OfferRequest { impl From<pb::OfferRequest> for requests::OfferRequest {
fn from(c: pb::OfferRequest) -> Self { fn from(c: pb::OfferRequest) -> Self {

View file

@ -2290,6 +2290,38 @@ impl Node for Server
} }
async fn multi_withdraw(
&self,
request: tonic::Request<pb::MultiwithdrawRequest>,
) -> Result<tonic::Response<pb::MultiwithdrawResponse>, tonic::Status> {
let req = request.into_inner();
let req: requests::MultiwithdrawRequest = req.into();
debug!("Client asked for multi_withdraw");
trace!("multi_withdraw request: {:?}", req);
let mut rpc = ClnRpc::new(&self.rpc_path)
.await
.map_err(|e| Status::new(Code::Internal, e.to_string()))?;
let result = rpc.call(Request::MultiWithdraw(req))
.await
.map_err(|e| Status::new(
Code::Unknown,
format!("Error calling method MultiWithdraw: {:?}", e)))?;
match result {
Response::MultiWithdraw(r) => {
trace!("multi_withdraw response: {:?}", r);
Ok(tonic::Response::new(r.into()))
},
r => Err(Status::new(
Code::Internal,
format!(
"Unexpected result {:?} to method call MultiWithdraw",
r
)
)),
}
}
async fn offer( async fn offer(
&self, &self,
request: tonic::Request<pb::OfferRequest>, request: tonic::Request<pb::OfferRequest>,

47
cln-rpc/src/model.rs generated
View file

@ -89,6 +89,7 @@ pub enum Request {
ListPays(requests::ListpaysRequest), ListPays(requests::ListpaysRequest),
ListHtlcs(requests::ListhtlcsRequest), ListHtlcs(requests::ListhtlcsRequest),
MultiFundChannel(requests::MultifundchannelRequest), MultiFundChannel(requests::MultifundchannelRequest),
MultiWithdraw(requests::MultiwithdrawRequest),
Offer(requests::OfferRequest), Offer(requests::OfferRequest),
OpenChannel_Abort(requests::Openchannel_abortRequest), OpenChannel_Abort(requests::Openchannel_abortRequest),
OpenChannel_Bump(requests::Openchannel_bumpRequest), OpenChannel_Bump(requests::Openchannel_bumpRequest),
@ -211,6 +212,7 @@ pub enum Response {
ListPays(responses::ListpaysResponse), ListPays(responses::ListpaysResponse),
ListHtlcs(responses::ListhtlcsResponse), ListHtlcs(responses::ListhtlcsResponse),
MultiFundChannel(responses::MultifundchannelResponse), MultiFundChannel(responses::MultifundchannelResponse),
MultiWithdraw(responses::MultiwithdrawResponse),
Offer(responses::OfferResponse), Offer(responses::OfferResponse),
OpenChannel_Abort(responses::Openchannel_abortResponse), OpenChannel_Abort(responses::Openchannel_abortResponse),
OpenChannel_Bump(responses::Openchannel_bumpResponse), OpenChannel_Bump(responses::Openchannel_bumpResponse),
@ -2738,6 +2740,34 @@ pub mod requests {
} }
} }
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MultiwithdrawRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub feerate: Option<Feerate>,
#[serde(skip_serializing_if = "Option::is_none")]
pub minconf: Option<u32>,
#[serde(skip_serializing_if = "crate::is_none_or_empty")]
pub utxos: Option<Vec<Outpoint>>,
pub outputs: Vec<OutputDesc>,
}
impl From<MultiwithdrawRequest> for Request {
fn from(r: MultiwithdrawRequest) -> Self {
Request::MultiWithdraw(r)
}
}
impl IntoRequest for MultiwithdrawRequest {
type Response = super::responses::MultiwithdrawResponse;
}
impl TypedRequest for MultiwithdrawRequest {
type Response = super::responses::MultiwithdrawResponse;
fn method(&self) -> &str {
"multiwithdraw"
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct OfferRequest { pub struct OfferRequest {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub absolute_expiry: Option<u64>, pub absolute_expiry: Option<u64>,
@ -7757,6 +7787,23 @@ pub mod responses {
} }
} }
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MultiwithdrawResponse {
pub tx: String,
pub txid: String,
}
impl TryFrom<Response> for MultiwithdrawResponse {
type Error = super::TryFromResponseError;
fn try_from(response: Response) -> Result<Self, Self::Error> {
match response {
Response::MultiWithdraw(response) => Ok(response),
_ => Err(TryFromResponseError)
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct OfferResponse { pub struct OfferResponse {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]

View file

@ -159,7 +159,7 @@ def load_jsonrpc_service():
"ListPays", "ListPays",
"ListHtlcs", "ListHtlcs",
"MultiFundChannel", "MultiFundChannel",
# "multiwithdraw", "MultiWithdraw",
"Offer", "Offer",
"OpenChannel_Abort", "OpenChannel_Abort",
"OpenChannel_Bump", "OpenChannel_Bump",

File diff suppressed because one or more lines are too long

View file

@ -359,6 +359,11 @@ class NodeStub(object):
request_serializer=node__pb2.MultifundchannelRequest.SerializeToString, request_serializer=node__pb2.MultifundchannelRequest.SerializeToString,
response_deserializer=node__pb2.MultifundchannelResponse.FromString, response_deserializer=node__pb2.MultifundchannelResponse.FromString,
) )
self.MultiWithdraw = channel.unary_unary(
'/cln.Node/MultiWithdraw',
request_serializer=node__pb2.MultiwithdrawRequest.SerializeToString,
response_deserializer=node__pb2.MultiwithdrawResponse.FromString,
)
self.Offer = channel.unary_unary( self.Offer = channel.unary_unary(
'/cln.Node/Offer', '/cln.Node/Offer',
request_serializer=node__pb2.OfferRequest.SerializeToString, request_serializer=node__pb2.OfferRequest.SerializeToString,
@ -993,6 +998,12 @@ class NodeServicer(object):
context.set_details('Method not implemented!') context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!') raise NotImplementedError('Method not implemented!')
def MultiWithdraw(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def Offer(self, request, context): def Offer(self, request, context):
"""Missing associated documentation comment in .proto file.""" """Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -1599,6 +1610,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.MultifundchannelRequest.FromString, request_deserializer=node__pb2.MultifundchannelRequest.FromString,
response_serializer=node__pb2.MultifundchannelResponse.SerializeToString, response_serializer=node__pb2.MultifundchannelResponse.SerializeToString,
), ),
'MultiWithdraw': grpc.unary_unary_rpc_method_handler(
servicer.MultiWithdraw,
request_deserializer=node__pb2.MultiwithdrawRequest.FromString,
response_serializer=node__pb2.MultiwithdrawResponse.SerializeToString,
),
'Offer': grpc.unary_unary_rpc_method_handler( 'Offer': grpc.unary_unary_rpc_method_handler(
servicer.Offer, servicer.Offer,
request_deserializer=node__pb2.OfferRequest.FromString, request_deserializer=node__pb2.OfferRequest.FromString,
@ -2997,6 +3013,23 @@ class Node(object):
options, channel_credentials, options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata) insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def MultiWithdraw(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/cln.Node/MultiWithdraw',
node__pb2.MultiwithdrawRequest.SerializeToString,
node__pb2.MultiwithdrawResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod @staticmethod
def Offer(request, def Offer(request,
target, target,

View file

@ -1686,6 +1686,13 @@ def multifundchannel2py(m):
}) })
def multiwithdraw2py(m):
return remove_default({
"tx": hexlify(m.tx), # PrimitiveField in generate_composite
"txid": hexlify(m.txid), # PrimitiveField in generate_composite
})
def offer2py(m): def offer2py(m):
return remove_default({ return remove_default({
"active": m.active, # PrimitiveField in generate_composite "active": m.active, # PrimitiveField in generate_composite