Skip to content

Commit

Permalink
Merge pull request #12 from tearust/airdrop
Browse files Browse the repository at this point in the history
Airdrop
  • Loading branch information
liyangwood authored Feb 6, 2024
2 parents 3e1a608 + 597196a commit 9de19b1
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 105 deletions.
4 changes: 4 additions & 0 deletions codecs/runtime-codec/proto/actor-tappstore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ message CommonSqlQueryRequest {
QueryDevTappItemByNameRequest QueryDevTappItemByNameRequest = 15;
QueryDevTappErrorLog QueryDevTappErrorLog = 16;
QueryReferenceRewardAccountRequest QueryReferenceRewardAccountRequest = 17;
QueryAirdropTaskRequest QueryAirdropTaskRequest = 18;
}
}

Expand Down Expand Up @@ -132,6 +133,9 @@ message QueryDevTappErrorLog {
message QueryReferenceRewardAccountRequest {
string acct = 1;
}
message QueryAirdropTaskRequest {
string acct = 1;
}

message CommonSqlQueryResponse {
bytes data = 1;
Expand Down
111 changes: 21 additions & 90 deletions codecs/runtime-codec/proto/runtime-rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions codecs/runtime-codec/proto/tokenstate-provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions codecs/runtime-codec/src/tapp/fluencer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::tapp::{Account, Balance, TokenId};
use serde::{Deserialize, Serialize};

#[doc(hidden)]
Expand All @@ -18,3 +19,17 @@ 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<Balance>,
pub description: String,
}
1 change: 1 addition & 0 deletions codecs/runtime-codec/src/vmh/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum RegistryKey {
IpfsOutbound,

AdapterInbound,
AdapterOutbond,

HttpOutbound,
HttpProxy,
Expand Down
21 changes: 21 additions & 0 deletions system-actors/src/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub struct InternalHttpRequest(pub Vec<u8>);
#[response(())]
pub struct RegisterHttp(pub Vec<String>);

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(())]
pub struct RegisterSocketio(pub Vec<String>);

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
Expand All @@ -24,6 +30,21 @@ pub struct HttpRequest {
pub payload: Vec<u8>,
}

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(Vec<u8>)]
pub struct SocketioRequest {
pub action: String,
pub payload: Vec<u8>,
}

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
#[response(Vec<u8>)]
pub struct SocketioClientRequest(pub Vec<u8>);

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
Expand Down
27 changes: 27 additions & 0 deletions system-actors/src/tappstore/txns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,33 @@ pub enum TappstoreTxn {
acct: Account,
amt: Balance,
},
AirdropAddTask {
token_id: TokenId,
owner: Account,
name: String,
task_type: String,
reward_type: String,
reward_text: String,
description: String,
},
AirdropRemoveTask {
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)]
Expand Down
9 changes: 9 additions & 0 deletions system-actors/src/tokenstate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,15 @@ pub struct BondingMintRequest(pub Vec<u8>);
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct BondingMintResponse(pub Vec<u8>);

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
pub struct BondingTransferRequest(pub Vec<u8>);

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId)]
pub struct BondingTransferResponse(pub Vec<u8>);

#[doc(hidden)]
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)]
#[price(10000)]
Expand Down
7 changes: 7 additions & 0 deletions utils/wasm-actor-utils/src/client/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> Result<()> {
Expand Down Expand Up @@ -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<Balance> {
let balance = Balance::from_str_radix(&balance_str, 10)
.map_err(|_| Errors::Unnamed(format!("Balance_string parse error.")))?;
Ok(balance)
}
15 changes: 0 additions & 15 deletions utils/wasm-actor-utils/src/client/types.rs
Original file line number Diff line number Diff line change
@@ -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<u8>)]
// pub struct ClientTxnCbRequest {
// pub action: String,
// pub payload: Vec<u8>,
// pub from_actor: String,
// pub uuid: String,
// }

type CBD = Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send>>;
pub type CallbackCB = dyn Fn(Vec<u8>, String) -> CBD + Sync + Send + 'static;
Expand Down
8 changes: 8 additions & 0 deletions utils/wasm-actor-utils/src/enclave/actors/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ pub async fn register_adapter_http_dispatcher(actions: Vec<String>) -> Result<()
ActorId::Static(NAME).call(RegisterHttp(actions)).await?;
Ok(())
}

#[doc(hidden)]
pub async fn register_adapter_socketio_dispatcher(actions: Vec<String>) -> Result<()> {
ActorId::Static(NAME)
.call(RegisterSocketio(actions))
.await?;
Ok(())
}
27 changes: 27 additions & 0 deletions utils/wasm-actor-utils/src/enclave/actors/tokenstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,33 @@ pub async fn mov(from: Account, to: Account, amt: Balance, ctx: Vec<u8>) -> Resu
Ok(res.0)
}

pub async fn mov_token(from: Account, to: Account, amt: Balance, ctx: Vec<u8>) -> Result<Vec<u8>> {
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(
Expand Down
3 changes: 3 additions & 0 deletions utils/wasm-actor-utils/src/enclave/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down

0 comments on commit 9de19b1

Please sign in to comment.