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.
This commit is contained in:
parent
2800e347de
commit
fec740ad6f
|
@ -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';
|
||||
|
|
|
@ -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});
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
<Button
|
||||
color="success"
|
||||
onClick={(e) => this.handleClick(e)}>
|
||||
Deploy
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
|
@ -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(<Badge key="success" className="badge-link" color="success">Compiled</Badge>);
|
||||
renderings.push(
|
||||
<React.Fragment key="success">
|
||||
<Badge className="badge-link" color="success">Compiled</Badge>
|
||||
<FiddleDeployButton />
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
if(errors.length) renderings.push(
|
||||
<React.Fragment key="errors">
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
]);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 = {};
|
||||
|
||||
|
|
Loading…
Reference in New Issue