A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { ethErrors, serializeError } from 'eth-rpc-errors';
|
|
|
|
|
|
|
|
const createMetaRPCHandler = (api, outStream) => {
|
|
|
|
return (data) => {
|
|
|
|
if (outStream._writableState.ended) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!api[data.method]) {
|
|
|
|
outStream.write({
|
|
|
|
jsonrpc: '2.0',
|
|
|
|
error: ethErrors.rpc.methodNotFound({
|
|
|
|
message: `${data.method} not found`,
|
|
|
|
}),
|
|
|
|
id: data.id,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
api[data.method](...data.params, (err, result) => {
|
|
|
|
if (outStream._writableState.ended) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
outStream.write({
|
|
|
|
jsonrpc: '2.0',
|
|
|
|
error: serializeError(err, { shouldIncludeStack: true }),
|
|
|
|
id: data.id,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
outStream.write({
|
|
|
|
jsonrpc: '2.0',
|
|
|
|
result,
|
|
|
|
id: data.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default createMetaRPCHandler;
|