Event function filt

This commit is contained in:
Anthony Laibe 2018-10-08 09:13:29 +01:00 committed by Pascal Precht
parent a118fc1017
commit 5fa118ae2e
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 110 additions and 40 deletions

View File

@ -2,11 +2,73 @@ import PropTypes from "prop-types";
import React from 'react'; import React from 'react';
import { import {
Page, Page,
Grid, Table Grid,
Table,
Form
} from "tabler-react"; } from "tabler-react";
const ContractLogger = ({contractName, contractLogs}) => ( class ContractLogger extends React.Component {
<Page.Content title={contractName + ' Logger'}>
getMethods() {
if (!this.props.contract.abiDefinition) {
return [];
}
return this.props.contract.abiDefinition.filter(method => (
method.name !== 'constructor' && method.mutability !== 'view' && method.mutability !== 'pure' && method.constant !== true && method.type === 'function'
));
}
getEvents() {
if (!this.props.contract.abiDefinition) {
return [];
}
return this.props.contract.abiDefinition.filter(method => method.type === 'event');
}
render() {
return (
<Page.Content title={this.props.contractName + ' Logger'}>
<Form>
<Grid.Row>
<Grid.Col md={6}>
<Form.Group label="Functions">
<Form.Select>
{this.getMethods().map((method, index) => <option key={index}>{method.name}</option>)}
</Form.Select>
</Form.Group>
</Grid.Col>
<Grid.Col md={6}>
<Form.Group label="Events">
<Form.Select>
{this.getEvents().map((event, index) => <option key={index}>{event.name}</option>)}
</Form.Select>
</Form.Group>
</Grid.Col>
<Grid.Col>
<Form.Group label="Tx Status">
<Form.Radio
isInline
label="Failed"
name="example-inline-radios"
value="option1"
/>
<Form.Radio
isInline
label="Success"
name="example-inline-radios"
value="option2"
/>
<Form.Radio
isInline
label="Any"
name="example-inline-radios"
value="option3"
/>
</Form.Group>
</Grid.Col>
</Grid.Row>
</Form>
<Grid.Row> <Grid.Row>
<Grid.Col> <Grid.Col>
<Table <Table
@ -14,39 +76,42 @@ const ContractLogger = ({contractName, contractLogs}) => (
cards cards
verticalAlign="center" verticalAlign="center"
className="text-nowrap"> className="text-nowrap">
<thead> <Table.Header>
<tr> <Table.Row>
<th>call</th> <Table.ColHeader>call</Table.ColHeader>
<th>Transaction hash</th> <Table.ColHeader>Transaction hash</Table.ColHeader>
<th>Gas Used</th> <Table.ColHeader>Gas Used</Table.ColHeader>
<th>Block number</th> <Table.ColHeader>Block number</Table.ColHeader>
<th>Status</th> <Table.ColHeader>Status</Table.ColHeader>
</tr> </Table.Row>
</thead> </Table.Header>
<tbody> <Table.Body>
{ {
contractLogs.map((log, index) => { this.props.contractLogs.map((log, index) => {
return ( return (
<tr key={'log-' + index}> <Table.Row key={'log-' + index}>
<td>{`${log.name}.${log.functionName}(${log.paramString})`}</td> <Table.Col>{`${log.name}.${log.functionName}(${log.paramString})`}</Table.Col>
<td>{log.transactionHash}</td> <Table.Col>{log.transactionHash}</Table.Col>
<td>{log.gasUsed}</td> <Table.Col>{log.gasUsed}</Table.Col>
<td>{log.blockNumber}</td> <Table.Col>{log.blockNumber}</Table.Col>
<td>{log.status}</td> <Table.Col>{log.status}</Table.Col>
</tr> </Table.Row>
); );
}) })
} }
</tbody> </Table.Body>
</Table> </Table>
</Grid.Col> </Grid.Col>
</Grid.Row> </Grid.Row>
</Page.Content> </Page.Content>
); );
}
}
ContractLogger.propTypes = { ContractLogger.propTypes = {
contractName: PropTypes.string.isRequired, contractName: PropTypes.string.isRequired,
contractLogs: PropTypes.array.isRequired contractLogs: PropTypes.array.isRequired.Header,
contract: PropTypes.object.isRequired
}; };
export default ContractLogger; export default ContractLogger;

View File

@ -31,6 +31,7 @@ function mapStateToProps(state, props) {
} }
ContractLoggerContainer.propTypes = { ContractLoggerContainer.propTypes = {
contract: PropTypes.object,
contractLogs: PropTypes.array, contractLogs: PropTypes.array,
fetchContractLogs: PropTypes.func, fetchContractLogs: PropTypes.func,
listenToContractLogs: PropTypes.func, listenToContractLogs: PropTypes.func,

View File

@ -16,6 +16,7 @@ const parseRequest = function (reqBody) {
} catch (e) { } catch (e) {
return; // Request is not a json. Do nothing return; // Request is not a json. Do nothing
} }
console.error("Request ", jsonO)
if (jsonO.method === "eth_sendTransaction") { if (jsonO.method === "eth_sendTransaction") {
commList[jsonO.id] = { commList[jsonO.id] = {
type: 'contract-log', type: 'contract-log',
@ -37,6 +38,7 @@ const parseResponse = function (ipc, resBody) {
} catch (e) { } catch (e) {
return; // Response is not a json. Do nothing return; // Response is not a json. Do nothing
} }
console.error("Response", jsonO)
if (commList[jsonO.id]) { if (commList[jsonO.id]) {
commList[jsonO.id].transactionHash = jsonO.result; commList[jsonO.id].transactionHash = jsonO.result;
transactions[jsonO.result] = {commListId: jsonO.id}; transactions[jsonO.result] = {commListId: jsonO.id};

View File

@ -1,6 +1,7 @@
pragma solidity ^0.4.25; pragma solidity ^0.4.25;
contract SimpleStorage { contract SimpleStorage {
event SetCalled(uint x);
uint public storedData; uint public storedData;
constructor(uint initialValue) public { constructor(uint initialValue) public {
@ -9,6 +10,7 @@ contract SimpleStorage {
function set(uint x) public { function set(uint x) public {
storedData = x; storedData = x;
emit SetCalled(x);
} }
function get() public view returns (uint retVal) { function get() public view returns (uint retVal) {