Skip to content

Commit

Permalink
update grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
x100111010 committed Oct 22, 2024
1 parent e2fce70 commit 305dc2d
Show file tree
Hide file tree
Showing 19 changed files with 8,922 additions and 8,806 deletions.
2 changes: 1 addition & 1 deletion lib/core/core_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ final spectreClientProvider = Provider((ref) {
});

final balancesForAddressesProvider = FutureProvider.family
.autoDispose<Iterable<BalancesByAddressEntry>, List<String>>(
.autoDispose<Iterable<RpcBalancesByAddressesEntry>, List<String>>(
(ref, addresses) async {
final client = ref.watch(spectreClientProvider);
final balance = await client.getBalancesByAddresses(addresses);
Expand Down
88 changes: 43 additions & 45 deletions lib/spectre/client/spectre_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class VoidSpectreClient extends SpectreClient {
);

@override
Future<SpectredMessage> _singleRequest(SpectredMessage message) async {
return SpectredMessage();
Future<SpectredResponse> _singleRequest(SpectredRequest message) async {
return SpectredResponse();
}

@override
Stream<SpectredMessage> _streamRequest(SpectredMessage message) {
return StreamController<SpectredMessage>().stream;
Stream<SpectredResponse> _streamRequest(SpectredRequest message) {
return StreamController<SpectredResponse>().stream;
}

@override
Expand Down Expand Up @@ -75,8 +75,8 @@ class SpectreClient {

Future<void> terminate() => channel.terminate();

Future<SpectredMessage> _singleRequest(SpectredMessage message) async {
final request = StreamController<SpectredMessage>();
Future<SpectredResponse> _singleRequest(SpectredRequest message) async {
final request = StreamController<SpectredRequest>();
final response = rpcClient.messageStream(request.stream);

request.sink.add(message);
Expand All @@ -88,19 +88,19 @@ class SpectreClient {
return result;
}

Stream<SpectredMessage> _streamRequest(SpectredMessage message) {
final request = StreamController<SpectredMessage>();
Stream<SpectredResponse> _streamRequest(SpectredRequest message) {
final request = StreamController<SpectredRequest>();
final response = rpcClient.messageStream(request.stream);

request.sink.add(message);

return response;
}

Future<List<BalancesByAddressEntry>> getBalancesByAddresses(
Future<List<RpcBalancesByAddressesEntry>> getBalancesByAddresses(
Iterable<String> addresses,
) async {
final message = SpectredMessage(
final message = SpectredRequest(
getBalancesByAddressesRequest: GetBalancesByAddressesRequestMessage(
addresses: addresses,
),
Expand All @@ -114,10 +114,10 @@ class SpectreClient {
return response.getBalancesByAddressesResponse.entries;
}

Future<List<UtxosByAddressesEntry>> getUtxosByAddresses(
Future<List<RpcUtxosByAddressesEntry>> getUtxosByAddresses(
Iterable<String> addresses,
) async {
final message = SpectredMessage(
final message = SpectredRequest(
getUtxosByAddressesRequest: GetUtxosByAddressesRequestMessage(
addresses: addresses,
),
Expand All @@ -135,7 +135,7 @@ class SpectreClient {
Stream<UtxosChangedNotificationMessage> notifyUtxosChanged(
Iterable<String> addresses,
) {
final message = SpectredMessage(
final message = SpectredRequest(
notifyUtxosChangedRequest: NotifyUtxosChangedRequestMessage(
addresses: addresses,
),
Expand All @@ -155,7 +155,7 @@ class SpectreClient {
}

Future<void> stopNotifyingUtxosChanged(List<String> addresses) async {
final message = SpectredMessage(
final message = SpectredRequest(
stopNotifyingUtxosChangedRequest: StopNotifyingUtxosChangedRequestMessage(
addresses: addresses,
),
Expand All @@ -171,7 +171,7 @@ class SpectreClient {
// Block Notifications

Stream<BlockAddedNotificationMessage> notifyBlockAdded() {
final message = SpectredMessage(
final message = SpectredRequest(
notifyBlockAddedRequest: NotifyBlockAddedRequestMessage(),
);

Expand All @@ -194,7 +194,7 @@ class SpectreClient {
RpcTransaction transaction, {
bool allowOrphan = false,
}) async {
final message = SpectredMessage(
final message = SpectredRequest(
submitTransactionRequest: SubmitTransactionRequestMessage(
transaction: transaction,
allowOrphan: allowOrphan,
Expand All @@ -212,12 +212,12 @@ class SpectreClient {

// Mempool

Future<MempoolEntry> getMempoolEntry({
Future<RpcMempoolEntry> getMempoolEntry({
required String txId,
bool includeOrphanPool = true,
bool filterTransactionPool = true,
}) async {
final message = SpectredMessage(
final message = SpectredRequest(
getMempoolEntryRequest: GetMempoolEntryRequestMessage(
txId: txId,
includeOrphanPool: includeOrphanPool,
Expand All @@ -234,11 +234,11 @@ class SpectreClient {
return result.getMempoolEntryResponse.entry;
}

Future<List<MempoolEntry>> getMempoolEntries({
Future<List<RpcMempoolEntry>> getMempoolEntries({
bool includeOrphanPool = true,
bool filterTransactionPool = true,
}) async {
final message = SpectredMessage(
final message = SpectredRequest(
getMempoolEntriesRequest: GetMempoolEntriesRequestMessage(
includeOrphanPool: includeOrphanPool,
filterTransactionPool: filterTransactionPool,
Expand All @@ -254,12 +254,12 @@ class SpectreClient {
return result.getMempoolEntriesResponse.entries;
}

Future<List<MempoolEntryByAddress>> getMempoolEntriesByAddresses(
Future<List<RpcMempoolEntryByAddress>> getMempoolEntriesByAddresses(
Iterable<String> addresses, {
bool filterTransactionPool = true,
bool includeOrphanPool = true,
}) async {
final message = SpectredMessage(
final message = SpectredRequest(
getMempoolEntriesByAddressesRequest:
GetMempoolEntriesByAddressesRequestMessage(
addresses: addresses,
Expand All @@ -280,7 +280,7 @@ class SpectreClient {
// Network info

Future<String> getCurrentNetwork() async {
final message = SpectredMessage(
final message = SpectredRequest(
getCurrentNetworkRequest: GetCurrentNetworkRequestMessage(),
);

Expand All @@ -294,21 +294,23 @@ class SpectreClient {
}

Future<GetBlockDagInfoResponseMessage> getBlockDagInfo() async {
final message = SpectredMessage(
final message = SpectredRequest(
getBlockDagInfoRequest: GetBlockDagInfoRequestMessage(),
);

final result = await _singleRequest(message);
final error = result.getBlockDagInfoResponse.error;
if (error.message.isNotEmpty) {
throw RpcException(error);
}

return result.getBlockDagInfoResponse;
}

// Get Info

Future<GetInfoResponseMessage> getInfo() async {
final message = SpectredMessage(
final message = SpectredRequest(
getInfoRequest: GetInfoRequestMessage(),
);

Expand All @@ -323,25 +325,24 @@ class SpectreClient {

// Virtual Selected Parent Chain Changed

Stream<VirtualSelectedParentChainChangedNotificationMessage>
Stream<VirtualChainChangedNotificationMessage>
notifyVirtualSelectedParentChainChanged({
required includeAcceptedTransactionIds,
}) {
final message = SpectredMessage(
notifyVirtualSelectedParentChainChangedRequest:
NotifyVirtualSelectedParentChainChangedRequestMessage(
final message = SpectredRequest(
notifyVirtualChainChangedRequest: NotifyVirtualChainChangedRequestMessage(
includeAcceptedTransactionIds: includeAcceptedTransactionIds,
),
);

final response = _streamRequest(message);

final result = response.map((event) {
final error = event.notifyVirtualSelectedParentChainChangedResponse.error;
final error = event.notifyVirtualChainChangedResponse.error;
if (error.message.isNotEmpty) {
throw RpcException(error);
}
return event.virtualSelectedParentChainChangedNotification;
return event.virtualChainChangedNotification;
}).skip(1);

return result;
Expand All @@ -350,36 +351,33 @@ class SpectreClient {
// Virtual Selected Parent Blue Score

Future<Int64> getVirtualSelectedParentBlueScore() async {
final message = SpectredMessage(
getVirtualSelectedParentBlueScoreRequest:
GetVirtualSelectedParentBlueScoreRequestMessage(),
final message = SpectredRequest(
getSinkBlueScoreRequest: GetSinkBlueScoreRequestMessage(),
);

final result = await _singleRequest(message);
final error = result.getVirtualSelectedParentBlueScoreResponse.error;
final error = result.getSinkBlueScoreResponse.error;
if (error.message.isNotEmpty) {
throw RpcException(error);
}

return result.getVirtualSelectedParentBlueScoreResponse.blueScore;
return result.getSinkBlueScoreResponse.blueScore;
}

Stream<Int64> notifyVirtualSelectedParentBlueScoreChanged() {
final message = SpectredMessage(
notifyVirtualSelectedParentBlueScoreChangedRequest:
NotifyVirtualSelectedParentBlueScoreChangedRequestMessage(),
final message = SpectredRequest(
notifySinkBlueScoreChangedRequest:
NotifySinkBlueScoreChangedRequestMessage(),
);

final response = _streamRequest(message);

final result = response.map((event) {
final error =
event.notifyVirtualSelectedParentBlueScoreChangedResponse.error;
final error = event.notifySinkBlueScoreChangedResponse.error;
if (error.message.isNotEmpty) {
throw RpcException(error);
}
return event.virtualSelectedParentBlueScoreChangedNotification
.virtualSelectedParentBlueScore;
return event.sinkBlueScoreChangedNotification.sinkBlueScore;
}).skip(1);

return result;
Expand All @@ -388,7 +386,7 @@ class SpectreClient {
// Virtual DAA Score

Stream<Int64> notifyVirtualDaaScoreChanged() {
final message = SpectredMessage(
final message = SpectredRequest(
notifyVirtualDaaScoreChangedRequest:
NotifyVirtualDaaScoreChangedRequestMessage(),
);
Expand All @@ -410,7 +408,7 @@ class SpectreClient {
String hash, {
bool includeTransactions = true,
}) async {
final message = SpectredMessage(
final message = SpectredRequest(
getBlockRequest: GetBlockRequestMessage(
hash: hash,
includeTransactions: includeTransactions,
Expand Down
Loading

0 comments on commit 305dc2d

Please sign in to comment.