Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ginkgo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vjrj
ginkgo
Commits
4309d521
Commit
4309d521
authored
1 year ago
by
vjrj
Browse files
Options
Downloads
Patches
Plain Diff
Refactor
parent
372e9353
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/data/models/multi_wallet_transaction_cubit.dart
+111
-103
111 additions, 103 deletions
lib/data/models/multi_wallet_transaction_cubit.dart
with
111 additions
and
103 deletions
lib/data/models/multi_wallet_transaction_cubit.dart
+
111
−
103
View file @
4309d521
...
...
@@ -147,123 +147,28 @@ class MultiWalletTransactionCubit
}
final
Map
<
String
,
dynamic
>
txData
=
txDataResult
.
item1
!
;
TransactionState
newState
=
final
TransactionState
new
Parsed
State
=
await
transactionsGvaParser
(
txData
,
currentState
);
if
(
newState
.
balance
<
0
)
{
if
(
new
Parsed
State
.
balance
<
0
)
{
logger
(
'Warning: Negative balance in node
${txDataResult.item2}
'
);
increaseNodeErrors
(
NodeType
.
gva
,
node
);
continue
;
}
success
=
true
;
if
(
newState
.
currentUd
!=
null
)
{
appCubit
.
setUd
(
newState
.
currentUd
!
);
if
(
new
Parsed
State
.
currentUd
!=
null
)
{
appCubit
.
setUd
(
new
Parsed
State
.
currentUd
!
);
}
logger
(
'Last received notification:
${newState.latestReceivedNotification.toIso8601String()}
)}'
);
'Last received notification:
${new
Parsed
State.latestReceivedNotification.toIso8601String()}
)}'
);
logger
(
'Last sent notification:
${newState.latestSentNotification.toIso8601String()}
)}'
);
'Last sent notification:
${new
Parsed
State.latestSentNotification.toIso8601String()}
)}'
);
// Check pending transactions
if
(
cursor
==
null
)
{
// First page, so let's check pending transactions
final
LinkedHashSet
<
Transaction
>
newPendingTransactions
=
LinkedHashSet
<
Transaction
>();
final
List
<
Transaction
>
newTransactions
=
<
Transaction
>[];
// Index transactions by key
final
Map
<
String
,
Transaction
>
txMap
=
<
String
,
Transaction
>{};
final
Map
<
String
,
Transaction
>
pendingMap
=
<
String
,
Transaction
>{};
// or maybe it doesn't merit the effort
for
(
final
Transaction
t
in
newState
.
transactions
)
{
txMap
[
_getTxKey
(
t
)]
=
t
;
}
// Get a range of tx in 1h
TransactionsBloc
()
.
lastTx
()
.
forEach
((
Transaction
t
)
{
txMap
[
_getTxKey
(
t
)]
=
t
;
});
for
(
final
Transaction
t
in
newState
.
pendingTransactions
)
{
pendingMap
[
_getTxKey
(
t
)]
=
t
;
}
// Adjust pending transactions
for
(
final
Transaction
pend
in
newState
.
pendingTransactions
)
{
if
(
pend
.
type
==
TransactionType
.
waitingNetwork
)
{
newPendingTransactions
.
add
(
pend
);
continue
;
}
if
(
txMap
[
_getTxKey
(
pend
)]
!=
null
)
{
// Found a match
// VER SI SENT o que
final
Transaction
t
=
txMap
[
_getTxKey
(
pend
)]
!
;
if
(
t
.
type
==
TransactionType
.
sent
)
{
loggerDev
(
'@@@@@ Found a sent match for pending transaction
${pend.toStringSmall(myPubKey)}
'
);
// Add later the tx, but don't add the pending
}
else
{
if
(
t
.
type
==
TransactionType
.
sending
)
{
loggerDev
(
'@@@@@ Found a sending match for pending transaction
${pend.toStringSmall(myPubKey)}
'
);
// Re-add as pending
// The tx will not be add as sending (as some nodes will show it and others will not,
// we use better the pending)
// FIXME: if this is old, probably is stuck, so maybe we should cancel->retry
newPendingTransactions
.
add
(
pend
.
copyWith
(
debugInfo:
pend
.
debugInfo
??
'Node where see it:
${node.url}
'
));
}
else
{
loggerDev
(
'@@@@@ WARNING: Found a
${t.type}
match for pending transaction
${pend.toStringSmall(myPubKey)}
'
);
}
}
}
else
{
// Not found a match
if
(
areDatesClose
(
DateTime
.
now
(),
pend
.
time
,
paymentTimeRange
))
{
loggerDev
(
'@@@@@ Not found yet pending transaction
${pend.toStringSmall(myPubKey)}
'
);
newPendingTransactions
.
add
(
pend
);
}
else
{
// Old pending transaction, warn user
loggerDev
(
'@@@@@ Warn user: Not found an old pending transaction
${pend.toStringSmall(myPubKey)}
'
);
// Add it but with missing type
newPendingTransactions
.
add
(
pend
.
copyWith
(
type:
TransactionType
.
failed
));
}
}
}
for
(
final
Transaction
tx
in
newState
.
transactions
)
{
if
(
pendingMap
[
_getTxKey
(
tx
)]
!=
null
&&
(
tx
.
type
==
TransactionType
.
sending
||
tx
.
type
==
TransactionType
.
sent
))
{
// Found a match
if
(
tx
.
type
==
TransactionType
.
sent
)
{
// Ok add it, but not as pending
newTransactions
.
add
(
tx
);
}
else
{
// It's sending so should be added before as pending
}
}
else
{
// Does not match
if
(
tx
.
type
==
TransactionType
.
sending
)
{
// Not found, maybe we are in other client, so add as pending
newPendingTransactions
.
add
(
tx
.
copyWith
(
type:
TransactionType
.
pending
));
}
else
{
// the rest
newTransactions
.
add
(
tx
);
}
}
}
newState
=
newState
.
copyWith
(
transactions:
newTransactions
,
pendingTransactions:
newPendingTransactions
.
toList
());
}
final
TransactionState
newState
=
_checkPendingTx
(
cursor
,
newParsedState
,
myPubKey
,
node
);
_emitState
(
myPubKey
,
newState
);
for
(
final
Transaction
tx
in
newState
.
transactions
.
reversed
)
{
...
...
@@ -304,4 +209,107 @@ class MultiWalletTransactionCubit
// This should not be executed
return
<
Transaction
>[];
}
TransactionState
_checkPendingTx
(
String
?
cursor
,
TransactionState
newState
,
String
myPubKey
,
Node
node
)
{
// Check pending transactions
if
(
cursor
==
null
)
{
// First page, so let's check pending transactions
final
LinkedHashSet
<
Transaction
>
newPendingTransactions
=
LinkedHashSet
<
Transaction
>();
final
List
<
Transaction
>
newTransactions
=
<
Transaction
>[];
// Index transactions by key
final
Map
<
String
,
Transaction
>
txMap
=
<
String
,
Transaction
>{};
final
Map
<
String
,
Transaction
>
pendingMap
=
<
String
,
Transaction
>{};
// or maybe it doesn't merit the effort
for
(
final
Transaction
t
in
newState
.
transactions
)
{
txMap
[
_getTxKey
(
t
)]
=
t
;
}
// Get a range of tx in 1h
TransactionsBloc
()
.
lastTx
()
.
forEach
((
Transaction
t
)
{
txMap
[
_getTxKey
(
t
)]
=
t
;
});
for
(
final
Transaction
t
in
newState
.
pendingTransactions
)
{
pendingMap
[
_getTxKey
(
t
)]
=
t
;
}
// Adjust pending transactions
for
(
final
Transaction
pend
in
newState
.
pendingTransactions
)
{
if
(
pend
.
type
==
TransactionType
.
waitingNetwork
)
{
newPendingTransactions
.
add
(
pend
);
continue
;
}
if
(
txMap
[
_getTxKey
(
pend
)]
!=
null
)
{
// Found a match
// VER SI SENT o que
final
Transaction
t
=
txMap
[
_getTxKey
(
pend
)]
!
;
if
(
t
.
type
==
TransactionType
.
sent
)
{
loggerDev
(
'@@@@@ Found a sent match for pending transaction
${pend.toStringSmall(myPubKey)}
'
);
// Add later the tx, but don't add the pending
}
else
{
if
(
t
.
type
==
TransactionType
.
sending
)
{
loggerDev
(
'@@@@@ Found a sending match for pending transaction
${pend.toStringSmall(myPubKey)}
'
);
// Re-add as pending
// The tx will not be add as sending (as some nodes will show it and others will not,
// we use better the pending)
// FIXME: if this is old, probably is stuck, so maybe we should cancel->retry
newPendingTransactions
.
add
(
pend
.
copyWith
(
debugInfo:
pend
.
debugInfo
??
'Node where see it:
${node.url}
'
));
}
else
{
loggerDev
(
'@@@@@ WARNING: Found a
${t.type}
match for pending transaction
${pend.toStringSmall(myPubKey)}
'
);
}
}
}
else
{
// Not found a match
if
(
areDatesClose
(
DateTime
.
now
(),
pend
.
time
,
paymentTimeRange
))
{
loggerDev
(
'@@@@@ Not found yet pending transaction
${pend.toStringSmall(myPubKey)}
'
);
newPendingTransactions
.
add
(
pend
);
}
else
{
// Old pending transaction, warn user
loggerDev
(
'@@@@@ Warn user: Not found an old pending transaction
${pend.toStringSmall(myPubKey)}
'
);
// Add it but with missing type
newPendingTransactions
.
add
(
pend
.
copyWith
(
type:
TransactionType
.
failed
));
}
}
}
for
(
final
Transaction
tx
in
newState
.
transactions
)
{
if
(
pendingMap
[
_getTxKey
(
tx
)]
!=
null
&&
(
tx
.
type
==
TransactionType
.
sending
||
tx
.
type
==
TransactionType
.
sent
))
{
// Found a match
if
(
tx
.
type
==
TransactionType
.
sent
)
{
// Ok add it, but not as pending
newTransactions
.
add
(
tx
);
}
else
{
// It's sending so should be added before as pending
}
}
else
{
// Does not match
if
(
tx
.
type
==
TransactionType
.
sending
)
{
// Not found, maybe we are in other client, so add as pending
newPendingTransactions
.
add
(
tx
.
copyWith
(
type:
TransactionType
.
pending
));
}
else
{
// the rest
newTransactions
.
add
(
tx
);
}
}
}
newState
=
newState
.
copyWith
(
transactions:
newTransactions
,
pendingTransactions:
newPendingTransactions
.
toList
());
}
return
newState
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment