diff --git a/lib/explorer.dart b/lib/explorer.dart index 85b35ec..640edf1 100644 --- a/lib/explorer.dart +++ b/lib/explorer.dart @@ -28,6 +28,7 @@ export 'src/network/explorer/explorer_api.dart' InputMerged, InputUtxo, Mempool, + StakeRewardsInfo, MempoolTransactionType, Miner, MintInfo, diff --git a/lib/src/network/explorer/explorer_api.dart b/lib/src/network/explorer/explorer_api.dart index 9813efc..32cd7c2 100644 --- a/lib/src/network/explorer/explorer_api.dart +++ b/lib/src/network/explorer/explorer_api.dart @@ -2774,3 +2774,46 @@ class Mempool { "amount": amount, }; } + +class StakeRewardsInfo { + int blocks; + int currentStake; + int dataRequests; + int genesis; + int lastActive; + int lies; + int nonce; + int rewards; + int timeWeightedStake; + String validator; + String withdrawer; + + StakeRewardsInfo({ + required this.blocks, + required this.currentStake, + required this.dataRequests, + required this.genesis, + required this.lastActive, + required this.lies, + required this.nonce, + required this.rewards, + required this.timeWeightedStake, + required this.validator, + required this.withdrawer, + }); + + factory StakeRewardsInfo.fromJson(data) { + return StakeRewardsInfo( + blocks: data['blocks'], + currentStake: data['current_stake'], + dataRequests: data['data_requests'], + genesis: data['genesis'], + lastActive: data['last_active'], + lies: data['lies'], + nonce: data['nonce'], + rewards: data['rewards'], + timeWeightedStake: data['time_weighted_stake'], + validator: data['validator'], + withdrawer: data['withdrawer']); + } +} diff --git a/lib/src/network/explorer/explorer_client.dart b/lib/src/network/explorer/explorer_client.dart index 34e11ce..fbac234 100644 --- a/lib/src/network/explorer/explorer_client.dart +++ b/lib/src/network/explorer/explorer_client.dart @@ -317,21 +317,32 @@ class ExplorerClient { } } - Future> stakes( + Future> stakes( {String? validator, String? withdrawer}) async { try { + Map params = {}; if (validator != null || withdrawer != null) { - Map params = {}; - if (validator != null && validator.isNotEmpty) { params['validator'] = validator; } if (withdrawer != null && withdrawer.isNotEmpty) { params['withdrawer'] = withdrawer; } - return await client.get(api('network/stakes', params)); } - return await client.get(api('network/stakes')); + dynamic result = await client.get(api('network/stakes', params)); + if (result != null) { + List? stakes = (await client + .get(api('network/stakes', params)))['stakes'] as List?; + if (stakes != null) { + return stakes + .map((result) => StakeRewardsInfo.fromJson(result)) + .toList(); + } else { + return []; + } + } else { + return []; + } } on ExplorerException catch (e) { throw ExplorerException( code: e.code, message: '{"stakes": "${e.message}"}'); @@ -698,6 +709,7 @@ class ExplorerClient { return PrioritiesEstimate.fromJson( await client.get(api('transaction/priority', {"key": "vtt"}))); } on ExplorerException catch (e) { + print(e); throw ExplorerException( code: e.code, message: '{"priority": "${e.message}"}'); }