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

method signature lookups, parameter decoding & management #2313

Merged
merged 55 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1bb08f9
add owned & signaturereg abi
jacogr Sep 24, 2016
9932603
add gpl headers
jacogr Sep 24, 2016
deec7ef
abi now maps both the method ids (baz(uint32,bool)) as well as signat…
jacogr Sep 24, 2016
7d79ccc
allow build of signaturereg dapp
jacogr Sep 24, 2016
62bf6d4
add signaturereg to hardcoded dapp list
jacogr Sep 24, 2016
ce76ab3
oops.
jacogr Sep 24, 2016
1e271d6
basic registration is operational
jacogr Sep 24, 2016
f0ed0c5
styling updates
jacogr Sep 25, 2016
35969bb
visual updates
jacogr Sep 25, 2016
e2e4994
Merge branch 'js' into jg-dapp-signaturereg
jacogr Sep 25, 2016
f06c2ef
fix merge issues
jacogr Sep 25, 2016
eaf81f7
add missing gpl headers (non-related)
jacogr Sep 25, 2016
98e782d
adjust display, expand account names
jacogr Sep 25, 2016
a09b07b
remove debug log
jacogr Sep 25, 2016
6b4b7a6
cleanup log filtering (pending vs. mined)
jacogr Sep 25, 2016
cefd529
debug info
jacogr Sep 25, 2016
7d7419d
fix event pending/mined filtering (check for actual method match)
jacogr Sep 25, 2016
7aa7e07
inverse button styling
jacogr Sep 25, 2016
f5a9b5b
show active address (needs selection)
jacogr Sep 25, 2016
120ece0
allow setting of from account address
jacogr Sep 25, 2016
de929eb
allow setting of fromAccount
jacogr Sep 25, 2016
146ca6e
Merge branch 'jg-abi-method-input-decode' into jg-dapp-signaturereg
jacogr Sep 25, 2016
8fec76c
helpers for contracts, single source
jacogr Sep 25, 2016
4a4766c
return empty when null supplied
jacogr Sep 25, 2016
275acbb
don't fail on contract creation encoding
jacogr Sep 25, 2016
a1cd82c
add contracts context
jacogr Sep 25, 2016
cf24bb2
calls gets expanded in transaction list view
jacogr Sep 25, 2016
c6a5ead
Merge branch 'jg-abi-method-input-decode' into jg-dapp-signaturereg
jacogr Sep 25, 2016
76e1591
add component for displaying decoded method inputs
jacogr Sep 26, 2016
aa5e216
split transaction row into own component
jacogr Sep 26, 2016
496869b
transaction display is closer to what we have in Signer
jacogr Sep 26, 2016
679cf09
small transaction list styling updates (align with Signer, non-shared…
jacogr Sep 26, 2016
88915c8
Merge branch 'js' into jg-dapp-signaturereg
jacogr Sep 26, 2016
24fd4ce
Merge branch 'js' into jg-dapp-signaturereg
jacogr Sep 26, 2016
abda702
small format display updates
jacogr Sep 26, 2016
3cbf646
value & token formatting
jacogr Sep 26, 2016
ff6a1fc
methods with monospace
jacogr Sep 26, 2016
6ead4ca
method decoding returns Natspec-like description of what is going on
jacogr Sep 26, 2016
a2b4823
show general value transfers as well (to contract or address)
jacogr Sep 26, 2016
a5d23dd
split between received/sent
jacogr Sep 26, 2016
a000c14
formatting updates
jacogr Sep 26, 2016
1385efc
updated signaturereg to new play contract
jacogr Sep 26, 2016
d199282
expand decoding of human-readable transactions
jacogr Sep 26, 2016
efe4491
Merge branch 'js' into jg-dapp-signaturereg
jacogr Sep 26, 2016
3b80451
Merge branch 'js' into jg-dapp-signaturereg
jacogr Sep 26, 2016
64ccce3
use IdentityIcon where addresses are displayed
jacogr Sep 26, 2016
63560e4
padding & spacing, IdentityIcon allows token transaltion everywhere
jacogr Sep 26, 2016
901006a
slightly more subtle highlights
jacogr Sep 26, 2016
16e4062
remove unused renderSimple
jacogr Sep 27, 2016
5167462
small styling alignments
jacogr Sep 27, 2016
26e5ca9
s/owner/creator/ (matching new contract interface)
jacogr Sep 27, 2016
92b7cfb
TabBar invariant error
jacogr Sep 27, 2016
6c915db
pending requests padding (unrelated, inconsequential)
jacogr Sep 27, 2016
8f3e253
updated styling & gas display
jacogr Sep 27, 2016
95ed3f7
Merge branch 'js' into jg-dapp-signaturereg
jacogr Sep 27, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion js/src/abi/spec/event/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ export default class Event {
this._name = abi.name;
this._inputs = EventParam.toEventParams(abi.inputs || []);
this._anonymous = !!abi.anonymous;
this._signature = eventSignature(this._name, this.inputParamTypes());

const { id, signature } = eventSignature(this._name, this.inputParamTypes());
this._id = id;
this._signature = signature;
}

get name () {
return this._name;
}

get id () {
return this._id;
}

get inputs () {
return this._inputs;
}
Expand Down
9 changes: 8 additions & 1 deletion js/src/abi/spec/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export default class Func {
this._payable = abi.payable;
this._inputs = Param.toParams(abi.inputs || []);
this._outputs = Param.toParams(abi.outputs || []);
this._signature = methodSignature(this._name, this.inputParamTypes());

const { id, signature } = methodSignature(this._name, this.inputParamTypes());
this._id = id;
this._signature = signature;
}

get constant () {
Expand All @@ -37,6 +40,10 @@ export default class Func {
return this._name;
}

get id () {
return this._id;
}

get payable () {
return this._payable;
}
Expand Down
6 changes: 4 additions & 2 deletions js/src/abi/util/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export function eventSignature (name, params) {
const types = (params || []).map(fromParamType).join(',');
const id = `${name || ''}(${types})`;

return keccak_256(id);
return { id, signature: keccak_256(id) };
}

export function methodSignature (name, params) {
return eventSignature(name, params).substr(0, 8);
const { id, signature } = eventSignature(name, params);

return { id, signature: signature.substr(0, 8) };
}
20 changes: 10 additions & 10 deletions js/src/abi/util/signature.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,49 @@ describe('abi/util/signature', () => {
describe('eventSignature', () => {
it('encodes signature baz() correctly', () => {
expect(eventSignature('baz', []))
.to.equal('a7916fac4f538170f7cd12c148552e2cba9fcd72329a2dd5b07a6fa906488ddf');
.to.deep.equal({ id: 'baz()', signature: 'a7916fac4f538170f7cd12c148552e2cba9fcd72329a2dd5b07a6fa906488ddf' });
});

it('encodes signature baz(uint32) correctly', () => {
expect(eventSignature('baz', [{ type: 'uint', length: 32 }]))
.to.equal('7d68785e8fc871be024b75964bd86d093511d4bc2dc7cf7bea32c48a0efaecb1');
.to.deep.equal({ id: 'baz(uint32)', signature: '7d68785e8fc871be024b75964bd86d093511d4bc2dc7cf7bea32c48a0efaecb1' });
});

it('encodes signature baz(uint32, bool) correctly', () => {
expect(eventSignature('baz', [{ type: 'uint', length: 32 }, { type: 'bool' }]))
.to.equal('cdcd77c0992ec5bbfc459984220f8c45084cc24d9b6efed1fae540db8de801d2');
.to.deep.equal({ id: 'baz(uint32,bool)', signature: 'cdcd77c0992ec5bbfc459984220f8c45084cc24d9b6efed1fae540db8de801d2' });
});

it('encodes no-name signature correctly as ()', () => {
expect(eventSignature(undefined, []))
.to.equal('861731d50c3880a2ca1994d5ec287b94b2f4bd832a67d3e41c08177bdd5674fe');
.to.deep.equal({ id: '()', signature: '861731d50c3880a2ca1994d5ec287b94b2f4bd832a67d3e41c08177bdd5674fe' });
});

it('encodes no-params signature correctly as ()', () => {
expect(eventSignature(undefined, undefined))
.to.equal('861731d50c3880a2ca1994d5ec287b94b2f4bd832a67d3e41c08177bdd5674fe');
.to.deep.equal({ id: '()', signature: '861731d50c3880a2ca1994d5ec287b94b2f4bd832a67d3e41c08177bdd5674fe' });
});
});

describe('methodSignature', () => {
it('encodes signature baz() correctly', () => {
expect(methodSignature('baz', [])).to.equal('a7916fac');
expect(methodSignature('baz', [])).to.deep.equal({ id: 'baz()', signature: 'a7916fac' });
});

it('encodes signature baz(uint32) correctly', () => {
expect(methodSignature('baz', [{ type: 'uint', length: 32 }])).to.equal('7d68785e');
expect(methodSignature('baz', [{ type: 'uint', length: 32 }])).to.deep.equal({ id: 'baz(uint32)', signature: '7d68785e' });
});

it('encodes signature baz(uint32, bool) correctly', () => {
expect(methodSignature('baz', [{ type: 'uint', length: 32 }, { type: 'bool' }])).to.equal('cdcd77c0');
expect(methodSignature('baz', [{ type: 'uint', length: 32 }, { type: 'bool' }])).to.deep.equal({ id: 'baz(uint32,bool)', signature: 'cdcd77c0' });
});

it('encodes no-name signature correctly as ()', () => {
expect(methodSignature(undefined, [])).to.equal('861731d5');
expect(methodSignature(undefined, [])).to.deep.equal({ id: '()', signature: '861731d5' });
});

it('encodes no-params signature correctly as ()', () => {
expect(methodSignature(undefined, undefined)).to.equal('861731d5');
expect(methodSignature(undefined, undefined)).to.deep.equal({ id: '()', signature: '861731d5' });
});
});
});
52 changes: 52 additions & 0 deletions js/src/contracts/contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2015, 2016 Ethcore (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 <http://www.gnu.org/licenses/>.

import Registry from './registry';
import SignatureReg from './signaturereg';
import TokenReg from './tokenreg';

let instance = null;

export default class Contracts {
constructor (api) {
instance = this;

this._api = api;
this._registry = new Registry(api);
this._signaturereg = new SignatureReg(api, this._registry);
this._tokenreg = new TokenReg(api, this._registry);
}

get registry () {
return this._registry;
}

get signatureReg () {
return this._signaturereg;
}

get tokenReg () {
return this._tokenreg;
}

static create (api) {
return new Contracts(api);
}

static get () {
return instance;
}
}
17 changes: 17 additions & 0 deletions js/src/contracts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2015, 2016 Ethcore (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 <http://www.gnu.org/licenses/>.

export default from './contracts';
74 changes: 74 additions & 0 deletions js/src/contracts/registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2015, 2016 Ethcore (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 <http://www.gnu.org/licenses/>.

import * as abis from '../json';

export default class Registry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a class here? A simple function returning an object with getContractInstance and lookupAddress would have done the job and is conceptually a lot simpler than a class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same thing for src/contracts/signaturereg.js, src/contracts/tokenreg.js and src/contracts/tokenreg.js)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On purpose, to lessen congnitive overload. Use classes everywhere, so didn't deviate. I actually realised that with the 3rdparty stuff where we don't, it takes a couple of mins to get into it when changes are to be made.

constructor (api) {
this._api = api;
this._contracts = [];
this._instance = null;

this.getInstance();
}

getInstance () {
return new Promise((resolve, reject) => {
if (this._instance) {
resolve(this._instance);
return;
}

this._api.ethcore
.registryAddress()
.then((address) => {
this._instance = this._api.newContract(abis.registry, address).instance;
resolve(this._instance);
})
.catch(reject);
});
}

getContractInstance (_name) {
const name = _name.toLowerCase();

return new Promise((resolve, reject) => {
if (this._contracts[name]) {
resolve(this._contracts[name]);
return;
}

this
.lookupAddress(name)
.then((address) => {
this._contracts[name] = this._api.newContract(abis[name], address).instance;
resolve(this._contracts[name]);
})
.catch(reject);
});
}

lookupAddress (_name) {
const name = _name.toLowerCase();

return this.getInstance().then((instance) => {
if (name === 'signaturereg') {
return '0xD1888764222dbE5BBa54F0cf9d493e43aba667Fb';
}
return instance.getAddress.call({}, [this._api.util.sha3(name), 'A']);
});
}
}
34 changes: 34 additions & 0 deletions js/src/contracts/signaturereg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2015, 2016 Ethcore (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 <http://www.gnu.org/licenses/>.

export default class SignatureReg {
constructor (api, registry) {
this._api = api;
this._registry = registry;

this.getInstance();
}

getInstance () {
return this._registry.getContractInstance('signaturereg');
}

lookup (signature) {
return this.getInstance().then((instance) => {
return instance.get.call({}, [signature]);
});
}
}
41 changes: 41 additions & 0 deletions js/src/contracts/tokenreg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2015, 2016 Ethcore (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 <http://www.gnu.org/licenses/>.

export default class TokenReg {
constructor (api, registry) {
this._api = api;
this._registry = registry;
this._instance = null;

this.getInstance();
}

getInstance () {
return this._registry.getContractInstance('tokenreg');
}

tokenCount () {
return this.getInstance().then((instance) => {
return instance.tokenCount.call();
});
}

token (index) {
return this.getInstance().then((instance) => {
return instance.token.call({}, [index]);
});
}
}
16 changes: 16 additions & 0 deletions js/src/dapps/gavcoin/parity.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2015, 2016 Ethcore (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 <http://www.gnu.org/licenses/>.

const { api } = window.parity;

export {
Expand Down
18 changes: 18 additions & 0 deletions js/src/dapps/signaturereg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Method Signature Registry</title>
<link href="//fonts.googleapis.com/css?family=Roboto:300" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Roboto+Mono:300" rel="stylesheet">
</head>
<body>
<div id="container"></div>
<script src="vendor.js"></script>
<script src="commons.js"></script>
<script src="parity.js"></script>
<script src="signaturereg.js"></script>
</body>
</html>
Loading