Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Support POST method for Etherscan.io #54

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions subproviders/etherscan.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Calculate gasPrice based on last blocks.
* Etherscan.io API connector
* @author github.com/axic
*
* The etherscan.io API supports:
Expand Down Expand Up @@ -34,35 +34,35 @@ EtherscanProvider.prototype.handleRequest = function(payload, next, end){

switch(payload.method) {
case 'eth_blockNumber':
etherscanXHR(this.proto, 'proxy', 'eth_blockNumber', {}, end)
etherscanXHR(this.proto, true, 'proxy', 'eth_blockNumber', {}, end)
return

case 'eth_getBlockByNumber':
etherscanXHR(this.proto, 'proxy', 'eth_getBlockByNumber', {
etherscanXHR(this.proto, true, 'proxy', 'eth_getBlockByNumber', {
tag: payload.params[0],
boolean: payload.params[1] }, end)
return

case 'eth_getBalance':
etherscanXHR(this.proto, 'account', 'balance', {
etherscanXHR(this.proto, true, 'account', 'balance', {
address: payload.params[0],
tag: payload.params[1] }, end)
return

case 'eth_call':
etherscanXHR(this.proto, 'proxy', 'eth_call', payload.params[0], end)
etherscanXHR(this.proto, true, 'proxy', 'eth_call', payload.params[0], end)
return

case 'eth_sendRawTransaction':
etherscanXHR(this.proto, 'proxy', 'eth_sendRawTransaction', { hex: payload.params[0] }, end)
etherscanXHR(this.proto, true, 'proxy', 'eth_sendRawTransaction', { hex: payload.params[0] }, end)
return

case 'eth_getTransactionReceipt':
etherscanXHR(this.proto, 'proxy', 'eth_getTransactionReceipt', { txhash: payload.params[0] }, end)
etherscanXHR(this.proto, true, 'proxy', 'eth_getTransactionReceipt', { txhash: payload.params[0] }, end)
return

case 'eth_getTransactionCount':
etherscanXHR(this.proto, 'account', 'txlist', {
etherscanXHR(this.proto, true, 'account', 'txlist', {
sort: 'desc',
page: 0,
offset: 0,
Expand All @@ -88,13 +88,19 @@ function toQueryString(params) {
}).join('&')
}

function etherscanXHR(proto, module, action, params, end) {
function etherscanXHR(proto, get, module, action, params, end) {
var uri = proto + '://api.etherscan.io/api?' + toQueryString({ module: module, action: action }) + '&' + toQueryString(params)
// console.log('[etherscan] request: ', uri)

// URLs have a length in many browsers, switch to POST in that case
// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
if (uri.length > 2000) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kumavis this part was not taken into master and eth_sendRawTransaction still uses GET.

get = false
}

xhr({
uri: uri,
method: 'GET',
method: get ? 'GET' : 'POST',
headers: {
'Accept': 'application/json',
// 'Content-Type': 'application/json',
Expand Down