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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vincentux
Cesium
Commits
94e4eca3
Commit
94e4eca3
authored
5 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[fix] Update to ECMA 2015
parent
98c816cf
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
dist/desktop
+1
-1
1 addition, 1 deletion
dist/desktop
platforms/android
+1
-1
1 addition, 1 deletion
platforms/android
www/js/services/tx-services.js
+341
-335
341 additions, 335 deletions
www/js/services/tx-services.js
with
343 additions
and
337 deletions
desktop
@
2667bc6e
Compare
be5b9ddb
...
2667bc6e
Subproject commit
be5b9ddbbb88a5a129ec47c0968b9061de3b
fe2
9
Subproject commit
2667bc6efab8ae2393ab57f330c33f7dedf99
fe2
This diff is collapsed.
Click to expand it.
android
@
197e3a8e
Compare
583a19c5
...
197e3a8e
Subproject commit
583a19c5d1733a606e68f72ecbb124ce2d1316cc
Subproject commit
197e3a8e9162548461251a20ba3b99e1fc89c314
This diff is collapsed.
Click to expand it.
www/js/services/tx-services.js
+
341
−
335
View file @
94e4eca3
...
...
@@ -12,37 +12,38 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
BMA
=
BMA
||
defaultBMA
;
var
api
=
new
Api
(
this
,
"
csTx-
"
+
id
)
,
api
=
new
Api
(
this
,
"
csTx-
"
+
id
)
;
_
reduceTxAndPush
=
function
(
pubkey
,
txArray
,
result
,
processedTxMap
,
allowPendings
)
{
function
reduceTxAndPush
(
pubkey
,
txArray
,
result
,
processedTxMap
,
allowPendings
)
{
if
(
!
txArray
||
!
txArray
.
length
)
return
;
// Skip if empty
_
.
forEach
(
txArray
,
function
(
tx
)
{
if
(
tx
.
block_number
||
allowPendings
)
{
var
walletIsIssuer
=
false
;
var
otherIssuer
=
tx
.
issuers
.
reduce
(
function
(
issuer
,
res
)
{
if
(
tx
.
block_number
!==
null
||
allowPendings
)
{
let
walletIsIssuer
=
false
;
let
otherIssuer
=
tx
.
issuers
.
reduce
(
function
(
issuer
,
res
)
{
walletIsIssuer
=
walletIsIssuer
||
(
res
===
pubkey
);
return
issuer
+
((
res
!==
pubkey
)
?
'
,
'
+
res
:
''
);
},
''
);
if
(
otherIssuer
.
length
>
0
)
{
otherIssuer
=
otherIssuer
.
substring
(
2
);
}
var
otherReceiver
;
var
outputBase
;
var
sources
=
[];
var
lockedOutputs
;
var
amount
=
tx
.
outputs
.
reduce
(
function
(
sum
,
output
,
noffset
)
{
let
otherReceiver
,
outputBase
,
sources
=
[],
lockedOutputs
;
const
amount
=
tx
.
outputs
.
reduce
(
function
(
sum
,
output
,
noffset
)
{
// FIXME duniter v1.4.13
var
outputArray
=
(
typeof
output
==
'
string
'
)
?
output
.
split
(
'
:
'
,
3
)
:
[
output
.
amount
,
output
.
base
,
output
.
conditions
];
const
outputArray
=
(
typeof
output
==
'
string
'
)
?
output
.
split
(
'
:
'
,
3
)
:
[
output
.
amount
,
output
.
base
,
output
.
conditions
];
outputBase
=
parseInt
(
outputArray
[
1
]);
var
outputAmount
=
powBase
(
parseInt
(
outputArray
[
0
]),
outputBase
);
var
outputCondition
=
outputArray
[
2
];
var
sigMatches
=
BMA
.
regexp
.
TX_OUTPUT_SIG
.
exec
(
outputCondition
);
const
outputAmount
=
powBase
(
parseInt
(
outputArray
[
0
]),
outputBase
);
const
outputCondition
=
outputArray
[
2
];
const
sigMatches
=
BMA
.
regexp
.
TX_OUTPUT_SIG
.
exec
(
outputCondition
);
// Simple unlock condition
if
(
sigMatches
)
{
var
outputPubkey
=
sigMatches
[
1
];
if
(
outputPubkey
==
pubkey
)
{
// output is for the wallet
const
outputPubkey
=
sigMatches
[
1
];
if
(
outputPubkey
==
=
pubkey
)
{
// output is for the wallet
if
(
!
walletIsIssuer
)
{
return
sum
+
outputAmount
;
}
...
...
@@ -54,7 +55,8 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
type
:
'
T
'
,
identifier
:
tx
.
hash
,
noffset
:
noffset
,
consumed
:
false
consumed
:
false
,
conditions
:
outputCondition
});
}
}
...
...
@@ -69,20 +71,19 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
}
// Complex unlock condition, on the issuer pubkey
else
if
(
outputCondition
.
indexOf
(
'
SIG(
'
+
pubkey
+
'
)
'
)
!=
-
1
)
{
var
lockedOutput
=
BMA
.
tx
.
parseUnlockCondition
(
outputCondition
);
else
if
(
outputCondition
.
indexOf
(
'
SIG(
'
+
pubkey
+
'
)
'
)
!=
=
-
1
)
{
const
lockedOutput
=
BMA
.
tx
.
parseUnlockCondition
(
outputCondition
);
if
(
lockedOutput
)
{
// Add a source
// FIXME: should be uncomment when filtering source on transfer()
/*sources.push(angular.merge({
sources
.
push
(
angular
.
merge
({
amount
:
parseInt
(
outputArray
[
0
]),
base
:
outputBase
,
type
:
'
T
'
,
identifier
:
tx
.
hash
,
noffset
:
noffset
,
conditions
:
outputCondition
,
consumed
:
false
},
lockedOutput
));
*/
lockedOutput
.
amount
=
outputAmount
;
lockedOutputs
=
lockedOutputs
||
[];
lockedOutputs
.
push
(
lockedOutput
);
...
...
@@ -99,8 +100,8 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
// Avoid duplicated tx, or tx to him self
var
txKey
=
amount
+
'
:
'
+
tx
.
hash
+
'
:
'
+
time
;
if
(
!
processedTxMap
[
txKey
]
&&
amount
!==
0
)
{
processedTxMap
[
txKey
]
=
true
;
if
(
!
processedTxMap
[
txKey
])
{
processedTxMap
[
txKey
]
=
true
;
// Mark as processed
var
newTx
=
{
time
:
time
,
amount
:
amount
,
...
...
@@ -123,9 +124,10 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
}
}
});
},
}
loadTx
=
function
(
pubkey
,
fromTime
)
{
function
loadTx
(
pubkey
,
fromTime
)
{
return
$q
(
function
(
resolve
,
reject
)
{
var
nowInSec
=
moment
().
utc
().
unix
();
...
...
@@ -138,12 +140,6 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
};
var
processedTxMap
=
{};
var
_reduceTx
=
function
(
res
)
{
_reduceTxAndPush
(
pubkey
,
res
.
history
.
sent
,
tx
.
history
,
processedTxMap
);
_reduceTxAndPush
(
pubkey
,
res
.
history
.
received
,
tx
.
history
,
processedTxMap
);
_reduceTxAndPush
(
pubkey
,
res
.
history
.
sending
,
tx
.
pendings
,
processedTxMap
,
true
/*allow pendings*/
);
_reduceTxAndPush
(
pubkey
,
res
.
history
.
pending
,
tx
.
pendings
,
processedTxMap
,
true
/*allow pendings*/
);
};
var
jobs
=
[
// get current block
...
...
@@ -151,11 +147,18 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
// get pending tx
BMA
.
tx
.
history
.
pending
({
pubkey
:
pubkey
})
.
then
(
_reduceTx
)
.
then
(
function
(
res
)
{
reduceTxAndPush
(
pubkey
,
res
.
history
.
sending
,
tx
.
pendings
,
processedTxMap
,
true
/*allow pendings*/
);
reduceTxAndPush
(
pubkey
,
res
.
history
.
pending
,
tx
.
pendings
,
processedTxMap
,
true
/*allow pendings*/
);
})
];
// get TX history since
if
(
fromTime
!==
'
pending
'
)
{
var
reduceTxFn
=
function
(
res
)
{
reduceTxAndPush
(
pubkey
,
res
.
history
.
sent
,
tx
.
history
,
processedTxMap
,
false
);
reduceTxAndPush
(
pubkey
,
res
.
history
.
received
,
tx
.
history
,
processedTxMap
,
false
);
};
// get TX from a given time
if
(
fromTime
>
0
)
{
...
...
@@ -163,19 +166,20 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
var
sliceTime
=
csSettings
.
data
.
walletHistorySliceSecond
;
fromTime
=
fromTime
-
(
fromTime
%
sliceTime
);
for
(
var
i
=
fromTime
;
i
-
sliceTime
<
nowInSec
;
i
+=
sliceTime
)
{
jobs
.
push
(
BMA
.
tx
.
history
.
times
({
pubkey
:
pubkey
,
from
:
i
,
to
:
i
+
sliceTime
-
1
})
.
then
(
_
reduceTx
)
jobs
.
push
(
BMA
.
tx
.
history
.
times
({
pubkey
:
pubkey
,
from
:
i
,
to
:
i
+
sliceTime
-
1
}
,
true
/*with cache*/
)
.
then
(
reduceTx
Fn
)
);
}
jobs
.
push
(
BMA
.
tx
.
history
.
timesNoCache
({
pubkey
:
pubkey
,
from
:
nowInSec
-
(
nowInSec
%
sliceTime
),
to
:
nowInSec
+
999999999
})
.
then
(
_reduceTx
));
// Last slide: no cache
jobs
.
push
(
BMA
.
tx
.
history
.
times
({
pubkey
:
pubkey
,
from
:
nowInSec
-
(
nowInSec
%
sliceTime
),
to
:
nowInSec
+
999999999
},
false
/*no cache*/
)
.
then
(
reduceTxFn
));
}
// get all TX
else
{
jobs
.
push
(
BMA
.
tx
.
history
.
all
({
pubkey
:
pubkey
})
.
then
(
_
reduceTx
)
.
then
(
reduceTx
Fn
)
);
}
...
...
@@ -226,13 +230,11 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
tx
.
history
.
sort
(
function
(
tx1
,
tx2
)
{
return
(
tx2
.
time
-
tx1
.
time
);
});
tx
.
validating
=
tx
.
history
.
fi
lter
(
function
(
tx
)
{
return
(
tx
.
block_number
>
current
.
number
-
csSettings
.
data
.
blockValidityWindow
);
var
firstValidatedTxIndex
=
tx
.
history
.
fi
ndIndex
(
function
(
tx
){
return
(
tx
.
block_number
<=
current
.
number
-
csSettings
.
data
.
blockValidityWindow
);
});
// remove validating from history
if
(
tx
.
validating
.
length
)
{
tx
.
history
.
splice
(
0
,
tx
.
validating
.
length
);
}
tx
.
validating
=
firstValidatedTxIndex
>
0
?
tx
.
history
.
splice
(
0
,
firstValidatedTxIndex
)
:
[];
tx
.
fromTime
=
fromTime
!==
'
pending
'
&&
fromTime
||
undefined
;
tx
.
toTime
=
tx
.
history
.
length
?
tx
.
history
[
0
].
time
/*=max(tx.time)*/
:
tx
.
fromTime
;
...
...
@@ -241,27 +243,27 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
})
.
catch
(
reject
);
});
},
}
powBase
=
function
(
amount
,
base
)
{
function
powBase
(
amount
,
base
)
{
return
base
<=
0
?
amount
:
amount
*
Math
.
pow
(
10
,
base
);
},
}
addSource
=
function
(
src
,
sources
,
sourcesIndexByKey
)
{
function
addSource
(
src
,
sources
,
sourcesIndexByKey
)
{
var
srcKey
=
src
.
type
+
'
:
'
+
src
.
identifier
+
'
:
'
+
src
.
noffset
;
if
(
angular
.
isUndefined
(
sourcesIndexByKey
[
srcKey
]))
{
sources
.
push
(
src
);
sourcesIndexByKey
[
srcKey
]
=
sources
.
length
-
1
;
}
},
}
addSources
=
function
(
result
,
sources
)
{
function
addSources
(
result
,
sources
)
{
_
(
sources
).
forEach
(
function
(
src
)
{
addSource
(
src
,
result
.
sources
,
result
.
sourcesIndexByKey
);
});
},
}
loadSourcesAndBalance
=
function
(
pubkey
)
{
function
loadSourcesAndBalance
(
pubkey
)
{
return
BMA
.
tx
.
sources
({
pubkey
:
pubkey
})
.
then
(
function
(
res
){
var
data
=
{
...
...
@@ -282,9 +284,9 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
console
.
warn
(
"
[tx] Error while getting sources...
"
,
err
);
throw
err
;
});
},
}
loadData
=
function
(
pubkey
,
fromTime
)
{
function
loadData
(
pubkey
,
fromTime
)
{
var
now
=
Date
.
now
();
return
$q
.
all
([
...
...
@@ -314,7 +316,7 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
// TODO get sources from the issuer ?
}
else
{
_
.
f
orEach
(
tx
.
inputs
,
function
(
input
)
{
_
.
f
ind
(
tx
.
inputs
,
function
(
input
)
{
var
inputKey
=
input
.
split
(
'
:
'
).
slice
(
2
).
join
(
'
:
'
);
var
srcIndex
=
data
.
sourcesIndexByKey
[
inputKey
];
if
(
angular
.
isDefined
(
srcIndex
))
{
...
...
@@ -322,7 +324,7 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
}
else
{
valid
=
false
;
return
fals
e
;
// break
return
tru
e
;
// break
}
});
if
(
tx
.
sources
)
{
// add source output
...
...
@@ -377,16 +379,20 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
console
.
debug
(
'
[tx] TX and sources loaded in
'
+
(
Date
.
now
()
-
now
)
+
'
ms
'
);
return
data
;
});
})
.
catch
(
function
(
err
)
{
console
.
warn
(
"
[tx] Error while getting sources and tx...
"
,
err
);
throw
err
;
});
}
,
}
loadSources
=
function
(
pubkey
)
{
function
loadSources
(
pubkey
)
{
console
.
debug
(
"
[tx] Loading sources for
"
+
pubkey
.
substring
(
0
,
8
));
return
loadData
(
pubkey
,
'
pending
'
);
}
;
}
// Download TX history file
downloadHistoryFile
=
function
(
pubkey
,
options
)
{
function
downloadHistoryFile
(
pubkey
,
options
)
{
options
=
options
||
{};
options
.
fromTime
=
options
.
fromTime
||
-
1
;
...
...
@@ -444,7 +450,7 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
FileSaver
.
saveAs
(
file
,
filename
);
});
});
}
;
}
// Register extension points
api
.
registerEvent
(
'
data
'
,
'
loadUDs
'
);
...
...
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