Merge pull request #302 from MetaMask/batch-payload-origin

background - batch rpc fix for origin domain
feature/default_network_editable
Dan Finlay 9 years ago committed by GitHub
commit bb7788373d
  1. 27
      app/scripts/background.js

@ -152,19 +152,22 @@ function setupPublicConfig(stream){
} }
function setupProviderConnection(stream, originDomain){ function setupProviderConnection(stream, originDomain){
// decorate all payloads with origin domain
stream.on('data', function onRpcRequest(payload){ stream.on('data', function onRpcRequest(request){
// Append origin to rpc payload var payloads = Array.isArray(request) ? request : [request]
payload.origin = originDomain payloads.forEach(function(payload){
// Append origin to signature request // Append origin to rpc payload
if (payload.method === 'eth_sendTransaction') { payload.origin = originDomain
payload.params[0].origin = originDomain // Append origin to signature request
} else if (payload.method === 'eth_sign') { if (payload.method === 'eth_sendTransaction') {
payload.params.push({ origin: originDomain }) payload.params[0].origin = originDomain
} } else if (payload.method === 'eth_sign') {
payload.params.push({ origin: originDomain })
}
})
// handle rpc request // handle rpc request
provider.sendAsync(payload, function onPayloadHandled(err, response){ provider.sendAsync(request, function onPayloadHandled(err, response){
logger(null, payload, response) logger(null, request, response)
try { try {
stream.write(response) stream.write(response)
} catch (err) { } catch (err) {

Loading…
Cancel
Save