@@ -2,6 +2,7 @@ use actix::prelude::*;
2
2
use anyhow:: { anyhow, Error } ;
3
3
use futures:: { FutureExt , StreamExt , TryFutureExt } ;
4
4
use ya_client:: net:: NetApi ;
5
+ use ya_core_model:: NodeId ;
5
6
6
7
use std:: convert:: TryFrom ;
7
8
use std:: path:: { Path , PathBuf } ;
@@ -28,7 +29,9 @@ use crate::market::provider_market::{OfferKind, Shutdown as MarketShutdown, Unsu
28
29
use crate :: market:: { CreateOffer , Preset , PresetManager , ProviderMarket } ;
29
30
use crate :: payments:: { AccountView , LinearPricingOffer , Payments , PricingOffer } ;
30
31
use crate :: rules:: RulesManager ;
31
- use crate :: startup_config:: { FileMonitor , NodeConfig , ProviderConfig , RunConfig } ;
32
+ use crate :: startup_config:: {
33
+ FileMonitor , PaymentPlatform , NodeConfig , ProviderConfig , RunConfig ,
34
+ } ;
32
35
use crate :: tasks:: task_manager:: { InitializeTaskManager , TaskManager } ;
33
36
34
37
struct GlobalsManager {
@@ -77,9 +80,9 @@ pub struct ProviderAgent {
77
80
task_manager : Addr < TaskManager > ,
78
81
presets : PresetManager ,
79
82
hardware : hardware:: Manager ,
80
- accounts : Vec < AccountView > ,
83
+ account : NodeId ,
81
84
log_handler : LoggerHandle ,
82
- networks : Vec < NetworkName > ,
85
+ networks : Vec < PaymentPlatform > ,
83
86
rulestore_monitor : FileMonitor ,
84
87
keystore_monitor : FileMonitor ,
85
88
whitelist_monitor : FileMonitor ,
@@ -116,14 +119,8 @@ impl ProviderAgent {
116
119
let api = ProviderApi :: try_from ( & args. api ) ?;
117
120
118
121
log:: info!( "Loading payment accounts..." ) ;
119
- let accounts: Vec < AccountView > = api
120
- . payment
121
- . get_provider_accounts ( )
122
- . await ?
123
- . into_iter ( )
124
- . map ( Into :: into)
125
- . collect ( ) ;
126
- log:: info!( "Payment accounts: {:#?}" , accounts) ;
122
+ let account = api. identity . me ( ) . await ?. identity ;
123
+ log:: info!( "Payment account: {:#?}" , account) ;
127
124
let registry = config. registry ( ) ?;
128
125
registry. validate ( ) ?;
129
126
registry. test_runtimes ( & data_dir) . await ?;
@@ -149,7 +146,7 @@ impl ProviderAgent {
149
146
150
147
let networks = args. node . account . networks . clone ( ) ;
151
148
for n in networks. iter ( ) {
152
- let net_color = match n {
149
+ let net_color = match n. network {
153
150
NetworkName :: Mainnet => yansi:: Color :: Magenta ,
154
151
NetworkName :: Polygon => yansi:: Color :: Magenta ,
155
152
NetworkName :: Rinkeby => yansi:: Color :: Cyan ,
@@ -158,7 +155,7 @@ impl ProviderAgent {
158
155
NetworkName :: Holesky => yansi:: Color :: Cyan ,
159
156
_ => yansi:: Color :: Red ,
160
157
} ;
161
- log:: info!( "Using payment network: {}" , net_color. paint( & n) ) ;
158
+ log:: info!( "Using payment network: {}" , net_color. paint( & n. network ) ) ;
162
159
}
163
160
164
161
let mut globals = GlobalsManager :: try_new ( & config. globals_file , args. node ) ?;
@@ -186,7 +183,7 @@ impl ProviderAgent {
186
183
task_manager,
187
184
presets,
188
185
hardware,
189
- accounts ,
186
+ account ,
190
187
log_handler,
191
188
networks,
192
189
rulestore_monitor,
@@ -317,56 +314,21 @@ impl ProviderAgent {
317
314
. support_multi_activity ( true ) )
318
315
}
319
316
320
- fn accounts ( & self , networks : & Vec < NetworkName > ) -> anyhow:: Result < Vec < AccountView > > {
317
+ fn accounts ( & self , networks : & Vec < PaymentPlatform > ) -> anyhow:: Result < Vec < AccountView > > {
321
318
let globals = self . globals . get_state ( ) ;
322
- if let Some ( address) = & globals. account {
323
- log:: info!(
324
- "Filtering payment accounts by address={} and networks={:?}" ,
325
- address,
326
- networks,
327
- ) ;
328
- let accounts: Vec < AccountView > = self
329
- . accounts
330
- . iter ( )
331
- . filter ( |acc| & acc. address == address && networks. contains ( & acc. network ) )
332
- . cloned ( )
333
- . collect ( ) ;
334
-
335
- if accounts. is_empty ( ) {
336
- anyhow:: bail!(
337
- "Payment account {} not initialized. Please run\n \
338
- \t `yagna payment init --receiver --network {} --account {}`\n \
339
- for all drivers you want to use.",
340
- address,
341
- networks[ 0 ] ,
342
- address,
343
- )
344
- }
345
319
346
- Ok ( accounts)
347
- } else {
348
- log:: debug!( "Filtering payment accounts by networks={:?}" , networks) ;
349
- let accounts: Vec < AccountView > = self
350
- . accounts
351
- . iter ( )
352
- // FIXME: this is dirty fix -- we can get more that one address from this filter
353
- // FIXME: use /me endpoint and filter out only accounts bound to given app-key
354
- // FIXME: or introduce param to getProviderAccounts to filter out external account above
355
- . filter ( |acc| networks. contains ( & acc. network ) )
356
- . cloned ( )
357
- . collect ( ) ;
358
-
359
- if accounts. is_empty ( ) {
360
- anyhow:: bail!(
361
- "Default payment account not initialized. Please run\n \
362
- \t `yagna payment init --receiver --network {}`\n \
363
- for all drivers you want to use.",
364
- networks[ 0 ] ,
365
- )
366
- }
320
+ let account = globals. account . unwrap_or ( self . account ) ;
367
321
368
- Ok ( accounts)
369
- }
322
+ let accounts: Vec < _ > = networks
323
+ . iter ( )
324
+ . map ( |network| AccountView {
325
+ address : account,
326
+ network : network. network . clone ( ) ,
327
+ platform : network. platform ( ) ,
328
+ } )
329
+ . collect ( ) ;
330
+
331
+ Ok ( accounts)
370
332
}
371
333
}
372
334
0 commit comments