Merge pull request #119 from axic/patch/vmupdate

Update VM to latest
pull/1/head
chriseth 9 years ago
commit cb7961fb57
  1. 24
      assets/js/universal-dapp.js

@ -7,15 +7,13 @@ function UniversalDApp (contracts, options) {
if (!options.vm && web3.currentProvider) {
} else if (options.vm) {
this.vm = new EthVm();
//@todo this does not calculate the gas costs correctly but gets the job done.
this.identityCode = 'return { gasUsed: 1, return: opts.data, exception: 1 };';
this.identityAddr = ethUtil.pad(new Buffer('04', 'hex'), 20)
this.vm.loadCompiled(this.identityAddr, this.identityCode);
this.BN = EthJS.BN;
this.stateTrie = new EthJS.Trie();
this.vm = new EthJS.VM(this.stateTrie);
this.secretKey = '3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'
this.publicKey = '0406cc661590d48ee972944b35ad13ff03c7876eae3fd191e8a2f77311b0a3c6613407b5005e63d7d8d76b89d5f900cde691497688bb281e07a5052ff61edebdc0'
this.address = ethUtil.pubToAddress(new Buffer(this.publicKey, 'hex'));
this.account = new Account();
this.address = ethUtil.pubToAddress(new Buffer(this.publicKey, 'hex'), true);
this.account = new EthJS.Account();
this.account.balance = 'f00000000000000001';
this.nonce = 0;
this.vm.stateManager.trie.put(this.address, this.account.serialize());
@ -292,6 +290,8 @@ UniversalDApp.prototype.getCallButton = function(args) {
self.runTx(data, args, function(err, result) {
if (err) {
replaceOutput($result, $('<span/>').text(err).addClass('error'));
} else if (result.vm.exception && result.vm.exceptionError) {
replaceOutput($result, $('<span/>').text('VM Exception: ' + result.vm.exceptionError).addClass('error'));
} else if (self.options.vm && result.vm.return === undefined) {
replaceOutput($result, $('<span/>').text('Exception during execution.').addClass('error'));
} else if (self.options.vm && isConstructor) {
@ -437,16 +437,16 @@ UniversalDApp.prototype.runTx = function( data, args, cb) {
}
} else {
try {
var tx = new Tx({
var tx = new EthJS.Tx({
nonce: new Buffer([this.nonce++]), //@todo count beyond 255
gasPrice: '01',
gasLimit: '3000000000', //plenty
gasPrice: 1,
gasLimit: 3000000000, //plenty
to: to,
value: value,
data: data
data: new Buffer(data.slice(2), 'hex')
});
tx.sign(new Buffer(this.secretKey, 'hex'));
this.vm.runTx({tx: tx}, cb);
this.vm.runTx({tx: tx, skipBalance: true, skipNonce: true, enableHomestead: true}, cb);
} catch (e) {
cb( e, null );
}

Loading…
Cancel
Save