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 {
Page,
Grid, Table
Grid,
Table,
Form
} from "tabler-react";
const ContractLogger = ({contractName, contractLogs}) => (
<Page.Content title={contractName + ' Logger'}>
class ContractLogger extends React.Component {
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.Col>
<Table
@ -14,39 +76,42 @@ const ContractLogger = ({contractName, contractLogs}) => (
cards
verticalAlign="center"
className="text-nowrap">
<thead>
<tr>
<th>call</th>
<th>Transaction hash</th>
<th>Gas Used</th>
<th>Block number</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<Table.Header>
<Table.Row>
<Table.ColHeader>call</Table.ColHeader>
<Table.ColHeader>Transaction hash</Table.ColHeader>
<Table.ColHeader>Gas Used</Table.ColHeader>
<Table.ColHeader>Block number</Table.ColHeader>
<Table.ColHeader>Status</Table.ColHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{
contractLogs.map((log, index) => {
this.props.contractLogs.map((log, index) => {
return (
<tr key={'log-' + index}>
<td>{`${log.name}.${log.functionName}(${log.paramString})`}</td>
<td>{log.transactionHash}</td>
<td>{log.gasUsed}</td>
<td>{log.blockNumber}</td>
<td>{log.status}</td>
</tr>
<Table.Row key={'log-' + index}>
<Table.Col>{`${log.name}.${log.functionName}(${log.paramString})`}</Table.Col>
<Table.Col>{log.transactionHash}</Table.Col>
<Table.Col>{log.gasUsed}</Table.Col>
<Table.Col>{log.blockNumber}</Table.Col>
<Table.Col>{log.status}</Table.Col>
</Table.Row>
);
})
}
</tbody>
</Table.Body>
</Table>
</Grid.Col>
</Grid.Row>
</Page.Content>
);
);
}
}
ContractLogger.propTypes = {
contractName: PropTypes.string.isRequired,
contractLogs: PropTypes.array.isRequired
contractLogs: PropTypes.array.isRequired.Header,
contract: PropTypes.object.isRequired
};
export default ContractLogger;

View File

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

View File

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

View File

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