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

Handle unconfirmed trx in wallet #24

Merged
merged 22 commits into from
Dec 21, 2023
Merged

Handle unconfirmed trx in wallet #24

merged 22 commits into from
Dec 21, 2023

Conversation

dangershony
Copy link
Member

No description provided.

Comment on lines 14 to 15
public List<UtxoData> PendingAdd { get; set; } = new();
public List<UtxoData> PendingRemove { get; set; } = new();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We duplicate the data in storage, can't we just set it as a property on the UTXO data that is held in the address info utxo data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but it go more complicated, the duplication is negligible anyway

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of duplicates you need to pass both objects to the wallet operations and check each output you try to use to make sure it's not already used, this seems like you try to avoid a problem only to get it again down the line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is more complicated, if we start to change the state that we receive form the indexer then I will have to look at the state when syncing, the proposed flag on the object will get overridden when we refresh but the utxo is not confirmed yet, though we could overcome that by changing the structure of how we store data.

src/Angor/Client/Pages/Wallet.razor Outdated Show resolved Hide resolved
@dangershony
Copy link
Member Author

this is now ready to review @DavidGershony

Comment on lines 176 to 181
foreach (var addressInfo in accountInfo.AddressesInfo.Concat(accountInfo.ChangeAddressesInfo))
{
// find all spent inputs to mark them as spent
foreach (var utxoData in addressInfo.UtxoData)
{
foreach (var outPoint in inputs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 nested loops, isn't there a better way to get the utxos?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if I use linq there will still be loops it will just look shorter.
To optimize here we will need to use dictionaries but I think this is not really needed

return new Outpoint { outputIndex = (int)outPoint.N, transactionId = outPoint.Hash.ToString() };
}

public static Outpoint Create(string trxid, int index)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be a constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its simpler to understand as it is used in linq queries

DavidGershony
DavidGershony previously approved these changes Dec 15, 2023
DavidGershony
DavidGershony previously approved these changes Dec 21, 2023
@@ -368,7 +316,16 @@ public async Task UpdateAccountInfoWithNewAddressesAsync(AccountInfo accountInfo
{
var addressInfoToDelete = accountInfo.AddressesInfo.SingleOrDefault(_ => _.Address == addressInfo.Address);
if (addressInfoToDelete != null)
{
//TODO need to update the indexer response with mempool utxo as well so it is always consistant
foreach (var utxoData in addressInfo.UtxoData.Where(x => x.InMempoolTransaction))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a mistake it should be addressInfoToDelete.UtxoData.Where(x => x.InMempoolTransaction)

@dangershony dangershony merged commit d708d46 into main Dec 21, 2023
3 checks passed
@dangershony dangershony deleted the handle-unconfirmed branch December 21, 2023 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants