From fec740ad6f884ac617b5bd6253f311081657ad5b Mon Sep 17 00:00:00 2001 From: emizzle Date: Fri, 17 Aug 2018 18:17:14 +1000 Subject: [PATCH] Initial commit for deployment of fiddle API call set up for contract deploy which deploys the contract(s) sent from the fiddle. Frontend UI button calls API to deploy the fiddle code. --- embark-ui/src/actions/index.js | 7 +++ embark-ui/src/api/index.js | 6 ++- .../src/components/FiddleDeployButton.js | 47 +++++++++++++++++++ .../src/components/FiddleResultsSummary.js | 8 +++- embark-ui/src/containers/FiddleContainer.js | 7 ++- embark-ui/src/sagas/index.js | 16 +++++-- lib/contracts/contract.js | 22 --------- lib/modules/contracts_manager/index.js | 15 +++++- 8 files changed, 94 insertions(+), 34 deletions(-) create mode 100644 embark-ui/src/components/FiddleDeployButton.js delete mode 100644 lib/contracts/contract.js diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index c839e1038..9bab56fc1 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -175,6 +175,13 @@ export const fiddle = { failure: (error) => action(FIDDLE[FAILURE], {error}) }; +export const FIDDLE_DEPLOY = createRequestTypes('FIDDLE_DEPLOY'); +export const fiddleDeploy = { + request: (compiledCode) => action(FIDDLE_DEPLOY[REQUEST], {compiledCode}), + success: () => action(FIDDLE_DEPLOY[SUCCESS]), + failure: (error) => action(FIDDLE_DEPLOY[FAILURE], {error}) +}; + // Web Socket export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS'; export const WATCH_NEW_CONTRACT_LOGS = 'WATCH_NEW_CONTRACT_LOGS'; diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index 3718d0612..653fff8f9 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -124,6 +124,10 @@ export function webSocketBlockHeader() { return new WebSocket(`${constants.wsEndpoint}/blockchain/blockHeader`); } -export function fetchFiddle(payload) { +export function postFiddle(payload) { return post('/contract/compile', {code: payload.codeToCompile}); } + +export function postFiddleDeploy(payload) { + return post('/contract/deploy', {compiledContract: payload.compiledCode.compilationResult}); +} diff --git a/embark-ui/src/components/FiddleDeployButton.js b/embark-ui/src/components/FiddleDeployButton.js new file mode 100644 index 000000000..7805b95e7 --- /dev/null +++ b/embark-ui/src/components/FiddleDeployButton.js @@ -0,0 +1,47 @@ +import React, {Component} from 'react'; +import PropTypes from 'prop-types'; +import {Button} from 'tabler-react'; +import {fiddleDeploy as fiddleDeployAction} from '../actions'; +import {connect} from 'react-redux'; +import {getFiddle} from '../reducers/selectors'; + +class FiddleDeployButton extends Component{ + + handleClick(){ + this.props.postFiddleDeploy(this.props.fiddle); + } + render (){ + + return ( + + ); + } +} + +function mapStateToProps(state) { + return { + fiddle: getFiddle(state), + error: state.errorMessage, + loading: state.loading, + compiledContract: state.compiledContract + }; +} + +FiddleDeployButton.propTypes = { + fiddle: PropTypes.object, + postFiddleDeploy: PropTypes.func, + loading: PropTypes.bool, + compiledContract: PropTypes.object, + error: PropTypes.string +}; + +export default connect( + mapStateToProps, + { + postFiddleDeploy: fiddleDeployAction.request + }, +)(FiddleDeployButton); diff --git a/embark-ui/src/components/FiddleResultsSummary.js b/embark-ui/src/components/FiddleResultsSummary.js index 4a977421e..88b4cfa9f 100644 --- a/embark-ui/src/components/FiddleResultsSummary.js +++ b/embark-ui/src/components/FiddleResultsSummary.js @@ -1,6 +1,7 @@ import React, {Component} from 'react'; import {Badge, Icon} from 'tabler-react'; import PropTypes from 'prop-types'; +import FiddleDeployButton from './FiddleDeployButton'; class FiddleResultsSummary extends Component{ @@ -21,7 +22,12 @@ class FiddleResultsSummary extends Component{ } else { if(hasResult && !errors.length){ - renderings.push(Compiled); + renderings.push( + + Compiled + + + ); } if(errors.length) renderings.push( diff --git a/embark-ui/src/containers/FiddleContainer.js b/embark-ui/src/containers/FiddleContainer.js index d43ce130b..f57cb0541 100644 --- a/embark-ui/src/containers/FiddleContainer.js +++ b/embark-ui/src/containers/FiddleContainer.js @@ -27,7 +27,7 @@ class FiddleContainer extends Component { this.setState({value: newValue}); if (this.compileTimeout) clearTimeout(this.compileTimeout); this.compileTimeout = setTimeout(() => { - this.props.fetchFiddle(newValue); + this.props.postFiddle(newValue); }, 1000); } @@ -136,14 +136,13 @@ function mapStateToProps(state) { FiddleContainer.propTypes = { fiddle: PropTypes.object, error: PropTypes.string, - fetchFiddle: PropTypes.func, + postFiddle: PropTypes.func, loading: PropTypes.bool }; export default connect( mapStateToProps, { - fetchFiddle: fiddleAction.request - //fetchBlock: blockAction.request + postFiddle: fiddleAction.request }, )(FiddleContainer); diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 668767a14..34d74a238 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -5,7 +5,7 @@ import {all, call, fork, put, takeEvery, take} from 'redux-saga/effects'; const {account, accounts, block, blocks, transaction, transactions, processes, commands, processLogs, contracts, contract, contractProfile, messageSend, versions, plugins, messageListen, fiddle, - ensRecord, ensRecords, contractLogs, contractFile, contractFunction, contractDeploy} = actions; + fiddleDeploy, ensRecord, ensRecords, contractLogs, contractFile, contractFunction, contractDeploy} = actions; function *doRequest(entity, apiFn, payload) { const {response, error} = yield call(apiFn, payload); @@ -34,7 +34,8 @@ export const fetchContractProfile = doRequest.bind(null, contractProfile, api.fe export const fetchContractFile = doRequest.bind(null, contractFile, api.fetchContractFile); export const postContractFunction = doRequest.bind(null, contractFunction, api.postContractFunction); export const postContractDeploy = doRequest.bind(null, contractDeploy, api.postContractDeploy); -export const fetchFiddle = doRequest.bind(null, fiddle, api.fetchFiddle); +export const postFiddle = doRequest.bind(null, fiddle, api.postFiddle); +export const postFiddleDeploy = doRequest.bind(null, fiddleDeploy, api.postFiddleDeploy); export const sendMessage = doRequest.bind(null, messageSend, api.sendMessage); export const fetchEnsRecord = doRequest.bind(null, ensRecord, api.fetchEnsRecord); export const postEnsRecord = doRequest.bind(null, ensRecords, api.postEnsRecord); @@ -127,8 +128,12 @@ export function *watchListenToMessages() { yield takeEvery(actions.MESSAGE_LISTEN[actions.REQUEST], listenToMessages); } -export function *watchFetchFiddle() { - yield takeEvery(actions.FIDDLE[actions.REQUEST], fetchFiddle); +export function *watchPostFiddle() { + yield takeEvery(actions.FIDDLE[actions.REQUEST], postFiddle); +} + +export function *watchPostFiddleDeploy() { + yield takeEvery(actions.FIDDLE_DEPLOY[actions.REQUEST], postFiddleDeploy); } function createChannel(socket) { @@ -216,7 +221,8 @@ export default function *root() { fork(watchSendMessage), fork(watchFetchContract), fork(watchFetchTransaction), - fork(watchFetchFiddle), + fork(watchPostFiddle), + fork(watchPostFiddleDeploy), fork(watchFetchEnsRecord), fork(watchPostEnsRecords) ]); diff --git a/lib/contracts/contract.js b/lib/contracts/contract.js deleted file mode 100644 index df2aa6770..000000000 --- a/lib/contracts/contract.js +++ /dev/null @@ -1,22 +0,0 @@ -class Contract { - constructor(className, compiledContract, gas, gasPrice, type = 'file') { - this.className = className; - this.gas = gas; - this.gasPrice = gasPrice; - this.type = type; - this.compiledContract = compiledContract; - } - - set compiledContract(compiledContract) { - this.code = compiledContract.code; - this.runtimeBytecode = compiledContract.runtimeBytecode; - this.realRuntimeBytecode = (contract.realRuntimeBytecode || contract.runtimeBytecode); - this.swarmHash = compiledContract.swarmHash; - this.gasEstimates = compiledContract.gasEstimates; - this.functionHashes = compiledContract.functionHashes; - this.abiDefinition = compiledContract.abiDefinition; - this.filename = compiledContract.filename; - this.originalFilename = compiledContract.originalFilename || ("contracts/" + contract.filename); - } - -} \ No newline at end of file diff --git a/lib/modules/contracts_manager/index.js b/lib/modules/contracts_manager/index.js index de2f339df..c7710f420 100644 --- a/lib/modules/contracts_manager/index.js +++ b/lib/modules/contracts_manager/index.js @@ -164,9 +164,22 @@ class ContractsManager { self.events.request('contracts:all', null, res.send.bind(res)); } ); + + plugin.registerAPICall( + 'post', + '/embark-api/contract/deploy', + (req, res) => { + self.compiledContracts = req.body.compiledContract; + self.build((err, _mgr) => { + const responseData = {errors: err, success: !err}; + this.logger.trace(`POST response /embark-api/contract/deploy:\n ${JSON.stringify(responseData)}`); + res.send(responseData); + }, false); + } + ); } - build(done) { + build(done, useContractFiles = true) { let self = this; self.contracts = {};