diff --git a/codecs/runtime-codec/src/tapp/entity.rs b/codecs/runtime-codec/src/tapp/entity.rs index 4590118..dcecd05 100644 --- a/codecs/runtime-codec/src/tapp/entity.rs +++ b/codecs/runtime-codec/src/tapp/entity.rs @@ -20,5 +20,5 @@ pub struct EntitySettings { pub init_amount: Balance, pub hosting_amount: Balance, pub cml_id: Option, - pub from_token_id: Option, + // pub from_token_id: Option, } diff --git a/system-actors/src/payment_channel/mod.rs b/system-actors/src/payment_channel/mod.rs index 4459b05..1410fdf 100644 --- a/system-actors/src/payment_channel/mod.rs +++ b/system-actors/src/payment_channel/mod.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; use tea_codec::serde::TypeId; -use tea_runtime_codec::tapp::{Account, PaymentInfo}; +use tea_runtime_codec::tapp::{Account, ChannelId, PaymentInfo}; pub mod error; pub mod txns; @@ -9,10 +9,19 @@ pub const NAME: &[u8] = b"com.tea.payment-channel-actor"; #[doc(hidden)] #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] -pub struct QueryChannelInfoRequest(pub Account); +pub struct QueryChannelInfoRequest(pub Account, pub Option); #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] pub struct QueryChannelInfoResponse { pub payer_list: Vec, pub payee_list: Vec, } + +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId)] +pub struct QueryChannelWithChannelIdRequest(pub Vec); + +#[derive(Debug, Clone, Serialize, Deserialize, TypeId)] +pub struct QueryChannelWithChannelIdResponse { + pub list: Vec, +} diff --git a/system-actors/src/tokenstate/mod.rs b/system-actors/src/tokenstate/mod.rs index 839eda3..a86df1a 100644 --- a/system-actors/src/tokenstate/mod.rs +++ b/system-actors/src/tokenstate/mod.rs @@ -297,6 +297,7 @@ pub struct ListPaymentChannelsResponse { pub struct QueryPaymentChannelListWithAccountRequest { pub token_id: TokenId, pub acct: Account, + pub expire_time: Option, } #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] @@ -305,6 +306,19 @@ pub struct QueryPaymentChannelListWithAccountResponse { pub payee_list: Vec, } +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] +#[price(1000000)] +pub struct QueryPaymentChannelListWithChannelIdListRequest { + pub token_id: TokenId, + pub channel_id_list: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, TypeId)] +pub struct QueryPaymentChannelListWithChannelIdListResponse { + pub list: Vec, +} + #[doc(hidden)] #[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] #[price(1000000)] diff --git a/utils/wasm-actor-utils/src/client/api/channel.rs b/utils/wasm-actor-utils/src/client/api/channel.rs index 39a23dd..4cdd3ff 100644 --- a/utils/wasm-actor-utils/src/client/api/channel.rs +++ b/utils/wasm-actor-utils/src/client/api/channel.rs @@ -8,7 +8,7 @@ use prost::Message; use serde::{Deserialize, Serialize}; use serde_json::json; use tea_actorx::ActorId; -use tea_runtime_codec::tapp::{Account, Balance, ChannelItem, ChannelItemStatus}; +use tea_runtime_codec::tapp::{Account, Balance, ChannelId, ChannelItem, ChannelItemStatus}; use tea_sdk::IntoGlobal; use tea_system_actors::payment_channel::{ txns::PaymentChannelTxn, QueryChannelInfoRequest, QueryChannelInfoResponse, NAME, @@ -88,6 +88,17 @@ pub struct QueryChannelListWithAccountRequest { pub address: String, pub tapp_id_b64: String, pub auth_b64: String, + pub expire_time: Option, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct QueryChannelListWithChannelIdRequest { + pub uuid: String, + pub address: String, + pub tapp_id_b64: String, + pub auth_b64: String, + pub channel_id: Vec, } pub async fn open_payment_channel(payload: Vec, from_actor: String) -> Result> { @@ -231,8 +242,18 @@ pub async fn query_channel_list_with_account( let token_id = tapp_payment_channel_token_id()?; let acct = req.address.parse()?; + let expire_time: Option = if req.expire_time.is_some() { + let val = u128::from_str_radix(&req.expire_time.unwrap(), 10)?; + Some(val) + } else { + None + }; let res = ActorId::Static(tokenstate::NAME) - .call(tokenstate::QueryPaymentChannelListWithAccountRequest { acct, token_id }) + .call(tokenstate::QueryPaymentChannelListWithAccountRequest { + acct, + token_id, + expire_time, + }) .await?; let latest_tsid = statemachine::query_state_tsid().await?; @@ -251,6 +272,46 @@ pub async fn query_channel_list_with_account( help::result_ok() } +pub async fn query_channel_list_with_channel_id( + payload: Vec, + _from_actor: String, +) -> Result> { + let req: QueryChannelListWithChannelIdRequest = serde_json::from_slice(&payload)?; + // check_auth(&req.tapp_id_b64, &req.address, &req.auth_b64).await?; + + info!("query_channel_list_with_channel_id from local_state ..."); + let uuid = req.uuid; + + let token_id = tapp_payment_channel_token_id()?; + let mut channel_id_list: Vec = Vec::new(); + for id_str in req.channel_id { + let id = id_str.parse()?; + channel_id_list.push(id); + } + let res = ActorId::Static(tokenstate::NAME) + .call( + tokenstate::QueryPaymentChannelListWithChannelIdListRequest { + token_id, + channel_id_list, + }, + ) + .await?; + let latest_tsid = statemachine::query_state_tsid().await?; + + let x = serde_json::json!({ + "list": res.list, + "ts": latest_tsid.ts.to_string(), + }); + info!( + "query query_channel_list_with_channel_id from local_state => {:?}", + x + ); + + help::cache_json_with_uuid(&uuid, x).await?; + + help::result_ok() +} + pub async fn payee_update_payment(payload: Vec, from_actor: String) -> Result> { let req: PayeeUpdatePaymentRequest = serde_json::from_slice(&payload)?; // check_auth(&req.tapp_id_b64, &req.address, &req.auth_b64).await?; diff --git a/utils/wasm-actor-utils/src/client/types.rs b/utils/wasm-actor-utils/src/client/types.rs index 714a076..c455a33 100644 --- a/utils/wasm-actor-utils/src/client/types.rs +++ b/utils/wasm-actor-utils/src/client/types.rs @@ -40,6 +40,9 @@ pub async fn map_handler(action: &str, arg: Vec, from_actor: String) -> Resu "query_channel_list_with_account" => { api::channel::query_channel_list_with_account(arg, from_actor).await? } + "query_channel_list_with_channel_id" => { + api::channel::query_channel_list_with_channel_id(arg, from_actor).await? + } "payee_update_payment" => api::channel::payee_update_payment(arg, from_actor).await?, _ => vec![], @@ -103,6 +106,7 @@ pub fn map_fn_list() -> Vec<&'static str> { "terminate", "payer_refill_fund", "query_channel_list_with_account", + "query_channel_list_with_channel_id", "payee_update_payment", ] }