Skip to content

Commit

Permalink
Merge pull request ethereum#2583 from ethereum/refactor_logic6_2
Browse files Browse the repository at this point in the history
refactor blockchain logic into their own providers - 2
  • Loading branch information
yann300 authored Feb 6, 2020
2 parents 6778037 + 8683aee commit dc62bc9
Show file tree
Hide file tree
Showing 11 changed files with 693 additions and 490 deletions.
414 changes: 276 additions & 138 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/app/tabs/runTab/contractDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,24 @@ class ContractDropdownUI {
{
label: 'Force Send',
fn: () => {
this.blockchain.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, confirmationCb)
this.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, confirmationCb)
}}, {
label: 'Cancel',
fn: () => {
this.logCallback(`creation of ${selectedContract.name} canceled by user.`)
}
})
}
this.blockchain.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, confirmationCb)
this.deployContract(selectedContract, args, contractMetadata, compilerContracts, {continueCb, promptCb, statusCb, finalCb}, confirmationCb)
}

deployContract (selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb) {
const { statusCb } = callbacks
if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) {
return this.blockchain.deployContractAndLibraries(selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb)
}
if (Object.keys(selectedContract.bytecodeLinkReferences).length) statusCb(`linking ${JSON.stringify(selectedContract.bytecodeLinkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`)
this.blockchain.deployContractWithLibrary(selectedContract, args, contractMetadata, compilerContracts, callbacks, confirmationCb)
}

getConfirmationCb (modalDialog, confirmDialog) {
Expand Down
8 changes: 3 additions & 5 deletions src/app/tabs/runTab/model/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ class Recorder {
}
})

this.blockchain.event.register('transactionExecuted', (error, from, to, data, call, txResult, timestamp) => {
this.blockchain.event.register('transactionExecuted', (error, from, to, data, call, txResult, timestamp, _payload, rawAddress) => {
if (error) return console.log(error)
if (call) return

const rawAddress = this.blockchain.getAddressFromTransactionResult(txResult)
if (!rawAddress) return // not a contract creation
const stringAddress = this.addressToString(rawAddress)
const address = ethutil.toChecksumAddress(stringAddress)
Expand Down Expand Up @@ -249,13 +248,12 @@ class Recorder {
logCallBack(`(${index}) data: ${data.data}`)
record.data = { dataHex: data.data, funArgs: tx.record.parameters, funAbi: fnABI, contractBytecode: tx.record.bytecode, contractName: tx.record.contractName, timestamp: tx.timestamp }

self.blockchain.runTransaction(record, continueCb, promptCb, confirmationCb,
function (err, txResult) {
self.blockchain.runTx(record, confirmationCb, continueCb, promptCb,
function (err, txResult, rawAddress) {
if (err) {
console.error(err)
return logCallBack(err + '. Execution failed at ' + index)
}
const rawAddress = self.blockchain.getAddressFromTransactionResult(txResult)
if (rawAddress) {
const stringAddress = self.addressToString(rawAddress)
const address = ethutil.toChecksumAddress(stringAddress)
Expand Down
2 changes: 1 addition & 1 deletion src/app/tabs/runTab/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RecorderUI {
modalDialog('Confirm transaction', content,
{ label: 'Confirm',
fn: () => {
this.blockchain.udapp.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
this.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
// TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct')
Expand Down
2 changes: 1 addition & 1 deletion src/app/tabs/runTab/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SettingsUI {
if (!this.el) return
var accounts = $(this.el.querySelector('#txorigin')).children('option')
accounts.each((index, account) => {
this.blockchain.getAccountBalanceForAddress(account.value, (err, balance) => {
this.blockchain.getBalanceInEther(account.value, (err, balance) => {
if (err) return
account.innerText = helper.shortenAddress(account.value, balance)
})
Expand Down
11 changes: 8 additions & 3 deletions src/app/ui/modaldialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var yo = require('yo-yo')
var css = require('./styles/modaldialog-styles')

let incomingModal = false // in case modals are queued, ensure we are not hiding the last one.
module.exports = (title, content, ok, cancel, focusSelector, opts) => {
let agreed = true
let footerIsActive = false
Expand All @@ -9,7 +10,8 @@ module.exports = (title, content, ok, cancel, focusSelector, opts) => {
if (!container) {
document.querySelector('body').appendChild(html(opts))
container = document.querySelector(`.modal`)
}
incomingModal = false
} else incomingModal = true

var closeDiv = document.getElementById('modal-close')
if (opts.hideClose) closeDiv.style.display = 'none'
Expand Down Expand Up @@ -50,13 +52,15 @@ module.exports = (title, content, ok, cancel, focusSelector, opts) => {
function okListener () {
removeEventListener()
if (ok && ok.fn && agreed) ok.fn()
hide()
if (!incomingModal) hide()
incomingModal = false
}

function cancelListener () {
removeEventListener()
if (cancel && cancel.fn) cancel.fn()
hide()
if (!incomingModal) hide()
incomingModal = false
}

function modalKeyEvent (e) {
Expand All @@ -81,6 +85,7 @@ module.exports = (title, content, ok, cancel, focusSelector, opts) => {
container.style.display = 'none'
if (container.parentElement) container.parentElement.removeChild(container)
container = null
incomingModal = false
}

function show () {
Expand Down
19 changes: 16 additions & 3 deletions src/app/ui/universal-dapp-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
}

setLLIError('')
const fallback = self.blockchain.getFallbackInterface(contractABI)
const receive = self.blockchain.getReceiveInterface(contractABI)
const fallback = txHelper.getFallbackInterface(contractABI)
const receive = txHelper.getReceiveInterface(contractABI)
const args = {
funABI: fallback || receive,
address: address,
Expand Down Expand Up @@ -243,7 +243,20 @@ UniversalDAppUI.prototype.runTransaction = function (lookupOnly, args, valArr, i
}
}
const params = args.funABI.type !== 'fallback' ? inputsValues : ''
this.blockchain.runOrCallContractMethod(args.contractName, args.contractAbi, args.funABI, inputsValues, args.address, params, lookupOnly, logMsg, this.logCallback, outputCb, callbacksInContext)
this.blockchain.runOrCallContractMethod(
args.contractName,
args.contractAbi,
args.funABI,
inputsValues,
args.address,
params,
lookupOnly,
logMsg,
this.logCallback,
outputCb,
callbacksInContext.confirmationCb.bind(callbacksInContext),
callbacksInContext.continueCb.bind(callbacksInContext),
callbacksInContext.promptCb.bind(callbacksInContext))
}

module.exports = UniversalDAppUI
Loading

0 comments on commit dc62bc9

Please sign in to comment.