| 1 | import 'dart:convert'; |
| 2 | import 'package:cw_core/utils/proxy_wrapper.dart'; |
| 3 | import 'package:on_chain/solana/solana.dart'; |
| 4 | |
| 5 | class SolanaRPCHTTPService implements SolanaJSONRPCService { |
| 6 | SolanaRPCHTTPService( |
| 7 | {required this.url, this.defaultRequestTimeout = const Duration(seconds: 30)}); |
| 8 | @override |
| 9 | final String url; |
| 10 | final Duration defaultRequestTimeout; |
| 11 | |
| 12 | Future<Map<String, dynamic>> call(SolanaRequestDetails params, [Duration? timeout]) async { |
| 13 | final response = await ProxyWrapper().post( |
| 14 | clearnetUri: Uri.parse(url), |
| 15 | body: params.toRequestBody(), |
| 16 | headers: { |
| 17 | 'Content-Type': 'application/json', |
| 18 | }, |
| 19 | ).timeout(timeout ?? defaultRequestTimeout); |
| 20 | final data = json.decode(response.body) as Map<String, dynamic>; |
| 21 | return data; |
| 22 | } |
| 23 | } |