From 55f858eea274f075f6002cd972aa24f058c5f6b9 Mon Sep 17 00:00:00 2001 From: liyukun Date: Thu, 16 Nov 2023 21:14:31 +0800 Subject: [PATCH] chore: reuse old channel params --- src/transaction.rs | 25 ++++++++++--------------- tests/transaction.rs | 1 - 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/transaction.rs b/src/transaction.rs index 2b9b1be..f5f87d9 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -1,4 +1,4 @@ -use anyhow::{ensure, Context, Result}; +use anyhow::{anyhow, ensure, Context, Result}; use ckb_ics_axon::{ get_channel_id_str, handler::{IbcPacket, PacketStatus}, @@ -219,7 +219,6 @@ pub fn assemble_consume_ack_packet_partial_transaction( pub fn assemble_channel_close_init_partial_transaction( axon_metadata_cell_dep: packed::CellDep, channel_contract_cell_dep: packed::CellDep, - config: &Config, channel: IbcChannelCell, ) -> Result<(TransactionBuilder, Envelope)> { ensure!(channel.channel.state != State::Closed); @@ -234,19 +233,15 @@ pub fn assemble_channel_close_init_partial_transaction( .output_type(Some(new_channel_bytes.clone()).pack()) .build(); - let client_id: [u8; 32] = config - .axon_metadata_type_script() - .args() - .raw_data() - .to_vec() - .as_slice() - .try_into()?; - let new_channel_script_args = ChannelArgs { - client_id, - open: false, - channel_id: new_channel.number, - port_id: config.port_id(), - }; + let old_channel_lock = packed::Script::from(channel.output.lock.clone()); + let old_channel_script_args = + ChannelArgs::from_slice(&old_channel_lock.args().raw_data().to_vec()) + .map_err(|_| anyhow!("incompatible channel args"))?; + if !old_channel_script_args.open { + return Err(anyhow!("channel is already closed")); + } + let mut new_channel_script_args = old_channel_script_args; + new_channel_script_args.open = false; let new_channel_script = packed::Script::from(channel.output.lock.clone()) .as_builder() .args(new_channel_script_args.to_args().pack()) diff --git a/tests/transaction.rs b/tests/transaction.rs index 3cd2bb3..21a0003 100644 --- a/tests/transaction.rs +++ b/tests/transaction.rs @@ -423,7 +423,6 @@ fn test_channel_close_init() -> Result<()> { let (tx, envelope) = assemble_channel_close_init_partial_transaction( axon_metadata_cell_dep, channel_contract_cell_dep, - &config, channel_cell, )?; let tx = tx.input(