Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Breeze
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
Breeze
Commits
5403d689
Commit
5403d689
authored
Sep 26, 2017
by
dev0tion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update API to work with Bitcoin and Stratis
parent
2df97a0d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
27 deletions
+78
-27
api.service.ts
Breeze.UI/src/app/shared/services/api.service.ts
+68
-26
global.service.ts
Breeze.UI/src/app/shared/services/global.service.ts
+10
-1
No files found.
Breeze.UI/src/app/shared/services/api.service.ts
View file @
5403d689
...
@@ -7,6 +7,8 @@ import 'rxjs/add/operator/catch';
...
@@ -7,6 +7,8 @@ import 'rxjs/add/operator/catch';
import
"rxjs/add/observable/interval"
;
import
"rxjs/add/observable/interval"
;
import
'rxjs/add/operator/startWith'
;
import
'rxjs/add/operator/startWith'
;
import
{
GlobalService
}
from
'./global.service'
;
import
{
WalletCreation
}
from
'../classes/wallet-creation'
;
import
{
WalletCreation
}
from
'../classes/wallet-creation'
;
import
{
WalletRecovery
}
from
'../classes/wallet-recovery'
;
import
{
WalletRecovery
}
from
'../classes/wallet-recovery'
;
import
{
WalletLoad
}
from
'../classes/wallet-load'
;
import
{
WalletLoad
}
from
'../classes/wallet-load'
;
...
@@ -20,19 +22,29 @@ import { TransactionSending } from '../classes/transaction-sending';
...
@@ -20,19 +22,29 @@ import { TransactionSending } from '../classes/transaction-sending';
*/
*/
@
Injectable
()
@
Injectable
()
export
class
ApiService
{
export
class
ApiService
{
constructor
(
private
http
:
Http
)
{};
constructor
(
private
http
:
Http
,
private
globalService
:
GlobalService
)
{};
private
mockApiUrl
=
'http://localhost:3000/api'
;
private
webApiUrl
=
'http://localhost:5000/api'
;
private
headers
=
new
Headers
({
'Content-Type'
:
'application/json'
});
private
headers
=
new
Headers
({
'Content-Type'
:
'application/json'
});
private
pollingInterval
=
3000
;
private
pollingInterval
=
3000
;
private
bitcoinApiUrl
=
'http://localhost:5000/api'
;
private
stratisApiUrl
=
'http://localhost:5105/api'
;
private
currentApiUrl
=
'http://localhost:5000/api'
;
private
getCurrentCoin
()
{
let
currentCoin
=
this
.
globalService
.
getCoinName
();
if
(
currentCoin
===
"Bitcoin"
)
{
this
.
currentApiUrl
=
this
.
bitcoinApiUrl
;
}
else
if
(
currentCoin
===
"Stratis"
)
{
this
.
currentApiUrl
=
this
.
stratisApiUrl
;
}
}
/**
/**
* Gets available wallets at the default path
* Gets available wallets at the default path
*/
*/
getWalletFiles
():
Observable
<
any
>
{
getWalletFiles
():
Observable
<
any
>
{
return
this
.
http
return
this
.
http
.
get
(
this
.
web
ApiUrl
+
'/wallet/files'
)
.
get
(
this
.
bitcoin
ApiUrl
+
'/wallet/files'
)
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
...
@@ -40,8 +52,10 @@ export class ApiService {
...
@@ -40,8 +52,10 @@ export class ApiService {
* Create a new wallet.
* Create a new wallet.
*/
*/
createWallet
(
data
:
WalletCreation
):
Observable
<
any
>
{
createWallet
(
data
:
WalletCreation
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
return
this
.
http
return
this
.
http
.
post
(
this
.
web
ApiUrl
+
'/wallet/create/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
post
(
this
.
current
ApiUrl
+
'/wallet/create/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
...
@@ -49,17 +63,28 @@ export class ApiService {
...
@@ -49,17 +63,28 @@ export class ApiService {
* Recover a wallet.
* Recover a wallet.
*/
*/
recoverWallet
(
data
:
WalletRecovery
):
Observable
<
any
>
{
recoverWallet
(
data
:
WalletRecovery
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
return
this
.
http
.
post
(
this
.
currentApiUrl
+
'/wallet/recover/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
map
((
response
:
Response
)
=>
response
);
}
/**
* Load a Bitcoin wallet
*/
loadBitcoinWallet
(
data
:
WalletLoad
):
Observable
<
any
>
{
return
this
.
http
return
this
.
http
.
post
(
this
.
webApiUrl
+
'/wallet/recover
/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
post
(
this
.
bitcoinApiUrl
+
'/wallet/load
/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
/**
/**
* Load a wallet
* Load a
Stratis
wallet
*/
*/
loadWallet
(
data
:
WalletLoad
):
Observable
<
any
>
{
load
Stratis
Wallet
(
data
:
WalletLoad
):
Observable
<
any
>
{
return
this
.
http
return
this
.
http
.
post
(
this
.
web
ApiUrl
+
'/wallet/load/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
post
(
this
.
stratis
ApiUrl
+
'/wallet/load/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
...
@@ -67,8 +92,10 @@ export class ApiService {
...
@@ -67,8 +92,10 @@ export class ApiService {
* Get wallet status info from the API.
* Get wallet status info from the API.
*/
*/
getWalletStatus
():
Observable
<
any
>
{
getWalletStatus
():
Observable
<
any
>
{
this
.
getCurrentCoin
();
return
this
.
http
return
this
.
http
.
get
(
this
.
web
ApiUrl
+
'/wallet/status'
)
.
get
(
this
.
current
ApiUrl
+
'/wallet/status'
)
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
...
@@ -76,13 +103,15 @@ export class ApiService {
...
@@ -76,13 +103,15 @@ export class ApiService {
* Get general wallet info from the API.
* Get general wallet info from the API.
*/
*/
getGeneralInfo
(
data
:
WalletInfo
):
Observable
<
any
>
{
getGeneralInfo
(
data
:
WalletInfo
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
params
.
set
(
'Name'
,
data
.
walletName
);
params
.
set
(
'Name'
,
data
.
walletName
);
return
Observable
return
Observable
.
interval
(
this
.
pollingInterval
)
.
interval
(
this
.
pollingInterval
)
.
startWith
(
0
)
.
startWith
(
0
)
.
switchMap
(()
=>
this
.
http
.
get
(
this
.
web
ApiUrl
+
'/wallet/general-info'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
})))
.
switchMap
(()
=>
this
.
http
.
get
(
this
.
current
ApiUrl
+
'/wallet/general-info'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
})))
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
...
@@ -90,66 +119,79 @@ export class ApiService {
...
@@ -90,66 +119,79 @@ export class ApiService {
* Get wallet balance info from the API.
* Get wallet balance info from the API.
*/
*/
getWalletBalance
(
data
:
WalletInfo
):
Observable
<
any
>
{
getWalletBalance
(
data
:
WalletInfo
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
params
.
set
(
'walletName'
,
data
.
walletName
);
params
.
set
(
'walletName'
,
data
.
walletName
);
return
Observable
return
Observable
.
interval
(
this
.
pollingInterval
)
.
interval
(
this
.
pollingInterval
)
.
startWith
(
0
)
.
startWith
(
0
)
.
switchMap
(()
=>
this
.
http
.
get
(
this
.
web
ApiUrl
+
'/wallet/balance'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
})))
.
switchMap
(()
=>
this
.
http
.
get
(
this
.
current
ApiUrl
+
'/wallet/balance'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
})))
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
// return this.http
// .get(this.webApiUrl + '/wallet/balance', new RequestOptions({headers: this.headers, search: params}))
// .map((response: Response) => response);
}
}
/**
/**
* Get a wallets transaction history info from the API.
* Get a wallets transaction history info from the API.
*/
*/
getWalletHistory
(
data
:
WalletInfo
):
Observable
<
any
>
{
getWalletHistory
(
data
:
WalletInfo
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
params
.
set
(
'walletName'
,
data
.
walletName
);
params
.
set
(
'walletName'
,
data
.
walletName
);
return
Observable
return
Observable
.
interval
(
this
.
pollingInterval
)
.
interval
(
this
.
pollingInterval
)
.
startWith
(
0
)
.
startWith
(
0
)
.
switchMap
(()
=>
this
.
http
.
get
(
this
.
web
ApiUrl
+
'/wallet/history'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
})))
.
switchMap
(()
=>
this
.
http
.
get
(
this
.
current
ApiUrl
+
'/wallet/history'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
})))
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
// return this.http
// .get(this.webApiUrl + '/wallet/history', new RequestOptions({headers: this.headers, search: params}))
// .map((response: Response) => response);
}
}
/**
/**
* Get unused receive addresses for a certain wallet from the API.
* Get unused receive addresses for a certain wallet from the API.
*/
*/
getUnusedReceiveAddress
(
data
:
WalletInfo
):
Observable
<
any
>
{
getUnusedReceiveAddress
(
data
:
WalletInfo
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
let
params
:
URLSearchParams
=
new
URLSearchParams
();
params
.
set
(
'walletName'
,
data
.
walletName
);
params
.
set
(
'walletName'
,
data
.
walletName
);
params
.
set
(
'accountName'
,
"account 0"
);
//temporary
params
.
set
(
'accountName'
,
"account 0"
);
//temporary
return
this
.
http
return
this
.
http
.
get
(
this
.
web
ApiUrl
+
'/wallet/address'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
}))
.
get
(
this
.
current
ApiUrl
+
'/wallet/address'
,
new
RequestOptions
({
headers
:
this
.
headers
,
search
:
params
}))
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
/**
* Build a transaction
*/
buildTransaction
(
data
:
TransactionBuilding
):
Observable
<
any
>
{
buildTransaction
(
data
:
TransactionBuilding
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
return
this
.
http
return
this
.
http
.
post
(
this
.
web
ApiUrl
+
'/wallet/build-transaction/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
post
(
this
.
current
ApiUrl
+
'/wallet/build-transaction/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
/**
* Send transaction
*/
sendTransaction
(
data
:
TransactionSending
):
Observable
<
any
>
{
sendTransaction
(
data
:
TransactionSending
):
Observable
<
any
>
{
this
.
getCurrentCoin
();
return
this
.
http
return
this
.
http
.
post
(
this
.
web
ApiUrl
+
'/wallet/send-transaction/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
post
(
this
.
current
ApiUrl
+
'/wallet/send-transaction/'
,
JSON
.
stringify
(
data
),
{
headers
:
this
.
headers
})
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
/**
* Send shutdown signal to the daemon
*/
shutdownNode
():
Observable
<
any
>
{
shutdownNode
():
Observable
<
any
>
{
this
.
getCurrentCoin
();
return
this
.
http
return
this
.
http
.
post
(
this
.
web
ApiUrl
+
'/node/shutdown'
,
''
)
.
post
(
this
.
current
ApiUrl
+
'/node/shutdown'
,
''
)
.
map
((
response
:
Response
)
=>
response
);
.
map
((
response
:
Response
)
=>
response
);
}
}
}
}
Breeze.UI/src/app/shared/services/global.service.ts
View file @
5403d689
...
@@ -6,7 +6,8 @@ export class GlobalService {
...
@@ -6,7 +6,8 @@ export class GlobalService {
private
walletPath
:
string
;
private
walletPath
:
string
;
private
currentWalletName
:
string
;
private
currentWalletName
:
string
;
private
coinType
:
number
;
private
coinType
:
number
=
0
;
private
coinName
:
string
=
"Bitcoin"
;
getWalletPath
()
{
getWalletPath
()
{
return
this
.
walletPath
;
return
this
.
walletPath
;
...
@@ -35,4 +36,12 @@ export class GlobalService {
...
@@ -35,4 +36,12 @@ export class GlobalService {
setCoinType
(
coinType
:
number
)
{
setCoinType
(
coinType
:
number
)
{
this
.
coinType
=
coinType
;
this
.
coinType
=
coinType
;
}
}
getCoinName
()
{
return
this
.
coinName
;
}
setCoinName
(
coinName
:
string
)
{
this
.
coinName
=
coinName
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment