Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Cesium
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
Container Registry
Model registry
Operate
Environments
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
bpresles
Cesium
Commits
9ceb4763
Commit
9ceb4763
authored
6 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[fix] Currency: Add a retry;, when loading last UD and when the block is not found.
parent
fe88da95
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
www/js/services/currency-services.js
+36
-16
36 additions, 16 deletions
www/js/services/currency-services.js
with
36 additions
and
16 deletions
www/js/services/currency-services.js
+
36
−
16
View file @
9ceb4763
...
...
@@ -98,32 +98,52 @@ angular.module('cesium.currency.services', ['ngApi', 'cesium.bma.services'])
});
}
function
loadCurrentUD
()
{
function
loadCurrentUD
(
res
,
retryCount
)
{
return
BMA
.
blockchain
.
stats
.
ud
()
.
then
(
function
(
res
){
.
then
(
function
(
res
)
{
// Special case for currency init
if
(
!
res
.
result
.
blocks
.
length
)
{
data
.
currentUD
=
data
.
parameters
?
data
.
parameters
.
ud0
:
-
1
;
return
data
.
currentUD
;
}
else
{
var
lastBlockWithUD
=
res
.
result
.
blocks
[
res
.
result
.
blocks
.
length
-
1
];
return
BMA
.
blockchain
.
block
({
block
:
lastBlockWithUD
})
.
then
(
function
(
block
){
data
.
currentUD
=
powBase
(
block
.
dividend
,
block
.
unitbase
);
return
data
.
currentUD
;
})
.
catch
(
function
(
err
)
{
console
.
error
(
"
[currency] Unable to load last block with UD, with number {0}
"
.
format
(
lastBlockWithUD
));
data
.
currentUD
=
null
;
throw
err
;
});
}
return
_safeLoadCurrentUD
(
res
,
res
.
result
.
blocks
.
length
-
1
);
})
.
catch
(
function
(
err
)
{
data
.
currentUD
=
null
;
throw
err
;
});
})
}
/**
* Load the last UD, with a workaround if last block with UD is not found in the node
* @param res
* @param blockIndex
* @returns {*}
* @private
*/
function
_safeLoadCurrentUD
(
res
,
blockIndex
)
{
// Special case for currency init
if
(
!
res
.
result
.
blocks
.
length
||
blockIndex
<
0
)
{
data
.
currentUD
=
data
.
parameters
?
data
.
parameters
.
ud0
:
-
1
;
return
data
.
currentUD
;
}
else
{
var
lastBlockWithUD
=
res
.
result
.
blocks
[
blockIndex
];
return
BMA
.
blockchain
.
block
({
block
:
lastBlockWithUD
})
.
then
(
function
(
block
){
data
.
currentUD
=
powBase
(
block
.
dividend
,
block
.
unitbase
);
return
data
.
currentUD
;
})
.
catch
(
function
(
err
)
{
console
.
error
(
"
[currency] Unable to load last block with UD, with number {0}
"
.
format
(
lastBlockWithUD
));
if
(
blockIndex
>
0
)
{
console
.
error
(
"
[currency] Retrying to load UD from a previous block...
"
);
return
_safeLoadCurrentUD
(
res
,
blockIndex
-
1
);
}
data
.
currentUD
=
null
;
throw
err
;
});
}
}
function
getData
()
{
...
...
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