function UniversalDApp (contracts, options) { this.options = options || {}; this.$el = $('
'); this.contracts = contracts; if (web3.currentProvider) { } else if (options.vm) { this.stateTrie = new EthVm.Trie(); this.vm = new EthVm.VM(this.stateTrie); //@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.loadPrecompiled(this.identityAddr, this.identityCode); this.secretKey = '3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511' this.publicKey = '0406cc661590d48ee972944b35ad13ff03c7876eae3fd191e8a2f77311b0a3c6613407b5005e63d7d8d76b89d5f900cde691497688bb281e07a5052ff61edebdc0' this.address = ethUtil.pubToAddress(new Buffer(this.publicKey, 'hex')); this.account = new EthVm.Account(); this.account.balance = 'f00000000000000001'; this.nonce = 0; this.stateTrie.put(this.address, this.account.serialize()); } else { var host = options.host || "localhost"; var port = options.port || "8545"; var rpc_url = 'http://' + host + ':' + port; web3.setProvider( new web3.providers.HttpProvider( rpc_url ) ); } } UniversalDApp.prototype.render = function () { if (this.contracts.length == 0) { this.$el.append( this.getABIInputForm() ); } else { for (var c in this.contracts) { var $contractEl = $('
'); if (this.contracts[c].address) { this.getInstanceInterface(this.contracts[c], this.contracts[c].address, $contractEl ); } else { var $title = $('').text( this.contracts[c].name ); $contractEl.append( $title ).append( this.getCreateInterface( $contractEl, this.contracts[c]) ); } this.$el.append( $contractEl ); } } $legend = $('
') .append( $('
').text('Attach') ) .append( $('
').text('Transact') ) .append( $('
').text('Call') ) this.$el.append( $('
') .html("Universal ÐApp powered by The Blockchain") ) this.$el.append( $legend ) return this.$el; } UniversalDApp.prototype.getABIInputForm = function (cb){ var self = this; var $el = $('
'); var $jsonInput = $('