Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/explorer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export 'src/network/explorer/explorer_api.dart'
InputMerged,
InputUtxo,
Mempool,
StakeRewardsInfo,
MempoolTransactionType,
Miner,
MintInfo,
Expand Down
43 changes: 43 additions & 0 deletions lib/src/network/explorer/explorer_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
22 changes: 17 additions & 5 deletions lib/src/network/explorer/explorer_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,32 @@ class ExplorerClient {
}
}

Future<Map<String, dynamic>> stakes(
Future<List<StakeRewardsInfo?>> stakes(
{String? validator, String? withdrawer}) async {
try {
Map<String, dynamic> params = {};
if (validator != null || withdrawer != null) {
Map<String, dynamic> 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<dynamic>? stakes = (await client
.get(api('network/stakes', params)))['stakes'] as List<dynamic>?;
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}"}');
Expand Down Expand Up @@ -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}"}');
}
Expand Down