Skip to content
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

fix(wallet): select only basic utxos when building a transaction #4178

Merged
merged 11 commits into from
Jun 9, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ impl OutputSql {
tip_height: i64,
conn: &SqliteConnection,
) -> Result<Vec<OutputSql>, OutputManagerStorageError> {
let no_flags = i32::from(OutputFlags::empty().bits());
let coinbase_flag = i32::from(OutputFlags::COINBASE_OUTPUT.bits());

if strategy == UTXOSelectionStrategy::Default {
// lets get the max value for all utxos
let max: Vec<i64> = outputs::table
Expand All @@ -131,6 +134,7 @@ impl OutputSql {
.filter(outputs::maturity.le(tip_height))
.filter(outputs::features_unique_id.is_null())
.filter(outputs::features_parent_public_key.is_null())
.filter(outputs::flags.eq(no_flags).or(outputs::flags.eq(coinbase_flag)))
.order(outputs::value.desc())
.select(outputs::value)
.limit(1)
Expand All @@ -151,6 +155,7 @@ impl OutputSql {
.filter(outputs::maturity.le(tip_height))
.filter(outputs::features_unique_id.is_null())
.filter(outputs::features_parent_public_key.is_null())
.filter(outputs::flags.eq(no_flags).or(outputs::flags.eq(coinbase_flag)))
.order_by(outputs::spending_priority.desc());
match strategy {
UTXOSelectionStrategy::Smallest => {
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/features/WalletCli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ Feature: Wallet CLI
And I have mining node MINE connected to base node BASE and wallet WALLET
And mining node MINE mines 4 blocks
Then I wait for wallet WALLET to have at least 1000000 uT
And I publish a contract constitution from file "fixtures/contract_constitution.json" on wallet WALLET via command line
And I publish a contract definition from file "fixtures/contract_definition.json" on wallet WALLET via command line
And mining node MINE mines 8 blocks
Then wallet WALLET has at least 1 transactions that are all TRANSACTION_STATUS_MINED_CONFIRMED and not cancelled
And I publish a contract constitution from file "fixtures/contract_constitution.json" on wallet WALLET via command line
And mining node MINE mines 8 blocks
Then wallet WALLET has at least 2 transactions that are all TRANSACTION_STATUS_MINED_CONFIRMED and not cancelled
Then WALLET is connected to BASE