update blockchain module syntax

pull/1/head
Iuri Matias 5 years ago committed by yann300
parent 5169cfb515
commit ed22d29da0
  1. 36
      src/blockchain/blockchain.js

@ -60,7 +60,7 @@ class Blockchain {
async deployContract (selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb) { async deployContract (selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb) {
const { continueCb, promptCb, statusCb, finalCb } = callbacks const { continueCb, promptCb, statusCb, finalCb } = callbacks
var constructor = selectedContract.getConstructorInterface() const constructor = selectedContract.getConstructorInterface()
if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) {
return txFormat.buildData(selectedContract.name, selectedContract.object, compilerContracts, true, constructor, args, (error, data) => { return txFormat.buildData(selectedContract.name, selectedContract.object, compilerContracts, true, constructor, args, (error, data) => {
if (error) return statusCb(`creation of ${selectedContract.name} errored: ` + error) if (error) return statusCb(`creation of ${selectedContract.name} errored: ` + error)
@ -97,9 +97,9 @@ class Blockchain {
if (error) { if (error) {
return finalCb(`creation of ${selectedContract.name} errored: ${error}`) return finalCb(`creation of ${selectedContract.name} errored: ${error}`)
} }
var isVM = this.executionContext.isVM() const isVM = this.executionContext.isVM()
if (isVM) { if (isVM) {
var vmError = txExecution.checkVMError(txResult) const vmError = txExecution.checkVMError(txResult)
if (vmError.error) { if (vmError.error) {
return finalCb(vmError.message) return finalCb(vmError.message)
} }
@ -107,7 +107,7 @@ class Blockchain {
if (txResult.result.status === false || txResult.result.status === '0x0') { if (txResult.result.status === false || txResult.result.status === '0x0') {
return finalCb(`creation of ${selectedContract.name} errored: transaction execution failed`) return finalCb(`creation of ${selectedContract.name} errored: transaction execution failed`)
} }
var address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress const address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress
finalCb(null, selectedContract, address) finalCb(null, selectedContract, address)
} }
) )
@ -115,12 +115,12 @@ class Blockchain {
determineGasPrice (cb) { determineGasPrice (cb) {
this.getGasPrice((error, gasPrice) => { this.getGasPrice((error, gasPrice) => {
var warnMessage = ' Please fix this issue before sending any transaction. ' const warnMessage = ' Please fix this issue before sending any transaction. '
if (error) { if (error) {
return cb('Unable to retrieve the current network gas price.' + warnMessage + error) return cb('Unable to retrieve the current network gas price.' + warnMessage + error)
} }
try { try {
var gasPriceValue = this.fromWei(gasPrice, false, 'gwei') const gasPriceValue = this.fromWei(gasPrice, false, 'gwei')
cb(null, gasPriceValue) cb(null, gasPriceValue)
} catch (e) { } catch (e) {
cb(warnMessage + e.message, null, false) cb(warnMessage + e.message, null, false)
@ -153,7 +153,7 @@ class Blockchain {
// TODO: this try catch feels like an anti pattern, can/should be // TODO: this try catch feels like an anti pattern, can/should be
// removed, but for now keeping the original logic // removed, but for now keeping the original logic
try { try {
var fee = this.calculateFee(tx.gas, gasPrice) const fee = this.calculateFee(tx.gas, gasPrice)
txFeeText = ' ' + this.fromWei(fee, false, 'ether') + ' Ether' txFeeText = ' ' + this.fromWei(fee, false, 'ether') + ' Ether'
priceStatus = true priceStatus = true
} catch (e) { } catch (e) {
@ -205,8 +205,8 @@ class Blockchain {
} }
isWeb3Provider () { isWeb3Provider () {
var isVM = this.executionContext.isVM() const isVM = this.executionContext.isVM()
var isInjected = this.executionContext.getProvider() === 'injected' const isInjected = this.executionContext.getProvider() === 'injected'
return (!isVM && !isInjected) return (!isVM && !isInjected)
} }
@ -215,15 +215,15 @@ class Blockchain {
} }
signMessage (message, account, passphrase, cb) { signMessage (message, account, passphrase, cb) {
var isVM = this.executionContext.isVM() const isVM = this.executionContext.isVM()
var isInjected = this.executionContext.getProvider() === 'injected' const isInjected = this.executionContext.getProvider() === 'injected'
if (isVM) { if (isVM) {
const personalMsg = ethJSUtil.hashPersonalMessage(Buffer.from(message)) const personalMsg = ethJSUtil.hashPersonalMessage(Buffer.from(message))
var privKey = this.accounts[account].privateKey const privKey = this.accounts[account].privateKey
try { try {
var rsv = ethJSUtil.ecsign(personalMsg, privKey) const rsv = ethJSUtil.ecsign(personalMsg, privKey)
var signedData = ethJSUtil.toRpcSig(rsv.v, rsv.r, rsv.s) const signedData = ethJSUtil.toRpcSig(rsv.v, rsv.r, rsv.s)
cb(null, '0x' + personalMsg.toString('hex'), signedData) cb(null, '0x' + personalMsg.toString('hex'), signedData)
} catch (e) { } catch (e) {
cb(e.message) cb(e.message)
@ -244,7 +244,7 @@ class Blockchain {
const hashedMsg = Web3.utils.sha3(message) const hashedMsg = Web3.utils.sha3(message)
try { try {
var personal = new Personal(this.executionContext.web3().currentProvider) const personal = new Personal(this.executionContext.web3().currentProvider)
personal.sign(hashedMsg, account, passphrase, (error, signedData) => { personal.sign(hashedMsg, account, passphrase, (error, signedData) => {
cb(error.message, hashedMsg, signedData) cb(error.message, hashedMsg, signedData)
}) })
@ -277,9 +277,9 @@ class Blockchain {
if (funABI.type === 'fallback') data.dataHex = value if (funABI.type === 'fallback') data.dataHex = value
this.callFunction(address, data, funABI, callbacksInContext.confirmationCb.bind(callbacksInContext), callbacksInContext.continueCb.bind(callbacksInContext), callbacksInContext.promptCb.bind(callbacksInContext), (error, txResult) => { this.callFunction(address, data, funABI, callbacksInContext.confirmationCb.bind(callbacksInContext), callbacksInContext.continueCb.bind(callbacksInContext), callbacksInContext.promptCb.bind(callbacksInContext), (error, txResult) => {
if (!error) { if (!error) {
var isVM = this.executionContext.isVM() const isVM = this.executionContext.isVM()
if (isVM) { if (isVM) {
var vmError = txExecution.checkVMError(txResult) const vmError = txExecution.checkVMError(txResult)
if (vmError.error) { if (vmError.error) {
logCallback(`${logMsg} errored: ${vmError.message} `) logCallback(`${logMsg} errored: ${vmError.message} `)
return return
@ -410,7 +410,7 @@ class Blockchain {
stateManager.getAccount(address, (error, account) => { stateManager.getAccount(address, (error, account) => {
if (error) return console.log(error) if (error) return console.log(error)
account.balance = balance || '0xf00000000000000001' account.balance = balance || '0xf00000000000000001'
stateManager.putAccount(address, account, function cb (error) { stateManager.putAccount(address, account, (error) => {
if (error) console.log(error) if (error) console.log(error)
}) })
}) })

Loading…
Cancel
Save