|
|
@ -34,7 +34,7 @@ class Blockchain { |
|
|
|
this.executionContext.detectNetwork(cb) |
|
|
|
this.executionContext.detectNetwork(cb) |
|
|
|
}, |
|
|
|
}, |
|
|
|
personalMode: () => { |
|
|
|
personalMode: () => { |
|
|
|
return this.executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false |
|
|
|
return this.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false |
|
|
|
} |
|
|
|
} |
|
|
|
}, this.executionContext) |
|
|
|
}, this.executionContext) |
|
|
|
this.executionContext.event.register('contextChanged', this.resetEnvironment.bind(this)) |
|
|
|
this.executionContext.event.register('contextChanged', this.resetEnvironment.bind(this)) |
|
|
@ -66,7 +66,7 @@ class Blockchain { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getCurrentProvider () { |
|
|
|
getCurrentProvider () { |
|
|
|
const provider = this.executionContext.getProvider() |
|
|
|
const provider = this.getProvider() |
|
|
|
return this.providers[provider] |
|
|
|
return this.providers[provider] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -199,10 +199,6 @@ class Blockchain { |
|
|
|
return this.executionContext.setProviderFromEndpoint(target, context, cb) |
|
|
|
return this.executionContext.setProviderFromEndpoint(target, context, cb) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getProvider () { |
|
|
|
|
|
|
|
return this.executionContext.getProvider() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateNetwork (cb) { |
|
|
|
updateNetwork (cb) { |
|
|
|
this.networkcallid++ |
|
|
|
this.networkcallid++ |
|
|
|
((callid) => { |
|
|
|
((callid) => { |
|
|
@ -221,14 +217,18 @@ class Blockchain { |
|
|
|
return this.executionContext.detectNetwork(cb) |
|
|
|
return this.executionContext.detectNetwork(cb) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getProvider () { |
|
|
|
|
|
|
|
return this.executionContext.getProvider() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isWeb3Provider () { |
|
|
|
isWeb3Provider () { |
|
|
|
const isVM = this.executionContext.isVM() |
|
|
|
const isVM = this.getProvider === 'vm' |
|
|
|
const isInjected = this.executionContext.getProvider() === 'injected' |
|
|
|
const isInjected = this.getProvider() === 'injected' |
|
|
|
return (!isVM && !isInjected) |
|
|
|
return (!isVM && !isInjected) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isInjectedWeb3 () { |
|
|
|
isInjectedWeb3 () { |
|
|
|
return this.executionContext.getProvider() === 'injected' |
|
|
|
return this.getProvider() === 'injected' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
signMessage (message, account, passphrase, cb) { |
|
|
|
signMessage (message, account, passphrase, cb) { |
|
|
@ -263,13 +263,6 @@ class Blockchain { |
|
|
|
if (error) { |
|
|
|
if (error) { |
|
|
|
return logCallback(`${logMsg} errored: ${error} `) |
|
|
|
return logCallback(`${logMsg} errored: ${error} `) |
|
|
|
} |
|
|
|
} |
|
|
|
const isVM = this.executionContext.isVM() |
|
|
|
|
|
|
|
if (isVM) { |
|
|
|
|
|
|
|
const vmError = txExecution.checkVMError(txResult) |
|
|
|
|
|
|
|
if (vmError.error) { |
|
|
|
|
|
|
|
return logCallback(`${logMsg} errored: ${vmError.message} `) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (lookupOnly) { |
|
|
|
if (lookupOnly) { |
|
|
|
const returnValue = (this.executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result)) |
|
|
|
const returnValue = (this.executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result)) |
|
|
|
outputCb(returnValue) |
|
|
|
outputCb(returnValue) |
|
|
@ -322,7 +315,7 @@ class Blockchain { |
|
|
|
this.executionContext.detectNetwork(cb) |
|
|
|
this.executionContext.detectNetwork(cb) |
|
|
|
}, |
|
|
|
}, |
|
|
|
personalMode: () => { |
|
|
|
personalMode: () => { |
|
|
|
return this.executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false |
|
|
|
return this.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false |
|
|
|
} |
|
|
|
} |
|
|
|
}, this.executionContext) |
|
|
|
}, this.executionContext) |
|
|
|
this.txRunner.event.register('transactionBroadcasted', (txhash) => { |
|
|
|
this.txRunner.event.register('transactionBroadcasted', (txhash) => { |
|
|
@ -338,7 +331,7 @@ class Blockchain { |
|
|
|
* @param {{privateKey: string, balance: string}} newAccount The new account to create |
|
|
|
* @param {{privateKey: string, balance: string}} newAccount The new account to create |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
createVMAccount (newAccount) { |
|
|
|
createVMAccount (newAccount) { |
|
|
|
if (this.executionContext.getProvider() !== 'vm') { |
|
|
|
if (this.getProvider() !== 'vm') { |
|
|
|
throw new Error('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') |
|
|
|
throw new Error('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') |
|
|
|
} |
|
|
|
} |
|
|
|
return this.providers.vm.createVMAccount(newAccount) |
|
|
|
return this.providers.vm.createVMAccount(newAccount) |
|
|
@ -368,6 +361,14 @@ class Blockchain { |
|
|
|
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) { |
|
|
|
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) { |
|
|
|
const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' |
|
|
|
const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' |
|
|
|
this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, (error, txResult) => { |
|
|
|
this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, (error, txResult) => { |
|
|
|
|
|
|
|
const isVM = this.executionContext.isVM() |
|
|
|
|
|
|
|
if (isVM) { |
|
|
|
|
|
|
|
const vmError = txExecution.checkVMError(txResult) |
|
|
|
|
|
|
|
if (vmError.error) { |
|
|
|
|
|
|
|
return callback(vmError.message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
|
|
|
|
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
|
|
|
|
callback(error, txResult) |
|
|
|
callback(error, txResult) |
|
|
|
}) |
|
|
|
}) |
|
|
|