Merge pull request #1967 from ethereum/issue#1966-createvmaccount_api

Use an object for createVMAccount
pull/1/head
yann300 6 years ago committed by GitHub
commit 53b54e13ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      src/universal-dapp.js
  2. 5
      test-browser/plugin/plugin.js
  3. 5
      test-browser/plugin/remix.js

@ -82,13 +82,18 @@ module.exports = class UniversalDApp extends UdappApi {
this.transactionContextAPI = transactionContextAPI this.transactionContextAPI = transactionContextAPI
} }
createVMAccount (privateKey, balance, cb) { /**
return new Promise((resolve, reject) => { * Create a VM Account
if (executionContext.getProvider() !== 'vm') return reject('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') * @param {{privateKey: string, balance: string}} newAccount The new account to create
this._addAccount(privateKey, balance) */
privateKey = Buffer.from(privateKey, 'hex') createVMAccount (newAccount) {
resolve('0x' + ethJSUtil.privateToAddress(privateKey).toString('hex')) const { privateKey, balance } = newAccount
}) if (executionContext.getProvider() !== 'vm') {
throw new Error('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed')
}
this._addAccount(privateKey, balance)
const privKey = Buffer.from(privateKey, 'hex')
return '0x' + ethJSUtil.privateToAddress(privKey).toString('hex')
} }
newAccount (password, passwordPromptCb, cb) { newAccount (password, passwordPromptCb, cb) {

@ -44,7 +44,10 @@ window.onload = function () {
}) })
document.querySelector('input#testaccountcreation').addEventListener('click', function () { document.querySelector('input#testaccountcreation').addEventListener('click', function () {
extension.call('udapp', 'createVMAccount', ['71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce', '0x56BC75E2D63100000'], extension.call('udapp', 'createVMAccount', [{
privateKey: '71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce',
balance: '0x56BC75E2D63100000'
}],
function (error, result) { console.log(error, result) }) function (error, result) { console.log(error, result) })
}) })

@ -64,7 +64,10 @@ window.onload = function () {
action: 'request', action: 'request',
key: 'udapp', key: 'udapp',
type: 'createVMAccount', type: 'createVMAccount',
value: ['71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce', '0x56BC75E2D63100000'], value: [{
privateKey: '71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce',
balance: '0x56BC75E2D63100000'
}],
id: 38 id: 38
}), '*') }), '*')
}) })

Loading…
Cancel
Save