Skip to content

Commit

Permalink
Implement BCH and SLP tx history. Refactoring. #701 (#1175)
Browse files Browse the repository at this point in the history
* WIP.

* WIP. Added SqliteTxHistoryStorage.

* WIP. Implementing BCH and SLP tx history fetching as state machine.

* WIP.

* WIP. Tests fail.

* WIP. Refactoring.

* WIP.

* WIP.

* WIP.

* WIP.

* WIP.

* WIP. Fixes after merging dev.

* WIP.

* WIP. Adding tests.

* WIP. Updated toolchain. Adding block timestamp method to coins.

* WIP. Implementing my_tx_history_v2_rpc.

* WIP. Fixes after merging dev.

* WIP. Implementing my_tx_history 2.0 RPC.

* WIP.

* WIP. Implementing querying history from SQLite.

* WIP. Added db_common crate.

* WIP. RPC 2.0 is ready. Some tests left todo.

* Finish tests. Fix Clippy.

* Fix WASM.

* Add a couple of allows for my_tx_history_v2 under WASM.
  • Loading branch information
artemii235 committed Dec 28, 2021
1 parent be163e1 commit 383878a
Show file tree
Hide file tree
Showing 86 changed files with 3,812 additions and 911 deletions.
16 changes: 14 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ crc = "1.8"
crc32fast = { version = "1.2", features = ["std", "nightly"] }
crossbeam = "0.7"
crypto = { path = "mm2src/crypto" }
db_common = { path = "mm2src/db_common" }
derive_more = "0.99"
either = "1.6"
ethereum-types = { version = "0.4", default-features = false, features = ["std", "serialize"] }
Expand Down Expand Up @@ -109,7 +110,6 @@ serialization = { path = "mm2src/mm2_bitcoin/serialization" }
serialization_derive = { path = "mm2src/mm2_bitcoin/serialization_derive" }
sp-runtime-interface = { version = "3.0.0", default-features = false, features = ["disable_target_static_assertions"] }
sp-trie = { version = "3.0", default-features = false }
sql-builder = "3.1.1"

trie-db = { version = "0.22.6", default-features = false }
trie-root = "0.16.0"
Expand Down Expand Up @@ -147,6 +147,7 @@ members = [
"mm2src/coins/utxo_signer",
"mm2src/coins_activation",
"mm2src/crypto",
"mm2src/db_common",
"mm2src/derives/ser_error",
"mm2src/derives/ser_error_derive",
"mm2src/floodsub",
Expand Down
2 changes: 0 additions & 2 deletions azure-pipelines-build-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
displayName: 'Build MM2 Release'
# Build WASM.
- bash: |
cargo clean -p mm2-libp2p -p mm2 --target=wasm32-unknown-unknown
wasm-pack build --release --target web --out-dir target/target-wasm-release
displayName: 'Build MM2 WASM Release'
condition: eq( variables['Agent.OS'], 'Linux' )
Expand All @@ -56,7 +55,6 @@ jobs:
# Explicit --test-threads=16 makes testing process slightly faster on agents that have <16 CPU cores.
# Always run tests on mm2.1 branch and PRs
- bash: |
cargo clean -p mm2-libp2p -p mm2
cargo test --all -- --test-threads=16
displayName: 'Test MM2'
timeoutInMinutes: 22
Expand Down
20 changes: 20 additions & 0 deletions etomic_build/client/enable_tBCH_USDF
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data '{
"userpass": "'$userpass'",
"method": "enable_bch_with_tokens",
"mmrpc": "2.0",
"params": {
"ticker": "tBCH",
"allow_slp_unsafe_conf": true,
"bchd_urls": [],
"mode": {
"rpc": "Electrum",
"rpc_data":{
"servers": [{"url":"electroncash.de:50003"},{"url":"tbch.loping.net:60001"},{"url":"blackie.c3-soft.com:60001"},{"url":"bch0.kister.net:51001"},{"url":"testnet.imaginary.cash:50001"}]
}
},
"tx_history": true,
"slp_tokens_requests": [{"ticker":"USDF"}]
}
}'
1 change: 1 addition & 0 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cfg-if = "1.0"
chain = { path = "../mm2_bitcoin/chain" }
common = { path = "../common" }
crypto = { path = "../crypto" }
db_common = { path = "../db_common" }
derive_more = "0.99"
ethabi = { git = "https://github.com/artemii235/ethabi" }
ethcore-transaction = { git = "https://github.com/artemii235/parity-ethereum.git" }
Expand Down
6 changes: 4 additions & 2 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//
// Copyright © 2017-2019 SuperNET. All rights reserved.
//
use async_trait::async_trait;
use bigdecimal::BigDecimal;
use bitcrypto::sha256;
use common::custom_futures::TimedAsyncMutex;
Expand Down Expand Up @@ -659,6 +660,7 @@ impl Deref for EthCoin {
fn deref(&self) -> &EthCoinImpl { &*self.0 }
}

#[async_trait]
impl SwapOps for EthCoin {
fn send_taker_fee(&self, fee_addr: &[u8], amount: BigDecimal, _uuid: &[u8]) -> TransactionFut {
let address = try_fus!(addr_from_raw_pubkey(fee_addr));
Expand Down Expand Up @@ -986,7 +988,7 @@ impl SwapOps for EthCoin {
Box::new(fut.boxed().compat())
}

fn search_for_swap_tx_spend_my(
async fn search_for_swap_tx_spend_my(
&self,
_time_lock: u32,
_other_pub: &[u8],
Expand All @@ -999,7 +1001,7 @@ impl SwapOps for EthCoin {
self.search_for_swap_tx_spend(tx, swap_contract_address, search_from_block)
}

fn search_for_swap_tx_spend_other(
async fn search_for_swap_tx_spend_other(
&self,
_time_lock: u32,
_other_pub: &[u8],
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/eth/web3_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<T: Future> Future for SendFuture<T> {
fn poll(&mut self) -> Poll<Self::Item, Self::Error> { self.0.poll() }
}

unsafe impl<T> Send for SendFuture<T> {}
unsafe impl<T> Send for SendFuture<T> where T: Send {}
unsafe impl<T> Sync for SendFuture<T> {}

impl Transport for Web3Transport {
Expand Down
246 changes: 246 additions & 0 deletions mm2src/coins/for_tests/tBCH_tx_history_fixtures.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::utxo::{sat_from_big_decimal, FeePolicy, UtxoCommonOps, UtxoTxGenerati
use crate::{BalanceFut, CoinBalance, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MarketCoinOps, MmCoin,
NegotiateSwapContractAddrErr, SwapOps, TradeFee, TradePreimageFut, TradePreimageValue, TransactionEnum,
TransactionFut, UtxoStandardCoin, ValidateAddressResult, WithdrawFut, WithdrawRequest};
use async_trait::async_trait;
use bigdecimal::BigDecimal;
use bitcoin::blockdata::script::Script;
use bitcoin::hash_types::Txid;
Expand Down Expand Up @@ -116,6 +117,7 @@ impl LightningCoin {
fn platform_coin(&self) -> &UtxoStandardCoin { &self.platform_fields.platform_coin }
}

#[async_trait]
impl SwapOps for LightningCoin {
fn send_taker_fee(&self, _fee_addr: &[u8], _amount: BigDecimal, _uuid: &[u8]) -> TransactionFut { unimplemented!() }

Expand Down Expand Up @@ -232,7 +234,7 @@ impl SwapOps for LightningCoin {
unimplemented!()
}

fn search_for_swap_tx_spend_my(
async fn search_for_swap_tx_spend_my(
&self,
_time_lock: u32,
_other_pub: &[u8],
Expand All @@ -244,7 +246,7 @@ impl SwapOps for LightningCoin {
unimplemented!()
}

fn search_for_swap_tx_spend_other(
async fn search_for_swap_tx_spend_other(
&self,
_time_lock: u32,
_other_pub: &[u8],
Expand Down
12 changes: 6 additions & 6 deletions mm2src/coins/lightning/ln_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ impl EventHandler for LightningEventHandler {
// Give the funding transaction back to LDK for opening the channel.
match self
.channel_manager
.funding_transaction_generated(&temporary_channel_id, funding_tx.clone())
.funding_transaction_generated(temporary_channel_id, funding_tx.clone())
{
Ok(_) => {
let txid = funding_tx.txid();
self.filter.register_tx(&txid, &output_script);
self.filter.register_tx(&txid, output_script);
let output_to_be_registered = TxOut {
value: *channel_value_satoshis,
script_pubkey: output_script.clone(),
Expand Down Expand Up @@ -260,7 +260,7 @@ pub async fn start_lightning(
let broadcaster = Arc::new(platform_coin.clone());

// Initialize Persist
let ln_data_dir = my_ln_data_dir(&ctx, &ticker)
let ln_data_dir = my_ln_data_dir(ctx, &ticker)
.as_path()
.to_str()
.ok_or("Data dir is a non-UTF-8 string")
Expand Down Expand Up @@ -455,7 +455,7 @@ pub async fn start_lightning(

// If node is restarting read other nodes data from disk and reconnect to channel nodes/peers if possible.
if restarting_node {
let mut nodes_data = read_nodes_data_from_file(&nodes_data_path(&ctx, &ticker))?;
let mut nodes_data = read_nodes_data_from_file(&nodes_data_path(ctx, &ticker))?;
for (pubkey, node_addr) in nodes_data.drain() {
for chan_info in channel_manager.list_channels() {
if pubkey == chan_info.counterparty.node_id {
Expand Down Expand Up @@ -542,7 +542,7 @@ async fn process_tx_for_unconfirmation(txid: Txid, filter: Arc<PlatformFields>,
.platform_coin
.as_ref()
.rpc_client
.get_transaction_bytes(H256::from(txid.as_hash().into_inner()).reversed())
.get_transaction_bytes(&H256::from(txid.as_hash().into_inner()).reversed())
.compat()
.await
.map_err(|e| e.into_inner())
Expand Down Expand Up @@ -597,7 +597,7 @@ async fn process_txs_confirmations(
.platform_coin
.as_ref()
.rpc_client
.get_transaction_bytes(rpc_txid.clone())
.get_transaction_bytes(&rpc_txid)
.compat()
.await
{
Expand Down
Loading

0 comments on commit 383878a

Please sign in to comment.