Skip to content

Commit

Permalink
Merge QRC20 Native Mode into mm2.1 (#786)
Browse files Browse the repository at this point in the history
* Qrc20 native mode (#779)

* Add QRC20 and QTUM balance checking on QRC20 withdraw
* Add a description of that case when we have not enough QTUM balance

* Implement can_i_spend_other_payment for QRC20 that checks QTUM balance
* Update QRC20_GAS_LIMIT_DEFAULT to 100000, set QRC20_SWAP_GAS_REQUIRED to 300000

* Fix rustfmt errors

* Add Qrc20Coin::allowance and Qrc20Coin::contract_call

* Separate qrc20_withdraw to itself and generate_qrc20_transaction

* Implement Qrc20::send_maker_payment
* Add and implement approve_output, erc20_payment_output
* Add send_maker_payment QRC20 specific implementation

* Add SwapOps::wait_for_swap_payment_confirmations()
* Remove send_outputs_from_my_address from UtxoArcCommonOps

* Add QRC20Coin::validate_swap_contract_call()
* This function will be used not only within SwapOps::wait_for_swap_payment_confirmations()

* Add and implement Qrc20Coin::transaction_calls_details
The function will be used in wait_for_swap_payment_confirmations(), validate_maker_payment() etc

* Fix validate_maker_payment, add green tests

* Implement Qrc20Coin::send_taker_spends_maker_payment, add a green test

* Add ContractCallType::ReceiverSpend

* Add Erc20PaymentDetails
* Erc20PaymentDetails contains values from script_pubkey and logs both
* replace ContractCallDetails with Erc20PaymentDetails only

* Add an intermediate MakekSwap state - WaitForMakerPaymentComplete
* Add SwapOps::check_if_my_pament_completed()
* Remove SwapOps::wait_for_swap_payment_confirmations()
* Remove Erc20PaymentDetails::excepted

* Implement Qrc20Coin::check_if_my_payment_sent

* Implement Qrc20Coin::send_maker_refunds_payment, add green test

* Add an intermediate TakerSwap state - WaitForTakerPaymentComplete
* Fix MakerSwap::validate_taker_payment: call wait_for_confirmations before validate_taker_payment

* Fix wait duration when taker waits a maker-payment

* Implement taker side methods for Qrc20Coin (not all)
* Implement Qrc20Coin::[send_taker_payment, send_maker_spends_taker_payment, validate_taker_payment]
* Remove UtxoArcCommonOps::validate_payment
* Add test_maker_spends_taker_payment green test

* Implement Qrc20Coin::send_taker_refunds_payment()

* Implement Qrc20Coin::[send_taker_fee(), validate_fee()]

* Implement Qrc20Coin::[search_for_swap_tx_spend_my, search_for_swap_tx_spend_other]

* Refactor
* Remove UtxoCoinCommonOps::search_for_swap_tx_spend
* todo list

* Implement Qrc20Coin::wait_for_tx_spend

* Add and implement SwapOps::extract_secret()

* Add utxo_tests::qrc20_coin_for_test()

* Refactor QRC20
* Add HistoryBuilder
* Remove Qrc20Coin::search_swap_tx_by_call_type_and_swap_id (replaced with HistoryBuilder)

* Add wait_for_tx_spend_malicious, extract_secret_malicious tests

* Add swap_id validation in Qrc20Coin::validation_payment
* Fix test_qrc20_withdraw_impl_fee_details

* Refactor QRC20
* Add ContractCallOutput

* Refactor QRC20
* Replace qrc20.rs to coins directory from utxo
* Add qrc20/qrc20_tests.rs
* Add qrc20/rpc_electrum.rs

* Refactor QRC20
* Replace Swap specific functions to the separate swap_ops.rs module

* Refactor QRC20
* Add Qrc20CoinFields, Qrc20Coin(Arc<Qrc20CoinFields>)
* Replace AsRef<UtxoArc> with AsRef<UtxoCoinFields>

* Refactor QRC20
* Combine UtxoCoinCommonOps and UtxoArcCommonOps into UtxoCommonOps

* Replace TransactionDetails with TransactionIdentifier in maker/taker swap

* Add UtxoStandardOps
* Replace tx_details_by_hash, request_tx_history to UtxoStandardOps

* Add Qrc20Coin::transfer_details_by_hash
* Add TxInternalId

* Replace script pubkey function into separated module
* Add qrc20_script.rs
* Move Qrc20Coin::transfer_output into qrc20.rs

* Rename qrc20_script.rs to script_pubkey.rs

* Implement Qrc20Coin::process_history_loop
* Add common::LazyLocal
* Fix mm2_tests::test_qrc20_tx_history

* Fix is_qtum_unspent_mature
* Allow unspent outputs with confirmations == 0

* Send [maker, taker]-payment DHT immediately before wait_for_confirmations

* Optimize HistoryBuilder::build_utxo: load UtxoTx only if it is required
* Replace HistoryBuilder to history.rs
* Replace HistoryBuilder's build_utxo with build_utxo_lazy
* Add UtxoLazyFuture
* Add versionin to qrc20::script_pubkey::is_contract_call

* Fix UTXO validate_address

* Use Script::get_instruction() instead of Script::iter()

* Add for_tests::enable_qrc20
* Use enable_qrc20 in mm2_tests
* Fix trade_base_rel_electrum()

* Fix clippy warning

* Add conversion between Wallet and Contract QRC20 address formats
* Implement Qrc20Coin::try_address_from_str(), Qrc20Coin::convert_to_address()
* Refactor QRC20

* Refactor ContractCallType
* Replace ContractCallType to qrc20.rs
* Refactor ContractCallType::from_script_pubkey()

* Refactor comments

* Switch unjustified use of sign fields and variables

* Refactor contractaddress RPC call
* Remove UtxoCommonOps::try_address_from_str()
* Rename try_address_from_str() to address_from_any_format()

* PR issues
* Replace qrc20_addr_from_str() implementation with eth::addr_from_str
* Replace tokens.is_empty() with tokens.first()

* Make utxo_common::search_for_swap_tx_spend an async

* Fix can_i_spend_other_payment() and get_trade_fee()
* Add an estimated trade fee to gas fee within the both functions

* Add red test_validate_maker_payment_malicious

* Make test_validate_maker_payment_malicious green
* Add additional checking to Qrc20Coin::erc20_payment_details_from_tx()

* Add payment status checking on validate_payment (Eth, Qrc20)
* Change Qrc20Coin::get_qrc20_tx_fee return type from ActualTxFee to u64

* Cover case when swap contract address was updated during restart
* Do calling payment_status, refund and spend on smart contract address extracted from original swap transaction

* Refactor Qrc20Coin::validate_payment()
* Add field Erc20PaymentDetails::contract_call_bytes
* Try to compare expected erc20Payment call bytes with an actual bytes
* Rename extract_token_addr_from_script() to extract_contract_addr_from_script()

* Simplify utxo_common::check_if_my_payment_completed()

* Fix compile warnings

* Refactor Qrc20Coin
* Remove an extract unwrap() call
* Fix clippy warnings

* Add several retries on check_if_my_payment_completed() error

* Add a TODO message for the next Qrc20 impl iteration

* Request decimals from QRC20 contract if it is not set in config

* Remove [Maker/Taker]PaymentCompleteFailed, check_if_my_payment_completed

* Fix utxo_common::ordered_mature_unspents()
* Add the checking if block_count >= tx_height
* Replace caching from get_verbose_transaction_from_cache_or_rpc() to separate cache_transaction_if_possible()
* Add ordered_mature_unspents() tests
* Fix mm2_tests::test_withdraw_cashaddresses(): replace wallet address

* Rename calc_actual_tx_confirmations() to calc_actual_cached_tx_confirmations()

* Add the checking of taker payment spend transaction
* Add TakerPaymentSpendConfirmStarted, TakerPaymentSpendConfirmed, TakerPaymentSpendConfirmFailed maker events
* Add ConfirmTakerPaymentSpend maker command

* Refactor Qrc20Coin::wait_for_confirmations
* Add the checking of swap contract calls are completed

* MakerSwap::confirm_taker_payment_spend() wait confirmations anyway

* Replace TransactionDetails with TransactionIdent in test jsons

* Add Native RPC calls, add TransferHistoryBuilder

* Rename rpc_electrum.rs to rpc_client.rs, swap_ops.rs to swap.rs

* Refactor TransferHistoryBuilder to use it in QRC20 tx history

* Make it possible to load TX history using Native mode
* Replace TransferHistoryBuilder from swap.rs to history.rs
* Add TransferHistoryBuilder::build_tx_idents() that is used in request_tx_history()

* Add Native RPC client supporting to swap operations

* Refactor UTXO coin creation
* Add UtxoCoinBuilder trait, Qrc20CoinBuilder, UtxoArcBuilder
* Replace utxo_fields_from_conf_and_request() with UtxoCoinBuilder implementation

* Initialize a Qtum docker node on docker_tests start

* Add generate_qrc20_coin_with_random_privkey
* Add and implement Qrc20NativeWalletOps that may change a wallet state

* Refactor UTXO coin creation
* Add UtxoCoinBuilder trait, Qrc20CoinBuilder, UtxoArcBuilder
Add fill_qrc20_address, add a temporary green qrc20 docker test

* Add qrc20 tests to docker_tests
* Replace Qtum env bootstrap into separated qrc20_tests module

* Move Qrc20NativeWalletOps into for_tests module

* Add sergeyboyko/qtumregtest docker image instead of hardcode image id

* Add 'network' param to UTXO coin config

* Replace Qtum dependent functions to qtum.rs from qrc20.rs

* Specify QTUM_CONF_PATH to use it in regtest

* Remove TODO
* Set SEARCH_LOGS_STEP to 100 instead of 5000
* Call coin_daemon_data_dir with QRC20 platform in lowercase

* Rename qrc20/rpc_client.rs to qrc20/rpc_clients.rs

* Add MmCoinEnum::QtumCoin, CoinProtocol::QTUM

* Add [maker/taker]_coin_swap_contract_address to swap file
* Add the swap_contract_address param to the SwapOps/MmCoin/MarketCoin ops
* Add test_trade_qrc20 green test and other ignored tests

* Rename asset_coin_from_privkey to utxo_coin_from_privkey

* Add Qrc20RpcOps
* Replace request_token_decimals, Qrc20Coin::get_transaction_receipts, Qrc20Coin::rpc_contract_call to Qrc20RpcOps
* Replace RpcContractCallType to qrc20/rpc_clients.rs

* Replace get_addresses_by_label from QtumNativeOps to NativeClient

* Rename ContractCallType to MutContractCallType, RpcContractCallType to ViewContractCallType

* Fix PR issues
* Replace log! with error!, warn!
* Move electrum/native TransferHistory implementation into the BuildTransferHistory trait

* Replace merge_utxo_loop into utxo_common
* Add WeakUpgradableCoin, ArcDowngradableCoin to lp_coins

* Remove extra WeakUpgradableCoin, ArcDowngradableCoin traits
  • Loading branch information
sergeyboyko0791 authored Jan 18, 2021
1 parent 7b510fb commit 3cc42ed
Show file tree
Hide file tree
Showing 26 changed files with 3,755 additions and 2,060 deletions.
35 changes: 12 additions & 23 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ crc32fast = { version = "1.2", features = ["std", "nightly"] }
crossbeam = "0.7"
dirs = { version = "1", optional = true }
either = "1.6"
ethereum-types = { version = "0.4", default-features = false, features = ["std", "serialize"] }
enum-primitive-derive = "0.1"
fomat-macros = "0.2"
futures01 = { version = "0.1", package = "futures" }
Expand Down
Loading

0 comments on commit 3cc42ed

Please sign in to comment.