diff --git a/core/ic/src/tera/src/api/nonce.rs b/core/ic/src/tera/src/api/nonce.rs index 6abdbc09..53774ab5 100644 --- a/core/ic/src/tera/src/api/nonce.rs +++ b/core/ic/src/tera/src/api/nonce.rs @@ -9,3 +9,9 @@ use crate::{common::types::Nonce, tera::STATE}; fn get_nonces() -> Vec { STATE.with(|s| s.get_nonces()) } + +#[query(name = "nonce_exist")] +#[candid_method(query, rename = "nonce_exist")] +fn nonce_exist(nonce: Nonce) -> bool { + STATE.with(|s| s.nonce_exists(&nonce)) +} diff --git a/core/ic/src/tera/tera.did b/core/ic/src/tera/tera.did index 7dc415d5..b8496443 100644 --- a/core/ic/src/tera/tera.did +++ b/core/ic/src/tera/tera.did @@ -10,6 +10,7 @@ service : { get_messages : () -> (vec OutgoingMessagePair); get_messages_count : () -> (nat32) query; get_nonces : () -> (vec nat) query; + nonce_exist : (nat) -> (bool) query; remove_messages : (vec OutgoingMessagePair) -> (ConsumeMessageResponse); send_message : (principal, vec nat) -> (SendMessageResponse); store_message : (principal, principal, nat, vec nat) -> ( diff --git a/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did b/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did index 419c1a48..df9c30fc 100644 --- a/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did +++ b/magic_bridge/ic/src/dip20_proxy/dip20_proxy.did @@ -7,6 +7,7 @@ type ClaimableMessage = record { amount : nat; token_name : text; }; +type MessageStatus = variant { ConsumedNotMinted; Consuming }; type OperationFailure = variant { SendMessage : opt TxError; Burn : opt TxError; @@ -40,6 +41,7 @@ service : { get_all_token_balance : () -> (Result_1); get_balance : (principal, principal, nat) -> (opt nat); handle_message : (principal, nat, vec nat) -> (Result_2); + message_exist : (text) -> (opt MessageStatus) query; mint : (principal, nat, vec nat) -> (Result_2); perform_handshake : () -> (Result_3); remove_claimable : (principal, principal, nat) -> (Result_4); diff --git a/magic_bridge/ic/src/dip20_proxy/src/api/burn.rs b/magic_bridge/ic/src/dip20_proxy/src/api/burn.rs index 7aeb1774..1874a644 100644 --- a/magic_bridge/ic/src/dip20_proxy/src/api/burn.rs +++ b/magic_bridge/ic/src/dip20_proxy/src/api/burn.rs @@ -92,7 +92,7 @@ async fn burn( }); insert_claimable_asset(ClaimableMessage { - from: caller, + from: Some(caller), owner: eth_addr.clone(), msg_hash: outgoing_message.msg_hash.clone(), msg_key: Some(outgoing_message.msg_key.clone()), diff --git a/magic_bridge/ic/src/dip20_proxy/src/api/messages.rs b/magic_bridge/ic/src/dip20_proxy/src/api/messages.rs new file mode 100644 index 00000000..ea9b1810 --- /dev/null +++ b/magic_bridge/ic/src/dip20_proxy/src/api/messages.rs @@ -0,0 +1,10 @@ +use candid::candid_method; +use ic_cdk_macros::query; + +use crate::{common::types::MessageStatus, proxy::STATE}; + +#[query(name = "message_exist")] +#[candid_method(query, rename = "message_exist")] +fn message_exist(msg_hash: String) -> Option { + STATE.with(|s| s.get_message(&msg_hash)) +} diff --git a/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs b/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs index 1949045a..515c85a9 100644 --- a/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs +++ b/magic_bridge/ic/src/dip20_proxy/src/api/mod.rs @@ -5,6 +5,7 @@ mod claimable_assets; mod get_balance; mod handle_message; mod init; +mod messages; mod mint; mod upgrade; mod withdraw; diff --git a/magic_bridge/ic/src/dip20_proxy/src/api/withdraw.rs b/magic_bridge/ic/src/dip20_proxy/src/api/withdraw.rs index 68522608..c2dce532 100644 --- a/magic_bridge/ic/src/dip20_proxy/src/api/withdraw.rs +++ b/magic_bridge/ic/src/dip20_proxy/src/api/withdraw.rs @@ -77,7 +77,7 @@ pub async fn withdraw( }); insert_claimable_asset(ClaimableMessage { - from: caller, + from: Some(caller), owner: eth_addr.clone(), msg_hash: outgoing_message.msg_hash.clone(), msg_key: Some(outgoing_message.msg_key.clone()), diff --git a/magic_bridge/ic/src/dip20_proxy/src/common/types.rs b/magic_bridge/ic/src/dip20_proxy/src/common/types.rs index 6f2f21fc..78047c39 100644 --- a/magic_bridge/ic/src/dip20_proxy/src/common/types.rs +++ b/magic_bridge/ic/src/dip20_proxy/src/common/types.rs @@ -75,7 +75,7 @@ pub struct ClaimableMessage { pub token_name: String, pub token: TokenId, pub amount: Nat, - pub from: Principal, + pub from: Option, } #[derive(CandidType, Deserialize, Default)] diff --git a/magic_bridge/ic/src/dip20_proxy/src/proxy.rs b/magic_bridge/ic/src/dip20_proxy/src/proxy.rs index cb32f57b..2066643f 100644 --- a/magic_bridge/ic/src/dip20_proxy/src/proxy.rs +++ b/magic_bridge/ic/src/dip20_proxy/src/proxy.rs @@ -288,6 +288,11 @@ impl ToCapEvent for ClaimableMessage { } else { [0; 32] }; + let from = if self.from.is_some() { + self.from.unwrap() + } else { + Principal::anonymous() + }; let details = DetailsBuilder::default() .insert("owner", self.owner) .insert("ethContractAddress", self.token) @@ -295,7 +300,7 @@ impl ToCapEvent for ClaimableMessage { .insert("msgHashKey", hash_key.to_nat()) .insert("amount", self.amount.clone()) .insert("name", self.token_name.clone()) - .insert("from", self.from.clone()) + .insert("from", from) .build(); IndefiniteEventBuilder::new() @@ -317,7 +322,7 @@ impl From for ClaimableMessage { let from: Principal = event.details[6].1.clone().try_into().unwrap(); ClaimableMessage { - from: from, + from: Some(from), owner: event.caller, msg_key: Some(msg_key.to_nonce_bytes()), msg_hash: msg_hash,