Skip to content

Commit

Permalink
fix(wallet): select only basic utxos when building a transaction (#4178)
Browse files Browse the repository at this point in the history
Description
---
* Added a new filter when selecting unspent outputs on the wallet db level, to filter by the desired output tags
* Updated the integration test for the contract constitution, to first publish a contract definition

Motivation and Context
---
When selecting UTXOs as inputs for a new transaction, we want to only pick those "basic" UTXOs (only coinbase or no tags) to avoid spending "special" (i.e. DAN layer) outputs.

How Has This Been Tested?
---
The integration tests for contract definition + contract constitution do pass when publishing both transactions in the same test
  • Loading branch information
mrnaveira committed Jun 9, 2022
1 parent f3495ee commit 42269ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 42269ae

Please sign in to comment.