New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qtum delegation #1096
Qtum delegation #1096
Conversation
mm2src/coins/qrc20.rs
Outdated
amount: BigDecimal, | ||
to_addr: Address, | ||
fee: u64, | ||
) -> Result<GenerateQrc20TxResult, MmError<GenerateTxError>> { | ||
let staker_address_hex = qtum::contract_addr_from_utxo_addr(to_addr.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The amount cannot be < 100, otherwise, we need to return an error.
mm2src/coins/qrc20.rs
Outdated
Token::Bytes(signature.into()), | ||
])?; | ||
|
||
let contract_address = ethabi::Address::from_str("0000000000000000000000000000000000000086").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I turn it into a constant? It's the smart contract address of the delegation for QTUM.
mm2src/coins/qrc20.rs
Outdated
println!("res: {}", hex::encode(params)); | ||
println!("script_pubkey: {}", hex::encode(script_pubkey.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
…into qtum_delegation
…ure confirmations field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next review iteration 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more review iteration.
mm2src/mm2_tests/structs.rs
Outdated
@@ -4,6 +4,7 @@ | |||
/// backwards compatibility | |||
/// Use `#[serde(deny_unknown_fields)]` for all structs for tests to fail in case of adding new fields to the response | |||
use bigdecimal::BigDecimal; | |||
use coins::TransactionType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please declare the TransactionType
separately here. If we occasionally make an incompatible change, we won't catch it because we import the updated struct.
- Return an Error in add and remove delegation functions - get_staking_infos could also be used to see if your address format support delegation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor nitpicks 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is almost perfect. Could you please fix the last few comments?
mm2src/coins/lp_coins.rs
Outdated
@@ -442,6 +472,41 @@ impl WithdrawRequest { | |||
} | |||
} | |||
|
|||
/// Please note that no type should have the same structure as another type, | |||
/// because this enum has the `untagged` deserialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is the comment yet :D
because this enum has the
untagged
deserialization.
mm2src/coins/utxo/qtum_delegation.rs
Outdated
.map_to_mm(|e| StakingInfosError::Transport(e.to_string()))?; | ||
let am_i_staking = add_delegation_history.len() > remove_delegation_history.len(); | ||
if am_i_staking { | ||
let last_tx_add = &add_delegation_history[add_delegation_history.len() - 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't crush since add_delegation_history.len() > remove_delegation_history.len()
is true if add_delegation_history
is not empty. But could you please add an explicit check for the length of add_delegation_history
, or use
let last_tx_add = match add_delegation_history.last() {
Some(last_tx_add) => last_tx_add,
None => return Ok(None),
};
I ask you to do it because someone, including me, can change the if
condition and forget to check the length.
mm2src/coins/utxo/qtum_delegation.rs
Outdated
// topic[0] -> a23803f3b2b56e71f2921c22b23c32ef596a439dbe03f7250e6b58a30eb910b5 | ||
// topic[1] -> 000000000000000000000000d4ea77298fdac12c657a18b222adc8b307e18127 -> staker_address | ||
// topic[2] -> 0000000000000000000000006d9d2b554d768232320587df75c4338ecc8bf37d | ||
let raw = res[0].log[0].topics[1].trim_start_matches('0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddDelegation
contract call can be not only the first output of a transaction, but also second and third, and so on. Please look at the example. You can check which output emitted QTUM_ADD_DELEGATION_TOPIC
something like this:
let receipt = res.into_iter().find(|receipt| receipt.log.iter().any(it_qtum_add_delegation)).expect("TODO using match");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it looks perfect, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Milerius Please fix Clippy and make sure you run this check locally before pushing, especially to the almost finished PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reapproving
WIP:
#802
Some info before reviewing from QTUM developers:
ROI and Fees:
Staking amount:
Non-custodial
The last point is charming. This means that no modification is required regarding balance spendable or not; as far the delectation is still active, that means for every UTXO's > 100 QTUM, you will be staking.
Please read https://docs.qtum.site/en/OfflineStakingDelegation/ before reviewing.
remove_delegation example: https://testnet.qtum.info/tx/421a628e8465783a7e1ba28803b7b882e3069d1fe070fb84ae9efb5512eb2032
add_delegation example: https://testnet.qtum.info/tx/48921789c7dc3d6362421940a38b612354615351090e21095d636bb4b031782b