Skip to content

Commit

Permalink
Problem: Missing wait_for_transaction_receipt (fix #914) (#915)
Browse files Browse the repository at this point in the history
* Problem: Missing wait_for_transaction_receipt (fix #914)

* Use futures

* Use FutureExt

* Wait for transaction receipt no need Option

* Add TxHashState and get_block_number

* Apply format

* Fix clippy issue

* Add get_interval

* Allow dead code

* No need send

* Fix clippy

* Apply format

* Fix wrong return type

* Allow dead code for wasm

* Update release 0.3.6

* Update CHANGELOG
  • Loading branch information
damoncro authored May 16, 2023
1 parent 6a46658 commit c68c911
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
Unreleased

## [0.3.6] - 2023-5-16
### Changed
- Add get_eth_transaction_receipt
- Add wait_for_transaction_receipt
- Add get_block_number

## [0.3.5] - 2023-4-21
### Changed
- Implement Serialize and Deserialize for ContractApproval and ContractTransfer
Expand Down
9 changes: 6 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings/cpp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "defi-wallet-core-cpp"
version = "0.3.5"
version = "0.3.6"
edition = "2021"
rust-version = "1.57"
license = "Apache-2.0"
Expand Down
48 changes: 44 additions & 4 deletions bindings/cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,18 +600,31 @@ pub mod ffi {
/// sent from it.
pub fn get_eth_nonce(address: &str, api_url: &str) -> Result<String>;

pub fn get_block_number_blocking(api_url: String) -> Result<String>;

#[cxx_name = "get_eth_transaction_receipt_blocking"]
pub fn get_eth_transaction_receipt_by_vec_blocking(
tx_hash: Vec<u8>,
api_url: &str,
api_url: String,
) -> Result<String>;

#[cxx_name = "get_eth_transaction_receipt_blocking"]
pub fn get_eth_transaction_receipt_by_string_blocking(
tx_hash: String,
api_url: &str,
api_url: String,
) -> Result<String>;

#[cxx_name = "wait_for_transaction_receipt_blocking"]
pub fn wait_for_transaction_receipt_by_vec_blocking(
tx_hash: Vec<u8>,
api_url: String,
) -> Result<String>;

#[cxx_name = "wait_for_transaction_receipt_blocking"]
pub fn wait_for_transaction_receipt_by_string_blocking(
tx_hash: String,
api_url: String,
) -> Result<String>;
/// broadcast signed cronos tx
pub fn broadcast_eth_signed_raw_tx(
raw_tx: Vec<u8>,
Expand Down Expand Up @@ -1301,11 +1314,16 @@ pub fn get_eth_nonce(address: &str, api_url: &str) -> Result<String> {
Ok(res.to_string())
}

pub fn get_block_number_blocking(api_url: String) -> Result<String> {
let block_number = defi_wallet_core_common::get_block_number_blocking(api_url)?;
Ok(block_number)
}

/// Get eth transaction receipt with transaction hash, return json string
/// TODO: Provide TransactionReceipt type binding
pub fn get_eth_transaction_receipt_by_vec_blocking(
tx_hash: Vec<u8>,
api_url: &str,
api_url: String,
) -> Result<String> {
let receipt =
defi_wallet_core_common::get_eth_transaction_receipt_by_vec_blocking(tx_hash, api_url)?;
Expand All @@ -1320,7 +1338,7 @@ pub fn get_eth_transaction_receipt_by_vec_blocking(
/// TODO: Provide TransactionReceipt type binding
pub fn get_eth_transaction_receipt_by_string_blocking(
tx_hash: String,
api_url: &str,
api_url: String,
) -> Result<String> {
let receipt =
defi_wallet_core_common::get_eth_transaction_receipt_by_string_blocking(tx_hash, api_url)?;
Expand All @@ -1331,6 +1349,28 @@ pub fn get_eth_transaction_receipt_by_string_blocking(
}
}

/// Wait for transaction receipt with transaction hash, return json string
/// TODO: Provide TransactionReceipt type binding
pub fn wait_for_transaction_receipt_by_vec_blocking(
tx_hash: Vec<u8>,
api_url: String,
) -> Result<String> {
let receipt =
defi_wallet_core_common::wait_for_transaction_receipt_by_vec_blocking(tx_hash, api_url)?;
Ok(serde_json::to_string(&receipt)?)
}

/// wait for transaction receipt with transaction hash, return json string
/// TODO: Provide TransactionReceipt type binding
pub fn wait_for_transaction_receipt_by_string_blocking(
tx_hash: String,
api_url: String,
) -> Result<String> {
let receipt =
defi_wallet_core_common::wait_for_transaction_receipt_by_string_blocking(tx_hash, api_url)?;
Ok(serde_json::to_string(&receipt)?)
}

/// broadcast signed cronos tx
pub fn broadcast_eth_signed_raw_tx(
raw_tx: Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "defi-wallet-core-wasm"
version = "0.3.5"
version = "0.3.6"
edition = "2021"
rust-version = "1.57"
license = "Apache-2.0"
Expand Down
5 changes: 4 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "defi-wallet-core-common"
version = "0.3.5"
version = "0.3.6"
edition = "2021"
rust-version = "1.57"
license = "Apache-2.0"
Expand Down Expand Up @@ -56,6 +56,9 @@ uniffi = { version = "^0.23", optional = true }
uniffi_macros = { version = "^0.23", optional = true }
url = "2"
hex="0.4.3"
futures = "0.3"
futures-util = "0.3"
pin-project = "1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
cosmos-sdk-proto = { git = "https://github.com/crypto-com/cosmos-rust.git", default-features = false, features = ["cosmwasm", "grpc"] }
Expand Down
1 change: 1 addition & 0 deletions common/src/common.udl
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ enum EthError {
"SendTxFail",
"BroadcastTxFail",
"GetTransactionReceiptError",
"GetBlockNumberError",
"InvalidTxHash",
"MempoolDrop",
"BalanceFail",
Expand Down
Loading

0 comments on commit c68c911

Please sign in to comment.