Commit 533e0626 authored by aniket-engg's avatar aniket-engg Committed by Aniket

js to ts

parent c7107ce5
const Provider = require('./src/provider')
module.exports = {
Provider: Provider
}
import {Provider} from './provider'
export { Provider }
const ethJSUtil = require('ethereumjs-util')
const { BN, privateToAddress, isValidPrivate } = require('ethereumjs-util')
const Web3 = require('web3')
const crypto = require('crypto')
import { BN, privateToAddress, toChecksumAddress, isValidPrivate} from 'ethereumjs-util'
import { stripHexPrefix } from 'ethjs-util'
import Web3 from 'web3'
import * as crypto from 'crypto'
class Accounts{
export class Accounts {
web3
accounts
accountsKeys
executionContext
constructor(executionContext) {
this.web3 = new Web3()
......@@ -39,10 +44,10 @@ class Accounts{
_addAccount (privateKey, balance) {
return new Promise((resolve, reject) => {
privateKey = Buffer.from(privateKey, 'hex')
const address = ethJSUtil.privateToAddress(privateKey)
const address = privateToAddress(privateKey)
this.accounts[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 }
this.accountsKeys[ethJSUtil.toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex')
this.accounts[toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 }
this.accountsKeys[toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex')
let stateManager = this.executionContext.vm().stateManager
stateManager.getAccount(address, (error, account) => {
......@@ -81,7 +86,7 @@ class Accounts{
eth_getBalance (payload, cb) {
let address = payload.params[0]
address = ethJSUtil.stripHexPrefix(address)
address = stripHexPrefix(address)
this.executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), (err, account) => {
if (err) {
......@@ -95,7 +100,7 @@ class Accounts{
const address = payload.params[0]
const message = payload.params[1]
const privateKey = this.accountsKeys[ethJSUtil.toChecksumAddress(address)]
const privateKey = this.accountsKeys[toChecksumAddress(address)]
if (!privateKey) {
return cb(new Error('unknown account'))
}
......@@ -106,5 +111,3 @@ class Accounts{
cb(null, data.signature)
}
}
\ No newline at end of file
module.exports = Accounts
\ No newline at end of file
class Blocks {
export class Blocks {
executionContext
coinbase
blockNumber
constructor (executionContext, _options) {
this.executionContext = executionContext
const options = _options || {}
......@@ -130,10 +135,8 @@ class Blocks {
return cb(err, '')
}
let value = Object.values(result.storage)[0].value
let value = Object.values(result.storage)[0]['value']
cb(err, value)
})
}
}
\ No newline at end of file
module.exports = Blocks
\ No newline at end of file
class Debug {
export class Debug {
executionContext
constructor (executionContext) {
this.executionContext = executionContext
}
......@@ -29,5 +32,3 @@ class Debug {
cb)
}
}
module.exports = Debug
class Filters {
export class Filters {
executionContext
constructor(executionContext) {
this.executionContext = executionContext
}
......@@ -58,5 +61,3 @@ class Filters {
cb(null, results)
}
}
module.exports = Filters
\ No newline at end of file
const Web3 = require('web3')
const ethJSUtil = require('ethereumjs-util')
const processTx = require('./txProcess.js')
const BN = ethJSUtil.BN
import Web3 from 'web3'
import { toChecksumAddress, BN } from 'ethereumjs-util'
import { processTx } from './txProcess'
class Transactions{
executionContext
accounts
constructor(executionContext) {
this.executionContext = executionContext
}
......@@ -30,7 +32,7 @@ class Transactions{
eth_sendTransaction (payload, cb) {
// from might be lowercased address (web3)
if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
payload.params[0].from = toChecksumAddress(payload.params[0].from)
}
processTx(this.executionContext, this.accounts, payload, false, cb)
}
......@@ -83,10 +85,10 @@ class Transactions{
eth_call (payload, cb) {
// from might be lowercased address (web3)
if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
payload.params[0].from = toChecksumAddress(payload.params[0].from)
}
if (payload.params && payload.params.length > 0 && payload.params[0].to) {
payload.params[0].to = ethJSUtil.toChecksumAddress(payload.params[0].to)
payload.params[0].to = toChecksumAddress(payload.params[0].to)
}
payload.params[0].value = undefined
......@@ -136,7 +138,7 @@ class Transactions{
}
if (receipt.to) {
r.to = receipt.to
r['to'] = receipt.to
}
if (r.value === '0x') {
......@@ -182,7 +184,7 @@ class Transactions{
}
if (receipt.to) {
r.to = receipt.to
r['to'] = receipt.to
}
if (r.value === '0x') {
......@@ -224,7 +226,7 @@ class Transactions{
}
if (receipt.to) {
r.to = receipt.to
r['to'] = receipt.to
}
if (r.value === '0x') {
......@@ -235,5 +237,3 @@ class Transactions{
})
}
}
\ No newline at end of file
module.exports = Transactions
\ No newline at end of file
......@@ -39,7 +39,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac
let txRunnerInstance
function processTx (executionContext, accounts, payload, isCall, callback) {
export function processTx (executionContext, accounts, payload, isCall, callback) {
const api = {
logMessage: (msg) => {
},
......@@ -94,5 +94,3 @@ function processTx (executionContext, accounts, payload, isCall, callback) {
createContract(payload, from, data, value, gas, txRunnerInstance, callbacks, callback)
}
}
module.exports = processTx
......@@ -5,7 +5,7 @@ const log = require('./utils/logs.js')
const merge = require('merge')
const Accounts = require('./methods/accounts.js')
const Blocks = require('./methods/blocks.js')
import { Blocks } from './methods/blocks'
const Filters = require('./methods/filters.js')
const Misc = require('./methods/misc.js')
const Net = require('./methods/net.js')
......@@ -14,7 +14,14 @@ const Debug = require('./methods/debug.js')
const generateBlock = require('./genesis.js')
class Provider {
export class Provider {
options
executionContext
Accounts
Transactions
methods
constructor(options = {}) {
this.options = options
// TODO: init executionContext here
......@@ -75,5 +82,3 @@ class Provider {
this.executionContext.logsManager.addListener(type, cb)
}
}
\ No newline at end of file
module.exports = Provider
\ No newline at end of file
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["**/*.ts"]
}
\ No newline at end of file
{
"extends": "../../tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"allowJs": true,
"declaration": true,
"rootDir": "./",
"rootDir": "./src",
"types": ["node"]
},
"exclude": ["**/*.spec.js"],
"include": [
"src/**/*.js",
"./index.js",
"bin/"
]
}
\ No newline at end of file
"exclude": [
"**/*.spec.ts"
],
"include": ["**/*.ts"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment