Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cesium2s
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
clients
Cesium-grp
cesium2s
Commits
814b71c8
Commit
814b71c8
authored
1 year ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
formatting and fix
addV2Account arg type missing fields in currency in network service
parent
0cd5f384
Branches
hugo-dev
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/network/network.service.ts
+78
-52
78 additions, 52 deletions
src/app/network/network.service.ts
src/app/wallet/account.service.ts
+2
-7
2 additions, 7 deletions
src/app/wallet/account.service.ts
with
80 additions
and
59 deletions
src/app/network/network.service.ts
+
78
−
52
View file @
814b71c8
import
{
Injectable
}
from
"
@angular/core
"
;
import
{
ApiPromise
,
WsProvider
}
from
"
@polkadot/api
"
;
import
{
SettingsService
}
from
"
../settings/settings.service
"
;
import
{
Peer
,
Peers
}
from
"
./peer.model
"
;
import
{
StartableService
}
from
"
@app/shared/services/startable-service.class
"
;
import
{
abbreviate
}
from
"
@app/shared/currencies
"
;
import
{
Currency
}
from
"
@app/network/currency.model
"
;
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
ApiPromise
,
WsProvider
}
from
'
@polkadot/api
'
;
import
{
SettingsService
}
from
'
../settings/settings.service
'
;
import
{
Peer
,
Peers
}
from
'
./peer.model
'
;
import
{
StartableService
}
from
'
@app/shared/services/startable-service.class
'
;
import
{
abbreviate
}
from
'
@app/shared/currencies
'
;
import
{
Currency
}
from
'
@app/network/currency.model
'
;
//import * as definitions from '@duniter/core-types/interfaces'
const
WELL_KNOWN_CURRENCIES
=
Object
.
freeze
({
'
Ğdev
'
:
<
Partial
<
Currency
>>
{
network
:
"
gdev
"
,
Ğdev
:
<
Partial
<
Currency
>>
{
network
:
'
gdev
'
,
displayName
:
'
Ğdev
'
,
symbol
:
'
GD
'
,
prefix
:
42
,
genesis
:
'
0x9f956a87b5568f12c757bb3426897bba6123a1ef311fcd0945bd669fd0e612f8
'
,
genesis
:
'
0x9f956a87b5568f12c757bb3426897bba6123a1ef311fcd0945bd669fd0e612f8
'
,
fees
:
{
identity
:
300
,
// = 3 Gdev
tx
:
1
// = 0.01 Gdev
tx
:
1
,
// = 0.01 Gdev
},
decimals
:
2
decimals
:
2
,
},
'
Ğ1
'
:
<
Partial
<
Currency
>>
{
network
:
"
g1
"
,
Ğ1
:
<
Partial
<
Currency
>>
{
network
:
'
g1
'
,
displayName
:
'
Ğ1
'
,
symbol
:
'
G1
'
,
prefix
:
4450
,
genesis
:
'
0x___TODO___
'
,
fees
:
{
identity
:
300
,
// = 3G1 - FIXME
tx
:
1
// = 0.01 G1 - FIXME
tx
:
1
,
// = 0.01 G1 - FIXME
},
decimals
:
2
// FIXME remove for autodetection
}
decimals
:
2
,
// FIXME remove for autodetection
}
,
});
@
Injectable
({
providedIn
:
'
root
'
})
@
Injectable
({
providedIn
:
'
root
'
})
export
class
NetworkService
extends
StartableService
<
ApiPromise
>
{
currency
=
<
Currency
>
{
network
:
null
,
displayName
:
null
,
symbol
:
null
,
genesis
:
null
}
prefix
:
null
,
genesis
:
null
,
fees
:
{
identity
:
null
,
tx
:
null
},
decimals
:
null
,
};
get
api
():
ApiPromise
{
return
this
.
_data
;
...
...
@@ -51,11 +55,9 @@ export class NetworkService extends StartableService<ApiPromise> {
return
this
.
currency
.
symbol
||
''
;
}
constructor
(
private
settings
:
SettingsService
)
{
constructor
(
private
settings
:
SettingsService
)
{
super
(
settings
,
{
name
:
'
network-service
'
name
:
'
network-service
'
,
});
}
...
...
@@ -64,12 +66,12 @@ export class NetworkService extends StartableService<ApiPromise> {
const
peers
=
await
this
.
filterAliveNodes
(
settings
.
preferredPeers
);
if
(
!
peers
.
length
)
{
throw
{
message
:
'
ERROR.CHECK_NETWORK_CONNECTION
'
};
throw
{
message
:
'
ERROR.CHECK_NETWORK_CONNECTION
'
};
}
const
peer
=
this
.
selectRandomPeer
(
peers
);
const
wsUri
=
Peers
.
getWsUri
(
peer
);
console
.
info
(
`
${
this
.
_logPrefix
}
Connecting to peer {
${
wsUri
}
}...`
)
console
.
info
(
`
${
this
.
_logPrefix
}
Connecting to peer {
${
wsUri
}
}...`
)
;
// Extract all types from definitions - fast and dirty approach, flatted on 'types'
// const types = Object.values(definitions).reduce((res: any, { types }): object => {
...
...
@@ -80,7 +82,7 @@ export class NetworkService extends StartableService<ApiPromise> {
// Construct
const
wsProvider
=
new
WsProvider
(
wsUri
);
const
api
=
await
ApiPromise
.
create
({
provider
:
wsProvider
provider
:
wsProvider
,
//,...types
});
...
...
@@ -89,53 +91,77 @@ export class NetworkService extends StartableService<ApiPromise> {
const
chain
=
''
+
(
await
api
.
rpc
.
system
.
chain
());
const
genesis
=
api
.
genesisHash
.
toHex
();
console
.
info
(
`
${
this
.
_logPrefix
}
Connecting to chain {
${
chain
}
}: `
,
chainInfo
.
toHuman
());
console
.
info
(
`
${
this
.
_logPrefix
}
Connecting to chain {
${
chain
}
}: `
,
chainInfo
.
toHuman
()
);
// Check is well known currency
if
(
WELL_KNOWN_CURRENCIES
[
chain
])
{
const
wellKnownCurrency
=
WELL_KNOWN_CURRENCIES
[
chain
];
if
(
wellKnownCurrency
.
genesis
&&
wellKnownCurrency
.
genesis
!==
genesis
)
{
console
.
warn
(
`
${
this
.
_logPrefix
}
Invalid genesis for
${
chain
}
! Expected
${
wellKnownCurrency
.
genesis
}
but peer return
${
genesis
}
`
);
}
else
{
console
.
warn
(
`
${
this
.
_logPrefix
}
Invalid genesis for
${
chain
}
! Expected
${
wellKnownCurrency
.
genesis
}
but peer return
${
genesis
}
`
);
}
else
{
this
.
currency
=
WELL_KNOWN_CURRENCIES
[
chain
];
}
}
this
.
currency
.
displayName
=
this
.
currency
.
displayName
||
chain
;
this
.
currency
.
symbol
=
this
.
currency
.
symbol
||
chainInfo
.
tokenSymbol
.
value
?.[
0
].
toHuman
()
||
abbreviate
(
this
.
currency
.
displayName
);
this
.
currency
.
decimals
=
this
.
currency
.
decimals
||
+
(
chainInfo
.
tokenDecimals
.
value
?.[
0
].
toHuman
())
||
0
;
this
.
currency
.
symbol
=
this
.
currency
.
symbol
||
chainInfo
.
tokenSymbol
.
value
?.[
0
].
toHuman
()
||
abbreviate
(
this
.
currency
.
displayName
);
this
.
currency
.
decimals
=
this
.
currency
.
decimals
||
+
chainInfo
.
tokenDecimals
.
value
?.[
0
].
toHuman
()
||
0
;
// Read the genesis block hash
console
.
debug
(
`
${
this
.
_logPrefix
}
Blockchain symbol:
${
this
.
currency
.
symbol
}
`
);
console
.
debug
(
`
${
this
.
_logPrefix
}
Blockchain decimals:
${
this
.
currency
.
decimals
}
`
);
console
.
debug
(
`
${
this
.
_logPrefix
}
Blockchain symbol:
${
this
.
currency
.
symbol
}
`
);
console
.
debug
(
`
${
this
.
_logPrefix
}
Blockchain decimals:
${
this
.
currency
.
decimals
}
`
);
console
.
debug
(
`
${
this
.
_logPrefix
}
Blockchain genesis:
${
genesis
}
`
);
// Retrieve the latest header
const
lastHeader
=
await
api
.
rpc
.
chain
.
getHeader
();
console
.
info
(
`
${
this
.
_logPrefix
}
Last block: #
${
lastHeader
.
number
}
- hash
${
lastHeader
.
hash
}
`
);
console
.
info
(
`
${
this
.
_logPrefix
}
Last block: #
${
lastHeader
.
number
}
- hash
${
lastHeader
.
hash
}
`
);
return
api
;
}
async
filterAliveNodes
(
peers
:
string
[],
opts
?:
{
timeout
?:
number
;
}):
Promise
<
Peer
[]
>
{
const
result
:
Peer
[]
=
[];
await
Promise
.
all
(
peers
.
map
(
peer
=>
Peers
.
fromUri
(
peer
))
.
map
(
peer
=>
this
.
isPeerAlive
(
peer
)
.
then
(
alive
=>
{
async
filterAliveNodes
(
peers
:
string
[],
opts
?:
{
timeout
?:
number
;
}
):
Promise
<
Peer
[]
>
{
const
result
:
Peer
[]
=
[];
await
Promise
.
all
(
peers
.
map
((
peer
)
=>
Peers
.
fromUri
(
peer
))
.
map
((
peer
)
=>
this
.
isPeerAlive
(
peer
).
then
((
alive
)
=>
{
if
(
!
alive
)
return
;
result
.
push
(
peer
);
}))
);
return
result
;
})
)
);
return
result
;
}
async
isPeerAlive
(
peer
:
Peer
,
opts
?:
{
timeout
?:
number
;
}):
Promise
<
boolean
>
{
// TODO
async
isPeerAlive
(
peer
:
Peer
,
opts
?:
{
timeout
?:
number
;
}
):
Promise
<
boolean
>
{
// TODO
return
Promise
.
resolve
(
true
);
}
...
...
This diff is collapsed.
Click to expand it.
src/app/wallet/account.service.ts
+
2
−
7
View file @
814b71c8
...
...
@@ -303,16 +303,11 @@ export class AccountService extends StartableService {
return
true
;
}
async
addV2Account
(
data
:
RegisterData
):
Promise
<
Account
>
{
// add the account, encrypt the stored JSON with an account-specific password
const
{
pair
,
json
}
=
keyring
.
addUri
(
data
.
mnemonic
,
data
.
password
,
{
async
addV2Account
(
data
:
{
mnemonic
:
string
;
meta
?:
AccountMeta
}):
Promise
<
Account
>
{
const
{
pair
,
json
}
=
keyring
.
addUri
(
data
.
mnemonic
,
this
.
_password
,
{
name
:
data
.
meta
?.
name
||
'
default
'
,
genesisHash
:
this
.
network
.
currency
?.
genesis
},
'
sr25519
'
);
//this.debug('check pair', pair, json);
return
this
.
addAccount
({
address
:
json
.
address
,
meta
:
{
...
...
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