Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Pass value & type through from event log params
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Oct 22, 2016
1 parent 85f3c38 commit 6532f69
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 24 deletions.
4 changes: 3 additions & 1 deletion js/src/api/contract/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export default class Contract {
log.event = event.name;

decoded.params.forEach((param) => {
log.params[param.name] = param.token.value;
const { type, value } = param.token;

log.params[param.name] = { type, value };
});

return log;
Expand Down
4 changes: 4 additions & 0 deletions js/src/dapps/basiccoin/Deploy/Events/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export default class Events extends Component {

logToEvent = (log) => {
log.key = api.util.sha3(JSON.stringify(log));
log.params = Object.keys(log.params).reduce((params, name) => {
params[name] = log.params[name].value;
return params;
}, {});

return log;
}
Expand Down
5 changes: 4 additions & 1 deletion js/src/dapps/basiccoin/Transfer/Events/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export default class Events extends Component {

logToEvent = (log) => {
log.key = api.util.sha3(JSON.stringify(log));
log.params = Object.keys(log.params).reduce((params, name) => {
params[name] = log.params[name].value;
return params;
}, {});

return log;
}
Expand All @@ -139,7 +143,6 @@ export default class Events extends Component {
.concat(pendingEvents)
.filter((log) => !minedNew.find((event) => event.transactionHash === log.transactionHash));
const events = [].concat(pendingNew).concat(minedNew);
console.log('*** events', events.map((event) => event.address));
this.setState({ loading: false, events, minedEvents: minedNew, pendingEvents: pendingNew });
}
}
5 changes: 4 additions & 1 deletion js/src/dapps/gavcoin/Events/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ export default class Events extends Component {
logIndex,
transactionHash,
transactionIndex,
params,
params: Object.keys(params).reduce((data, name) => {
data[name] = params[name].value;
return data;
}, {}),
key
};
};
Expand Down
8 changes: 4 additions & 4 deletions js/src/dapps/registry/Events/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const renderEvent = (classNames, verb) => (e, accounts, contacts) => {

return (
<tr key={ e.key } className={ classes }>
<td>{ renderAddress(e.parameters.owner, accounts, contacts) }</td>
<td>{ renderAddress(e.parameters.owner.value, accounts, contacts) }</td>
<td><abbr title={ e.transaction }>{ verb }</abbr></td>
<td><code>{ renderHash(bytesToHex(e.parameters.name)) }</code></td>
<td><code>{ renderHash(bytesToHex(e.parameters.name.value)) }</code></td>
<td>{ renderStatus(e.timestamp, e.state === 'pending') }</td>
</tr>
);
Expand All @@ -64,10 +64,10 @@ const renderDataChanged = (e, accounts, contacts) => {

return (
<tr key={ e.key } className={ classNames }>
<td>{ renderAddress(e.parameters.owner, accounts, contacts) }</td>
<td>{ renderAddress(e.parameters.owner.value, accounts, contacts) }</td>
<td><abbr title={ e.transaction }>updated</abbr></td>
<td>
key <code>{ new Buffer(e.parameters.plainKey).toString('utf8') }</code> of <code>{ renderHash(bytesToHex(e.parameters.name)) }</code>
key <code>{ new Buffer(e.parameters.plainKey.value).toString('utf8') }</code> of <code>{ renderHash(bytesToHex(e.parameters.name.value)) }</code>
</td>
<td>{ renderStatus(e.timestamp, e.state === 'pending') }</td>
</tr>
Expand Down
5 changes: 4 additions & 1 deletion js/src/dapps/signaturereg/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const logToEvent = (log) => {
logIndex,
transactionHash,
transactionIndex,
params,
params: Object.keys(params).reduce((data, name) => {
data[name] = params[name].value;
return data;
}, {}),
key
};
};
Expand Down
16 changes: 8 additions & 8 deletions js/src/dapps/tokenreg/Status/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,41 +148,41 @@ export const subscribeEvents = () => (dispatch, getState) => {
return dispatch(setTokenData(params.id.toNumber(), {
tla: '...',
base: -1,
address: params.addr,
name: params.name,
address: params.addr.value,
name: params.name.value,
isPending: true
}));
}

if (event === 'Registered' && type === 'mined') {
return dispatch(loadToken(params.id.toNumber()));
return dispatch(loadToken(params.id.value.toNumber()));
}

if (event === 'Unregistered' && type === 'pending') {
return dispatch(setTokenPending(params.id.toNumber(), true));
return dispatch(setTokenPending(params.id.value.toNumber(), true));
}

if (event === 'Unregistered' && type === 'mined') {
return dispatch(deleteToken(params.id.toNumber()));
return dispatch(deleteToken(params.id.value.toNumber()));
}

if (event === 'MetaChanged' && type === 'pending') {
return dispatch(setTokenData(
params.id.toNumber(),
params.id.value.toNumber(),
{ metaPending: true, metaMined: false }
));
}

if (event === 'MetaChanged' && type === 'mined') {
setTimeout(() => {
dispatch(setTokenData(
params.id.toNumber(),
params.id.value.toNumber(),
{ metaPending: false, metaMined: false }
));
}, 5000);

return dispatch(setTokenData(
params.id.toNumber(),
params.id.value.toNumber(),
{ metaPending: false, metaMined: true }
));
}
Expand Down
16 changes: 8 additions & 8 deletions js/src/views/Contract/Events/Event/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class Event extends Component {
const keys = Object.keys(event.params).map((key, index) => {
return <div className={ styles.key } key={ `${event.key}_key_${index}` }>{ key }</div>;
});
const values = Object.values(event.params).map((value, index) => {
const values = Object.values(event.params).map((param, index) => {
return (
<div className={ styles.value } key={ `${event.key}_val_${index}` }>
{ this.renderValue(value) }
{ this.renderParam(param) }
</div>
);
});
Expand All @@ -82,16 +82,16 @@ class Event extends Component {
);
}

renderValue (value) {
renderParam (param) {
const { api } = this.context;

if (api.util.isInstanceOf(value, BigNumber)) {
return value.toFormat(0);
} else if (api.util.isArray(value)) {
return api.util.bytesToHex(value);
if (api.util.isInstanceOf(param.value, BigNumber)) {
return param.value.toFormat(0);
} else if (api.util.isArray(param.value)) {
return api.util.bytesToHex(param.value);
}

return value.toString();
return param.value.toString();
}

formatBlockTimestamp (block) {
Expand Down

0 comments on commit 6532f69

Please sign in to comment.