Skip to content

Commit

Permalink
Fixed http provider send json rpc failed (leonardocustodio#456)
Browse files Browse the repository at this point in the history
Fixed http provider send json rpc failed and make sure response id is always parse-able
  • Loading branch information
weishirongzhen authored Jun 18, 2024
1 parent 39bc6cb commit 0a2cfab
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/polkadart/lib/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@ class HttpProvider extends Provider {

@override
Future<RpcResponse> send(String method, List<dynamic> params) async {
final response = await http.post(url, body: {
'id': (++_sequence).toString(),
'jsonrpc': '2.0',
'method': method,
'params': params,
});
final response = await http.post(url,
body: jsonEncode(
{
'id': (++_sequence).toString(),
'jsonrpc': '2.0',
'method': method,
'params': params,
},
),
headers: {'Content-Type': 'application/json'});
final data = jsonDecode(response.body);

return RpcResponse(
id: data['id'],
id: int.tryParse(data['id'].toString()) ?? -1,
result: data['result'],
);
}
Expand Down

0 comments on commit 0a2cfab

Please # to comment.