-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
81 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/dapi/lib/externalApis/tenderdash/requestTenderRpc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const UnavailableGrpcError = require('@dashevo/grpc-common/lib/server/error/UnavailableGrpcError'); | ||
const ResourceExhaustedGrpcError = require('@dashevo/grpc-common/lib/server/error/ResourceExhaustedGrpcError'); | ||
const RPCError = require('../../rpcServer/RPCError'); | ||
|
||
/** | ||
* @param {jaysonClient} rpcClient | ||
* @return {requestTenderRpc} | ||
*/ | ||
function requestTenderRpcFactory(rpcClient) { | ||
/** | ||
* @typedef requestTenderRpc | ||
* @param {string} uri | ||
* @param {Object} [params] | ||
* @return {Promise<Object>} | ||
*/ | ||
return async function requestTenderRpc(uri, params = {}) { | ||
let response; | ||
try { | ||
response = await rpcClient.request(uri, params); | ||
} catch (e) { | ||
if (e.message === 'socket hang up') { | ||
throw new UnavailableGrpcError('Tenderdash is not available'); | ||
} | ||
|
||
e.message = `Failed to request ${uri}: ${e.message}`; | ||
|
||
throw e; | ||
} | ||
|
||
const { result, error: jsonRpcError } = response; | ||
|
||
if (jsonRpcError) { | ||
if (typeof jsonRpcError.data === 'string') { | ||
if (jsonRpcError.data.includes('too_many_resets')) { | ||
throw new ResourceExhaustedGrpcError('tenderdash is not responding: too many requests'); | ||
} | ||
} | ||
|
||
throw new RPCError( | ||
jsonRpcError.code || -32602, | ||
jsonRpcError.message || 'Internal error', | ||
jsonRpcError.data, | ||
); | ||
} | ||
|
||
return result; | ||
}; | ||
} | ||
|
||
module.exports = requestTenderRpcFactory; |
72 changes: 0 additions & 72 deletions
72
...grpcServer/handlers/platform/broadcastStateTransition/fetchCachedStateTransitionResult.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters