Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Cesium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
Cesium-grp
Cesium
Commits
3776e3ec
Commit
3776e3ec
authored
8 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
- Currency : begin to display peers BEFORE sort end
parent
a8b42aa9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
www/js/controllers/currency-controllers.js
+110
-6
110 additions, 6 deletions
www/js/controllers/currency-controllers.js
www/js/services/network-services.js
+13
-4
13 additions, 4 deletions
www/js/services/network-services.js
with
123 additions
and
10 deletions
www/js/controllers/currency-controllers.js
+
110
−
6
View file @
3776e3ec
...
...
@@ -91,7 +91,7 @@ function CurrencyLookupController($scope, $state, UIUtils, csCurrency) {
};
}
function
CurrencyViewController
(
$scope
,
$q
,
$translate
,
BMA
,
UIUtils
,
csSettings
,
csCurrency
,
csNetwork
)
{
function
CurrencyViewController
(
$scope
,
$q
,
$translate
,
$timeout
,
BMA
,
UIUtils
,
csSettings
,
csCurrency
,
csNetwork
)
{
$scope
.
loadingPeers
=
true
;
$scope
.
formData
=
{
...
...
@@ -138,20 +138,124 @@ function CurrencyViewController($scope, $q, $translate, BMA, UIUtils, csSettings
csNetwork
.
close
();
});
$scope
.
checkLoadingPeers
=
function
()
{
if
(
!
csNetwork
.
data
.
updatingPeers
)
{
$scope
.
loadingPeers
=
false
;
}
else
{
$timeout
(
function
(){
$scope
.
checkLoadingPeers
();
},
1000
);
}
};
$scope
.
load
=
function
(
currency
)
{
$scope
.
name
=
currency
.
name
;
$scope
.
node
=
!
BMA
.
node
.
same
(
currency
.
peer
.
host
,
currency
.
peer
.
port
)
?
BMA
.
instance
(
currency
.
peer
.
host
,
currency
.
peer
.
port
)
:
BMA
;
UIUtils
.
loading
.
show
();
if
(
$scope
.
loadingPeers
){
csNetwork
.
start
(
$scope
.
node
,
$scope
)
csNetwork
.
start
(
$scope
.
node
,
true
/*no wait*/
)
.
then
(
function
(
peers
)
{
$scope
.
peers
=
peers
;
$scope
.
loadingPeers
=
false
;
$scope
.
checkLoadingPeers
();
});
$scope
.
$on
(
'
$destroy
'
,
function
(){
csNetwork
.
close
();
});
}
$scope
.
loadParameter
();
};
$scope
.
loadParameter
=
function
()
{
if
(
!
$scope
.
node
)
{
return
;
}
var
M
;
return
$q
.
all
([
// Get the currency parameters
$scope
.
node
.
blockchain
.
parameters
()
.
then
(
function
(
json
){
$scope
.
currency
=
json
.
currency
;
$scope
.
c
=
json
.
c
;
$scope
.
dt
=
json
.
dt
;
$scope
.
sigQty
=
json
.
sigQty
;
}),
// Get the current block informations
$scope
.
node
.
blockchain
.
current
()
.
then
(
function
(
block
){
M
=
block
.
monetaryMass
;
$scope
.
N
=
block
.
membersCount
;
$scope
.
time
=
moment
(
block
.
medianTime
*
1000
).
format
(
$scope
.
datePattern
);
$scope
.
difficulty
=
block
.
powMin
;
}),
// Get the UD informations
$scope
.
node
.
blockchain
.
stats
.
ud
()
.
then
(
function
(
res
){
if
(
res
.
result
.
blocks
.
length
)
{
var
lastBlockWithUD
=
res
.
result
.
blocks
[
res
.
result
.
blocks
.
length
-
1
];
return
$scope
.
node
.
blockchain
.
block
({
block
:
lastBlockWithUD
})
.
then
(
function
(
block
){
$scope
.
currentUD
=
(
block
.
unitbase
>
0
)
?
block
.
dividend
*
Math
.
pow
(
10
,
block
.
unitbase
)
:
block
.
dividend
;
$scope
.
Nprev
=
block
.
membersCount
;
});
}
})
])
// Done
.
then
(
function
(){
var
Mprev
=
M
-
$scope
.
currentUD
*
$scope
.
Nprev
;
// remove fresh money
var
MoverN
=
Mprev
/
$scope
.
Nprev
;
$scope
.
cactual
=
100
*
$scope
.
currentUD
/
MoverN
;
if
(
$scope
.
formData
.
useRelative
)
{
$scope
.
M
=
Mprev
/
$scope
.
currentUD
;
$scope
.
MoverN
=
MoverN
/
$scope
.
currentUD
;
$scope
.
UD
=
1
;
}
else
{
$scope
.
M
=
Mprev
;
$scope
.
MoverN
=
MoverN
;
$scope
.
UD
=
$scope
.
currentUD
;
}
// Set Ink
UIUtils
.
ink
({
selector
:
'
.peer-item
'
});
$scope
.
loading
=
false
;
UIUtils
.
loading
.
hide
();
})
.
catch
(
function
(
err
)
{
$scope
.
loading
=
false
;
UIUtils
.
onError
(
'
ERROR.LOAD_NODE_DATA_FAILED
'
)(
err
);
})
};
$scope
.
refresh
=
function
()
{
UIUtils
.
loading
.
show
();
$scope
.
loadParameter
()
.
then
(
function
(){
// Network
$scope
.
loadingPeers
=
true
;
$scope
.
peers
=
csNetwork
.
getPeers
();
csNetwork
.
refreshPeers
(
true
)
.
then
(
function
()
{
$scope
.
checkLoadingPeers
();
})
.
catch
(
function
(
err
)
{
$scope
.
loadingPeers
=
false
;
});
});
}
$scope
.
onUseRelativeChanged
=
function
()
{
if
(
$scope
.
loading
)
return
;
if
(
$scope
.
formData
.
useRelative
)
{
...
...
@@ -239,9 +343,9 @@ function CurrencyViewController($scope, $q, $translate, BMA, UIUtils, csSettings
// Network
$scope
.
loadingPeers
=
true
;
$scope
.
peers
=
csNetwork
.
getPeers
();
csNetwork
.
refreshPeers
()
csNetwork
.
refreshPeers
(
true
)
.
then
(
function
()
{
$scope
.
l
oadingPeers
=
false
;
$scope
.
checkL
oadingPeers
()
;
})
.
catch
(
function
(
err
)
{
$scope
.
loadingPeers
=
false
;
...
...
This diff is collapsed.
Click to expand it.
www/js/services/network-services.js
+
13
−
4
View file @
3776e3ec
...
...
@@ -121,21 +121,29 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
}
},
refreshPeers
=
function
()
{
refreshPeers
=
function
(
doNotWaitAllPeers
)
{
return
$q
(
function
(
resolve
,
reject
){
if
(
interval
)
{
$interval
.
cancel
(
interval
);
}
var
resolved
=
false
;
interval
=
$interval
(
function
()
{
if
(
data
.
newPeers
.
length
)
{
data
.
peers
=
data
.
peers
.
concat
(
data
.
newPeers
.
splice
(
0
));
sortPeers
();
if
(
doNotWaitAllPeers
)
{
resolved
=
true
;
resolve
(
data
.
peers
);
}
}
else
if
(
data
.
updatingPeers
&&
!
data
.
searchingPeersOnNetwork
)
{
// The peer lookup endend, we can make a clean final report
sortPeers
();
data
.
updatingPeers
=
false
;
if
(
!
resolved
)
{
resolve
(
data
.
peers
);
}
$interval
.
cancel
(
interval
);
}
},
1000
);
...
...
@@ -192,14 +200,14 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
});
},
start
=
function
(
bma
,
$scope
)
{
start
=
function
(
bma
,
doNotWaitAllPeers
)
{
return
$q
(
function
(
resolve
,
reject
)
{
close
();
data
.
bma
=
bma
?
bma
:
BMA
;
console
.
info
(
'
[network] Starting network [
'
+
bma
.
node
.
server
+
'
]
'
);
var
now
=
new
Date
();
startListeningOnSocket
(
resolve
,
reject
);
refreshPeers
()
refreshPeers
(
doNotWaitAllPeers
)
.
then
(
function
(
peers
){
resolve
(
peers
);
console
.
debug
(
'
[network] Started in
'
+
(
new
Date
().
getTime
()
-
now
.
getTime
())
+
'
ms
'
);
...
...
@@ -264,6 +272,7 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
close
:
close
,
hasPeers
:
hasPeers
,
getPeers
:
getPeers
,
getTrustedPeers
:
getTrustedPeers
,
getKnownBlocks
:
getKnownBlocks
,
getMainBlockUid
:
getMainBlockUid
,
refreshPeers
:
refreshPeers
,
...
...
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