// Copyright 2015-2017 Parity Technologies (UK) Ltd. // This file is part of Parity. // Parity is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Parity is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Parity. If not, see . import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { observer } from 'mobx-react'; import { connect } from 'react-redux'; import moment from 'moment'; import { throttle } from 'lodash'; import { Actionbar, ActionbarExport, ActionbarImport, Button, Dropdown, Input, Loading, Page, Toggle, Tab } from '@parity/ui'; import { CancelIcon, ListIcon, SaveIcon, SendIcon, SettingsIcon } from '@parity/ui/Icons'; import Editor from '@parity/ui/Editor'; import DeployContract from '@parity/dapp-contracts/DeployContract'; import LoadContract from './LoadContract'; import SaveContract from './SaveContract'; import ContractDevelopStore from './store'; import styles from './contractDevelop.css'; import { Debugger, TransactButton, Contract, DropdownBond } from 'parity-reactive-ui'; import { Bond } from 'oo7'; import { bonds } from 'oo7-parity'; const traceOptions = [{ text: 'trace', value: 'trace' }, { text: 'vmTrace', value: 'vmTrace' }, { text: 'stateDiff', value: 'stateDiff' }]; @observer class ContractDevelop extends Component { static propTypes = { accounts: PropTypes.object.isRequired, worker: PropTypes.object, workerError: PropTypes.any }; store = ContractDevelopStore.get(); state = { resizing: false, size: 65 }; debugDeploy = this.debugDeploy.bind(this); componentWillMount () { const { worker } = this.props; if (worker !== undefined) { this.store.setWorker(worker); } this.throttledResize = throttle(this.applyResize, 100, { leading: true }); } componentDidMount () { this.store.setEditor(this.refs.editor); if (this.props.workerError) { this.store.setWorkerError(this.props.workerError); } // Wait for editor to be loaded window.setTimeout(() => { this.store.resizeEditor(); }, 2000); } // Set the worker if not set before (eg. first page loading) componentWillReceiveProps (nextProps) { if (this.props.worker === undefined && nextProps.worker !== undefined) { this.store.setWorker(nextProps.worker); } if (this.props.workerError !== nextProps.workerError) { this.store.setWorkerError(nextProps.workerError); } } render () { console.log('render contractDevelopment'); const { sourcecode } = this.store; const { size, resizing } = this.state; const annotations = this.store.annotations .slice() .filter((a) => a.contract === ''); const panes = [ { menuItem: 'Parameters', render: () =>
{ this.renderParameters() }
}, { menuItem: 'Debugger', render: () => this.renderDebugger() }, { menuItem: 'ShowTrace', render: () => } ] } /> } ]; return (
{ this.renderDeployModal() } { this.renderSaveModal() } { this.renderLoadModal() } { this.renderActionBar() }

{ this.renderTitle() }

); } renderTitle () { const { selectedContract } = this.store; if (!selectedContract || !selectedContract.name) { return ( ); } return ( { selectedContract.name } } > ); } debugDeploy (contract) { const { contracts, contractIndex } = this.store; const bytecode = contract.bytecode; const abi = contract.interface; if (!contract.deployed) { let tx = bonds.deployContract(bytecode, JSON.parse(abi)); tx.done(s => { console.log('txDone!'); // address is undefined from s (How to become ? => TuT) , error because of triggering while triggering => can makeContract call? between here and next printout let address = s.deployed.address; contract.deployed = bonds.makeContract(address, JSON.parse(abi), [], true); contract.address = address; contract.trace = new Bond(); contract.trace.tie(v => { console.log('TIED to BOND', v); // v.then(console.log); }); contracts[contractIndex] = contract; console.log('New Contract', contract, 'index', contractIndex); }); return tx; } else { return null; } } renderDebugger () { const { contracts, compiled } = this.store; let traceMode = new Bond(); const contractKeys = Object.keys(contracts); return (
{compiled ?
{contractKeys.map((name, i) => { let c = contracts[name]; console.log('contract', c, 'index', i, 'name', name); return (
{ c.deployed ? : this.debugDeploy(c) } statusText disabled={ c.deployed } />}
); })}
: null}
); } renderActionBar () { const { sourcecode, selectedContract } = this.store; const filename = selectedContract && selectedContract.name ? selectedContract.name .replace(/[^a-z0-9]+/gi, '-') .replace(/-$/, '') .toLowerCase() : 'contract.sol'; const extension = /\.sol$/.test(filename) ? '' : '.sol'; const buttons = [