From 5d3b9786db538a6797a8b70a64e00eee075a280a Mon Sep 17 00:00:00 2001 From: Yan Mingzhi Date: Thu, 25 Jan 2024 07:48:09 +0000 Subject: [PATCH 1/4] feat: add socketio request related --- codecs/runtime-codec/proto/runtime-rpc.proto | 111 ++++-------------- codecs/runtime-codec/src/vmh/io.rs | 1 + system-actors/src/adapter/mod.rs | 21 ++++ utils/wasm-actor-utils/src/client/types.rs | 15 --- .../src/enclave/actors/adapter.rs | 8 ++ 5 files changed, 51 insertions(+), 105 deletions(-) diff --git a/codecs/runtime-codec/proto/runtime-rpc.proto b/codecs/runtime-codec/proto/runtime-rpc.proto index 11a96eda..2bae21e8 100644 --- a/codecs/runtime-codec/proto/runtime-rpc.proto +++ b/codecs/runtime-codec/proto/runtime-rpc.proto @@ -7,45 +7,38 @@ message AdapterServerRequest { string uuid = 1; oneof msg { AdapterHttpRequest AdapterHttpRequest = 2; - CheckValidRsaPubKeyRequest CheckValidRsaPubKeyRequest = 3; - DataUploadCompletedRequest DataUploadCompletedRequest = 4; - IpfsInboundP2pForwardRequest IpfsInboundP2pForwardRequest = 5; - IpfsP2pForwardResponse IpfsP2pForwardResponse = 6; - IpfsBlockGetResponse IpfsBlockGetResponse = 7; + AdapterSocketioHttpRequest AdapterSocketioHttpRequest = 3; } } -message AdapterServerResponse { +message HttpGeneralRequest { + uint64 seqNumber = 1; oneof msg { - CheckValidRsaPubKeyResponse CheckValidRsaPubKeyResponse = 1; - IpfsInboundP2pForwardResponse IpfsInboundP2pForwardResponse = 2; + HttpExecutionRequest HttpExecutionRequest = 6; + UpgradeVersionRequest UpgradeVersionRequest = 7; + ImportRequest ImportRequest = 8; } } -message AdapterClientRequest { - uint64 seqNumber = 1; +message SocketioClientRequest { oneof msg { - IpfsBlockGetRequest IpfsBlockGetRequest = 2; - IpfsInfoRequest IpfsInfoRequest = 3; - IpfsP2pFrowardRequest IpfsP2pFrowardRequest = 4; - IpfsP2pCloseRequest IpfsP2pCloseRequest = 5; - IpfsPullCidDataRequest IpfsPullCidDataRequest = 6; + SocketioHttpRequest SocketioHttpRequest = 4; } } -message AdapterClientResponse { +message SocketioClientResponse { oneof msg { - IpfsInfoResponse IpfsInfoResponse = 1; + HttpExecutionResponse HttpExecutionResponse = 5; + HttpExecutionError HttpExecutionError = 6; } } -message HttpGeneralRequest { - uint64 seqNumber = 1; - oneof msg { - HttpExecutionRequest HttpExecutionRequest = 6; - UpgradeVersionRequest UpgradeVersionRequest = 7; - ImportRequest ImportRequest = 8; - } +message SocketioHttpRequest { + string action = 1; + repeated HttpExecutionHeader headers = 2; + HttpExecutionTimeout timeout = 3; + string method = 4; + HttpExecutionPayload payload = 5; } message HttpExecutionRequest { @@ -101,76 +94,14 @@ message HttpExecutionError { string errorMessage = 1; } -message IpfsInfoRequest { - string peerId = 1; -} - -message IpfsInfoResponse { - string id = 1; - string publicKey = 2; - repeated string addresses = 3; - string agentVersion = 4; - string protocolVersion = 5; -} - -message IpfsP2pFrowardRequest { - string peerId = 1; - string reply = 2; - p2p.GeneralMsg p2pGeneralMsg = 3; -} - -message IpfsP2pCloseRequest { - string peerId = 1; -} - -message IpfsPullCidDataRequest { - string peerId = 1; - string reply = 2; - bytes payload = 3; - bool pin = 4; - string cid = 5; -} - -message IpfsBlockGetRequest { - string cid = 1; - string reply = 2; - bool waitLocally = 3; - bool returnIfNotExist = 4; -} - message AdapterHttpRequest { string action = 2; bytes payload = 3; string actor = 4; } -message CheckValidRsaPubKeyRequest { - string rsaPub = 1; -} - -message CheckValidRsaPubKeyResponse { - bytes result = 1; -} - -message DataUploadCompletedRequest { - bytes payload = 1; -} - -message IpfsInboundP2pForwardRequest { - string peerId = 1; - p2p.GeneralMsg p2pGeneralMsg = 2; -} - -message IpfsInboundP2pForwardResponse { - p2p.P2pReplyMessage P2pReplyMessage = 1; -} - -message IpfsP2pForwardResponse { - p2p.P2pReplyMessage P2pReplyMessage = 1; -} - -message IpfsBlockGetResponse { - string cid = 1; - string reply = 2; +message AdapterSocketioHttpRequest { + string action = 2; bytes payload = 3; -} + string actor = 4; +} \ No newline at end of file diff --git a/codecs/runtime-codec/src/vmh/io.rs b/codecs/runtime-codec/src/vmh/io.rs index 094e60e8..41af0df0 100644 --- a/codecs/runtime-codec/src/vmh/io.rs +++ b/codecs/runtime-codec/src/vmh/io.rs @@ -32,6 +32,7 @@ pub enum RegistryKey { IpfsOutbound, AdapterInbound, + AdapterOutbond, HttpOutbound, HttpProxy, diff --git a/system-actors/src/adapter/mod.rs b/system-actors/src/adapter/mod.rs index ac2a4c0d..79566baa 100644 --- a/system-actors/src/adapter/mod.rs +++ b/system-actors/src/adapter/mod.rs @@ -15,6 +15,12 @@ pub struct InternalHttpRequest(pub Vec); #[response(())] pub struct RegisterHttp(pub Vec); +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] +#[price(10000)] +#[response(())] +pub struct RegisterSocketio(pub Vec); + #[doc(hidden)] #[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] #[price(10000)] @@ -24,6 +30,21 @@ pub struct HttpRequest { pub payload: Vec, } +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] +#[price(10000)] +#[response(Vec)] +pub struct SocketioRequest { + pub action: String, + pub payload: Vec, +} + +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] +#[price(10000)] +#[response(Vec)] +pub struct SocketioClientRequest(pub Vec); + #[doc(hidden)] #[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] #[price(10000)] diff --git a/utils/wasm-actor-utils/src/client/types.rs b/utils/wasm-actor-utils/src/client/types.rs index 6c6df148..714a0762 100644 --- a/utils/wasm-actor-utils/src/client/types.rs +++ b/utils/wasm-actor-utils/src/client/types.rs @@ -1,24 +1,9 @@ use crate::client::api; use crate::client::error::Result; -use crate::client::help; -use crate::client::request::uuid_cb_key; use crate::client::txn_cache; pub use crate::enclave::action::HttpRequest; use futures::Future; use std::pin::Pin; -use tea_actorx::IntoActor; - -use serde::{Deserialize, Serialize}; -use tea_codec::serde::TypeId; - -// #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] -// #[response(Vec)] -// pub struct ClientTxnCbRequest { -// pub action: String, -// pub payload: Vec, -// pub from_actor: String, -// pub uuid: String, -// } type CBD = Pin>> + Send>>; pub type CallbackCB = dyn Fn(Vec, String) -> CBD + Sync + Send + 'static; diff --git a/utils/wasm-actor-utils/src/enclave/actors/adapter.rs b/utils/wasm-actor-utils/src/enclave/actors/adapter.rs index a8bc3ff7..22cb3640 100644 --- a/utils/wasm-actor-utils/src/enclave/actors/adapter.rs +++ b/utils/wasm-actor-utils/src/enclave/actors/adapter.rs @@ -7,3 +7,11 @@ pub async fn register_adapter_http_dispatcher(actions: Vec) -> Result<() ActorId::Static(NAME).call(RegisterHttp(actions)).await?; Ok(()) } + +#[doc(hidden)] +pub async fn register_adapter_socketio_dispatcher(actions: Vec) -> Result<()> { + ActorId::Static(NAME) + .call(RegisterSocketio(actions)) + .await?; + Ok(()) +} From 75246132ed6f313188fde2b5951a5530e0bd728b Mon Sep 17 00:00:00 2001 From: "Jacky.li" Date: Sun, 28 Jan 2024 17:55:37 +0800 Subject: [PATCH 2/4] add airdrop tasks --- codecs/runtime-codec/proto/actor-tappstore.proto | 4 ++++ codecs/runtime-codec/src/tapp/fluencer.rs | 14 ++++++++++++++ system-actors/src/tappstore/txns.rs | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/codecs/runtime-codec/proto/actor-tappstore.proto b/codecs/runtime-codec/proto/actor-tappstore.proto index 453bda12..f270ccd4 100644 --- a/codecs/runtime-codec/proto/actor-tappstore.proto +++ b/codecs/runtime-codec/proto/actor-tappstore.proto @@ -82,6 +82,7 @@ message CommonSqlQueryRequest { QueryDevTappItemByNameRequest QueryDevTappItemByNameRequest = 15; QueryDevTappErrorLog QueryDevTappErrorLog = 16; QueryReferenceRewardAccountRequest QueryReferenceRewardAccountRequest = 17; + QueryAirdropTaskRequest QueryAirdropTaskRequest = 18; } } @@ -132,6 +133,9 @@ message QueryDevTappErrorLog { message QueryReferenceRewardAccountRequest { string acct = 1; } +message QueryAirdropTaskRequest { + string acct = 1; +} message CommonSqlQueryResponse { bytes data = 1; diff --git a/codecs/runtime-codec/src/tapp/fluencer.rs b/codecs/runtime-codec/src/tapp/fluencer.rs index 0c35c618..8fb7a782 100644 --- a/codecs/runtime-codec/src/tapp/fluencer.rs +++ b/codecs/runtime-codec/src/tapp/fluencer.rs @@ -1,3 +1,4 @@ +use crate::tapp::{Account, Balance, TokenId}; use serde::{Deserialize, Serialize}; #[doc(hidden)] @@ -18,3 +19,16 @@ pub struct CreditSystemInfo { pub end_time: String, pub status: String, } + +#[doc(hidden)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] +pub struct AirdropTaskInfo { + pub id: String, + pub token_id: TokenId, + pub owner: Account, + pub name: String, + pub reward_type: String, + pub reward_text: String, + pub r#type: String, + pub balance: Option, +} diff --git a/system-actors/src/tappstore/txns.rs b/system-actors/src/tappstore/txns.rs index 874c7a7f..9ff9cee5 100644 --- a/system-actors/src/tappstore/txns.rs +++ b/system-actors/src/tappstore/txns.rs @@ -383,6 +383,18 @@ pub enum TappstoreTxn { acct: Account, amt: Balance, }, + AirdropAddTask { + token_id: TokenId, + owner: Account, + name: String, + task_type: String, + reward_type: String, + reward_text: String, + }, + AirdropRemoveTask { + token_id: TokenId, + owner: Account, + }, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] From 22bccb1010939f5bf9f8a40f9190701e185af62b Mon Sep 17 00:00:00 2001 From: "Jacky.li" Date: Wed, 31 Jan 2024 15:41:52 +0800 Subject: [PATCH 3/4] update for test --- .../proto/tokenstate-provider.proto | 10 +++++++ system-actors/src/tappstore/txns.rs | 14 ++++++++++ system-actors/src/tokenstate/mod.rs | 9 +++++++ utils/wasm-actor-utils/src/client/help.rs | 7 +++++ .../src/enclave/actors/tokenstate.rs | 27 +++++++++++++++++++ utils/wasm-actor-utils/src/enclave/error.rs | 3 +++ 6 files changed, 70 insertions(+) diff --git a/codecs/runtime-codec/proto/tokenstate-provider.proto b/codecs/runtime-codec/proto/tokenstate-provider.proto index 10001d36..18c35838 100644 --- a/codecs/runtime-codec/proto/tokenstate-provider.proto +++ b/codecs/runtime-codec/proto/tokenstate-provider.proto @@ -464,6 +464,16 @@ message BondingMintResponse { bytes ctx = 1; } +message BondingTransferRequest { + bytes ctx = 1; + bytes from = 2; + bytes to = 3; + bytes amount = 4; +} +message BondingTransferResponse { + bytes ctx = 1; +} + message BondingBurnRequest { bytes ctx = 1; bytes account = 2; diff --git a/system-actors/src/tappstore/txns.rs b/system-actors/src/tappstore/txns.rs index 9ff9cee5..69f0f2f8 100644 --- a/system-actors/src/tappstore/txns.rs +++ b/system-actors/src/tappstore/txns.rs @@ -395,6 +395,20 @@ pub enum TappstoreTxn { token_id: TokenId, owner: Account, }, + AirdropLoadTokenWithCredit { + token_id: TokenId, + from: Account, + }, + AirdropLoadToken { + token_id: TokenId, + from: Account, + token_amount: Balance, + }, + AirdropUnloadToken { + token_id: TokenId, + to: Account, + token_amount: Balance, + }, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] diff --git a/system-actors/src/tokenstate/mod.rs b/system-actors/src/tokenstate/mod.rs index ea831afa..839eda31 100644 --- a/system-actors/src/tokenstate/mod.rs +++ b/system-actors/src/tokenstate/mod.rs @@ -700,6 +700,15 @@ pub struct BondingMintRequest(pub Vec); #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] pub struct BondingMintResponse(pub Vec); +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] +#[price(10000)] +pub struct BondingTransferRequest(pub Vec); + +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId)] +pub struct BondingTransferResponse(pub Vec); + #[doc(hidden)] #[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] #[price(10000)] diff --git a/utils/wasm-actor-utils/src/client/help.rs b/utils/wasm-actor-utils/src/client/help.rs index e79aa4b8..51b17e0c 100644 --- a/utils/wasm-actor-utils/src/client/help.rs +++ b/utils/wasm-actor-utils/src/client/help.rs @@ -2,6 +2,7 @@ use crate::client::{Errors, Result}; use crate::enclave::actors::kvp; use serde::Serialize; use tea_codec::OptionExt; +use tea_runtime_codec::tapp::Balance; /// Set a cache value for 1800 senond. pub async fn set_mem_cache(key: &str, val: Vec) -> Result<()> { @@ -130,3 +131,9 @@ pub async fn remove_query_cache(key: &str) -> Result<()> { kvp::del(&key).await?; Ok(()) } + +pub fn string_to_balance(balance_str: &str) -> Result { + let balance = Balance::from_str_radix(&balance_str, 10) + .map_err(|_| Errors::Unnamed(format!("Balance_string parse error.")))?; + Ok(balance) +} diff --git a/utils/wasm-actor-utils/src/enclave/actors/tokenstate.rs b/utils/wasm-actor-utils/src/enclave/actors/tokenstate.rs index 4cb37f70..c7fb7380 100644 --- a/utils/wasm-actor-utils/src/enclave/actors/tokenstate.rs +++ b/utils/wasm-actor-utils/src/enclave/actors/tokenstate.rs @@ -191,6 +191,33 @@ pub async fn mov(from: Account, to: Account, amt: Balance, ctx: Vec) -> Resu Ok(res.0) } +pub async fn mov_token(from: Account, to: Account, amt: Balance, ctx: Vec) -> Result> { + if amt.is_zero() { + info!("Mov 0 unit, ignored."); + return Ok(ctx); + } + + let req = tokenstate::BondingTransferRequest { + from: serialize(&from)?, + to: serialize(&to)?, + amount: serialize(&amt)?, + ctx, + }; + + let res = ActorId::Static(NAME) + .call(BondingTransferRequest(encode_protobuf(req)?)) + .await + .map_err(|e| { + Errors::StateMachineBondingMoveFailed( + from.to_string(), + to.to_string(), + amt, + e.to_string(), + ) + })?; + Ok(res.0) +} + /// Move TEA value from one token_id balance to another token_id balance. /// Most likely a move between TAppStore balance and a TAppToken balance due to buying/selling a token. pub async fn cross_move( diff --git a/utils/wasm-actor-utils/src/enclave/error.rs b/utils/wasm-actor-utils/src/enclave/error.rs index 4928753e..c5bb2a34 100644 --- a/utils/wasm-actor-utils/src/enclave/error.rs +++ b/utils/wasm-actor-utils/src/enclave/error.rs @@ -118,6 +118,9 @@ pub enum Errors { #[error("Actor_statemachine move {0} to {1} with amount {2} failed: {3}")] StateMachineMoveFailed(String, String, Balance, String), + #[error("Actor_statemachine bonding_move {0} to {1} with amount {2} failed: {3}")] + StateMachineBondingMoveFailed(String, String, Balance, String), + #[error("Actor_statemachine cross_move failed. From token_id {0} account {1} to token_id {2} account {3} with amount {4}. Reason: {5}")] StateMachineCrossMoveFailed(String, String, String, String, Balance, String), From 597196a16e1dec8db9d0522b6a3aa073d8830cdf Mon Sep 17 00:00:00 2001 From: "Jacky.li" Date: Sun, 4 Feb 2024 15:45:55 +0800 Subject: [PATCH 4/4] update struct --- codecs/runtime-codec/src/tapp/fluencer.rs | 1 + system-actors/src/tappstore/txns.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/codecs/runtime-codec/src/tapp/fluencer.rs b/codecs/runtime-codec/src/tapp/fluencer.rs index 8fb7a782..c72fc566 100644 --- a/codecs/runtime-codec/src/tapp/fluencer.rs +++ b/codecs/runtime-codec/src/tapp/fluencer.rs @@ -31,4 +31,5 @@ pub struct AirdropTaskInfo { pub reward_text: String, pub r#type: String, pub balance: Option, + pub description: String, } diff --git a/system-actors/src/tappstore/txns.rs b/system-actors/src/tappstore/txns.rs index 69f0f2f8..7156f697 100644 --- a/system-actors/src/tappstore/txns.rs +++ b/system-actors/src/tappstore/txns.rs @@ -390,6 +390,7 @@ pub enum TappstoreTxn { task_type: String, reward_type: String, reward_text: String, + description: String, }, AirdropRemoveTask { token_id: TokenId,