|
|
|
@ -1,22 +1,10 @@ |
|
|
|
|
var Web3 = require('web3') |
|
|
|
|
var RemixLib = require('remix-lib') |
|
|
|
|
var executionContext = RemixLib.execution.executionContext |
|
|
|
|
var ethJSUtil = require('ethereumjs-util') |
|
|
|
|
var processTx = require('./txProcess.js') |
|
|
|
|
var BN = ethJSUtil.BN |
|
|
|
|
|
|
|
|
|
function hexConvert (ints) { |
|
|
|
|
var ret = '0x' |
|
|
|
|
for (var i = 0; i < ints.length; i++) { |
|
|
|
|
var h = ints[i] |
|
|
|
|
if (h) { |
|
|
|
|
ret += (h <= 0xf ? '0' : '') + h.toString(16) |
|
|
|
|
} else { |
|
|
|
|
ret += '00' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ret |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var Transactions = function (accounts) { |
|
|
|
|
this.accounts = accounts |
|
|
|
|
} |
|
|
|
@ -45,15 +33,15 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { |
|
|
|
|
return cb(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var txBlock = executionContext.txs[receipt.hash]; |
|
|
|
|
var txBlock = executionContext.txs[receipt.hash] |
|
|
|
|
|
|
|
|
|
var r = { |
|
|
|
|
'transactionHash': receipt.hash, |
|
|
|
|
'transactionIndex': '0x00', |
|
|
|
|
'blockHash': "0x" + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': "0x" + txBlock.header.number.toString('hex'), |
|
|
|
|
'gasUsed': web3.utils.toHex(receipt.gas), |
|
|
|
|
'cumulativeGasUsed': web3.utils.toHex(receipt.gas), |
|
|
|
|
'blockHash': '0x' + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': '0x' + txBlock.header.number.toString('hex'), |
|
|
|
|
'gasUsed': Web3.utils.toHex(receipt.gas), |
|
|
|
|
'cumulativeGasUsed': Web3.utils.toHex(receipt.gas), |
|
|
|
|
'contractAddress': receipt.contractAddress, |
|
|
|
|
'logs': receipt.logs, |
|
|
|
|
'status': receipt.status |
|
|
|
@ -70,13 +58,13 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) { |
|
|
|
|
Transactions.prototype.eth_getCode = function (payload, cb) { |
|
|
|
|
let address = payload.params[0] |
|
|
|
|
|
|
|
|
|
executionContext.web3().eth.getCode(address, (error, result) => { |
|
|
|
|
if (error) { |
|
|
|
|
console.dir("error getting code"); |
|
|
|
|
console.dir(error); |
|
|
|
|
} |
|
|
|
|
cb(error, result) |
|
|
|
|
}) |
|
|
|
|
executionContext.web3().eth.getCode(address, (error, result) => { |
|
|
|
|
if (error) { |
|
|
|
|
console.dir('error getting code') |
|
|
|
|
console.dir(error) |
|
|
|
|
} |
|
|
|
|
cb(error, result) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Transactions.prototype.eth_call = function (payload, cb) { |
|
|
|
@ -103,35 +91,33 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { |
|
|
|
|
return cb(error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var test = executionContext.web3(); |
|
|
|
|
|
|
|
|
|
var txBlock = executionContext.txs[receipt.transactionHash]; |
|
|
|
|
var txBlock = executionContext.txs[receipt.transactionHash] |
|
|
|
|
|
|
|
|
|
// TODO: params to add later
|
|
|
|
|
let r = { |
|
|
|
|
'blockHash': "0x" + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': "0x" + txBlock.header.number.toString('hex'), |
|
|
|
|
'blockHash': '0x' + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': '0x' + txBlock.header.number.toString('hex'), |
|
|
|
|
'from': receipt.from, |
|
|
|
|
'gas': web3.utils.toHex(receipt.gas), |
|
|
|
|
'gas': Web3.utils.toHex(receipt.gas), |
|
|
|
|
// 'gasPrice': '2000000000000', // 0x123
|
|
|
|
|
"gasPrice":"0x4a817c800", // 20000000000
|
|
|
|
|
'gasPrice': '0x4a817c800', // 20000000000
|
|
|
|
|
'hash': receipt.transactionHash, |
|
|
|
|
'input': receipt.input, |
|
|
|
|
// "nonce": 2, // 0x15
|
|
|
|
|
// "transactionIndex": 0,
|
|
|
|
|
"value": receipt.value |
|
|
|
|
'value': receipt.value |
|
|
|
|
// "value":"0xf3dbb76162000" // 4290000000000000
|
|
|
|
|
// "v": "0x25", // 37
|
|
|
|
|
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
|
|
|
|
|
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
|
|
|
|
|
// "v": "0x25", // 37
|
|
|
|
|
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
|
|
|
|
|
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (receipt.to) { |
|
|
|
|
r.to = receipt.to |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (r.value === "0x") { |
|
|
|
|
r.value = "0x0" |
|
|
|
|
if (r.value === '0x') { |
|
|
|
|
r.value = '0x0' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cb(null, r) |
|
|
|
@ -142,7 +128,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload |
|
|
|
|
const txIndex = payload.params[1] |
|
|
|
|
|
|
|
|
|
var txBlock = executionContext.blocks[payload.params[0]] |
|
|
|
|
const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') |
|
|
|
|
const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex') |
|
|
|
|
|
|
|
|
|
executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { |
|
|
|
|
if (error) { |
|
|
|
@ -151,17 +137,17 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload |
|
|
|
|
|
|
|
|
|
// TODO: params to add later
|
|
|
|
|
let r = { |
|
|
|
|
'blockHash': "0x" + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': "0x" + txBlock.header.number.toString('hex'), |
|
|
|
|
'blockHash': '0x' + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': '0x' + txBlock.header.number.toString('hex'), |
|
|
|
|
'from': receipt.from, |
|
|
|
|
'gas': web3.utils.toHex(receipt.gas), |
|
|
|
|
'gas': Web3.utils.toHex(receipt.gas), |
|
|
|
|
// 'gasPrice': '2000000000000', // 0x123
|
|
|
|
|
"gasPrice": "0x4a817c800", // 20000000000
|
|
|
|
|
'gasPrice': '0x4a817c800', // 20000000000
|
|
|
|
|
'hash': receipt.transactionHash, |
|
|
|
|
'input': receipt.input, |
|
|
|
|
// "nonce": 2, // 0x15
|
|
|
|
|
// "transactionIndex": 0,
|
|
|
|
|
"value": receipt.value |
|
|
|
|
'value': receipt.value |
|
|
|
|
// "value":"0xf3dbb76162000" // 4290000000000000
|
|
|
|
|
// "v": "0x25", // 37
|
|
|
|
|
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
|
|
|
|
@ -172,8 +158,8 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload |
|
|
|
|
r.to = receipt.to |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (r.value === "0x") { |
|
|
|
|
r.value = "0x0" |
|
|
|
|
if (r.value === '0x') { |
|
|
|
|
r.value = '0x0' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cb(null, r) |
|
|
|
@ -184,7 +170,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo |
|
|
|
|
const txIndex = payload.params[1] |
|
|
|
|
|
|
|
|
|
var txBlock = executionContext.blocks[payload.params[0]] |
|
|
|
|
const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') |
|
|
|
|
const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex') |
|
|
|
|
|
|
|
|
|
executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { |
|
|
|
|
if (error) { |
|
|
|
@ -193,17 +179,17 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo |
|
|
|
|
|
|
|
|
|
// TODO: params to add later
|
|
|
|
|
let r = { |
|
|
|
|
'blockHash': "0x" + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': "0x" + txBlock.header.number.toString('hex'), |
|
|
|
|
'blockHash': '0x' + txBlock.hash().toString('hex'), |
|
|
|
|
'blockNumber': '0x' + txBlock.header.number.toString('hex'), |
|
|
|
|
'from': receipt.from, |
|
|
|
|
'gas': web3.utils.toHex(receipt.gas), |
|
|
|
|
'gas': Web3.utils.toHex(receipt.gas), |
|
|
|
|
// 'gasPrice': '2000000000000', // 0x123
|
|
|
|
|
"gasPrice": "0x4a817c800", // 20000000000
|
|
|
|
|
'gasPrice': '0x4a817c800', // 20000000000
|
|
|
|
|
'hash': receipt.transactionHash, |
|
|
|
|
'input': receipt.input, |
|
|
|
|
// "nonce": 2, // 0x15
|
|
|
|
|
// "transactionIndex": 0,
|
|
|
|
|
"value": receipt.value |
|
|
|
|
'value': receipt.value |
|
|
|
|
// "value":"0xf3dbb76162000" // 4290000000000000
|
|
|
|
|
// "v": "0x25", // 37
|
|
|
|
|
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
|
|
|
|
@ -214,12 +200,12 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo |
|
|
|
|
r.to = receipt.to |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (r.value === "0x") { |
|
|
|
|
r.value = "0x0" |
|
|
|
|
if (r.value === '0x') { |
|
|
|
|
r.value = '0x0' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cb(null, r) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
module.exports = Transactions |
|
|
|
|
module.exports = Transactions |
|
|
|
|