Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

misc: Move types. Renaming/typos in comments. Fix linting errors. Add license headers. Add FIXMEs #44

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract.instance.callMe

## apis

APIs implement the calls as exposed in the [Ethcore JSON Ethereum RPC](https://github.com/paritytech/js-api) definitions. Mapping follows the naming conventions of the originals, i.e. `eth_call` becomes `eth.call`, `personal_accounts` becomes `personal.accounts`, etc.
APIs implement the calls as exposed in the [Parity JSON Ethereum RPC](https://github.com/paritytech/js-api) definitions. Mapping follows the naming conventions of the originals, i.e. `eth_call` becomes `eth.call`, `personal_accounts` becomes `personal.accounts`, etc.

## public node

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you rebase on top of master? I merged the other one.

// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/api.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/contract/contract.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/contract/contract.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/contract/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/format/input.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
56 changes: 30 additions & 26 deletions packages/api/src/format/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import BigNumber from 'bignumber.js';

import { BlockNumber } from '../types';
import { BlockNumber, InputDeriveHashMap, InputOptions, InputOptionsConditions, InputTrace, InputTraceHashMap } from '../types';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer in this PR to not touch anything in packages/api. This package needs some bigger effort to make it clean, see #21.

import { isArray, isHex, isInstanceOf, isString } from '../util/types';
import { padLeft, toHex } from '../util/format';

Expand Down Expand Up @@ -56,7 +56,7 @@ export const inHash = (hash: string) => {
return inHex(hash);
};

export const inTopics = topics => {
export const inTopics = (topics: Array<any>): Array<any> | string | null => {
return (topics || []).filter(topic => topic === null || topic).map(topic => {
if (topic === null) {
return null;
Expand All @@ -70,29 +70,29 @@ export const inTopics = topics => {
});
};

export const inFilter = options => {
export const inFilter = (options: InputOptions) => {
if (options) {
Object.keys(options).forEach(key => {
switch (key) {
case 'address':
if (isArray(options[key])) {
options[key] = options[key].map(inAddress);
options[key] = (options[key] as Array<string | number>).map(inAddress);
} else {
options[key] = inAddress(options[key]);
options[key] = inAddress(options[key] as string);
}
break;

case 'fromBlock':
case 'toBlock':
options[key] = inBlockNumber(options[key]);
options[key] = inBlockNumber(options[key] as BlockNumber);
break;

case 'limit':
options[key] = inNumber10(options[key]);
options[key] = inNumber10(options[key] as BlockNumber);
break;

case 'topics':
options[key] = inTopics(options[key]);
options[key] = inTopics(options[key] as Array<any>);
}
});
}
Expand Down Expand Up @@ -140,7 +140,7 @@ export const inOptionsCondition = (condition: {
return null;
};

export const inOptions = (_options = {}) => {
export const inOptions = (_options: InputOptions = {}) => {
const options = Object.assign({}, _options);

Object.keys(options).forEach(key => {
Expand All @@ -149,38 +149,38 @@ export const inOptions = (_options = {}) => {
// Don't encode the `to` option if it's empty
// (eg. contract deployments)
if (options[key]) {
options.to = inAddress(options[key]);
options.to = inAddress(options[key] as string);
}
break;

case 'from':
options[key] = inAddress(options[key]);
options[key] = inAddress(options[key] as string);
break;

case 'condition':
options[key] = inOptionsCondition(options[key]);
options[key] = inOptionsCondition(options[key] as InputOptionsConditions);
break;

case 'gas':
case 'gasPrice':
options[key] = inNumber16(new BigNumber(options[key]).round());
options[key] = inNumber16(new BigNumber(options[key] as string).toFixed() as BlockNumber);
break;

case 'value':
case 'nonce':
options[key] = inNumber16(options[key]);
options[key] = inNumber16(options[key] as BlockNumber);
break;

case 'data':
options[key] = inData(options[key]);
options[key] = inData(options[key] as string);
break;
}
});

return options;
};

export const inTraceFilter = filterObject => {
export const inTraceFilter = (filterObject: InputTraceHashMap) => {
if (filterObject) {
Object.keys(filterObject).forEach(key => {
switch (key) {
Expand All @@ -193,7 +193,7 @@ export const inTraceFilter = filterObject => {

case 'toBlock':
case 'fromBlock':
filterObject[key] = inBlockNumber(filterObject[key]);
filterObject[key] = inBlockNumber(filterObject[key] as BlockNumber);
break;
}
});
Expand All @@ -202,29 +202,31 @@ export const inTraceFilter = filterObject => {
return filterObject;
};

export const inTraceType = whatTrace => {
export const inTraceType = (whatTrace: InputTrace): InputTrace => {
if (isString(whatTrace)) {
return [whatTrace];
}

return whatTrace;
};

export const inDeriveType = derive => {
export const inDeriveType = (derive: InputDeriveHashMap): string => {
return derive && derive.type === 'hard' ? 'hard' : 'soft';
};

export const inDeriveHash = derive => {
const hash = derive && derive.hash ? derive.hash : derive;
const type = inDeriveType(derive);
export const inDeriveHash = (derive: InputDeriveHashMap | string): InputDeriveHashMap => {
const hash = derive && (derive as InputDeriveHashMap).hash
? ((derive as InputDeriveHashMap).hash) as string
: derive as string;
const type = inDeriveType(derive as InputDeriveHashMap);

return {
hash: inHex(hash),
type
};
};

export const inDeriveIndex = derive => {
export const inDeriveIndex = (derive: Array<InputDeriveHashMap | BlockNumber> | InputDeriveHashMap): Array<InputDeriveIndexHashMap | number | null> => {
if (!derive) {
return [];
}
Expand All @@ -233,12 +235,14 @@ export const inDeriveIndex = derive => {
derive = [derive];
}

return derive.map(item => {
const index = inNumber10(item && item.index ? item.index : item);
return (derive as Array<InputDeriveHashMap | BlockNumber>).map(item => {
const index = inNumber10(item && ((item as InputDeriveHashMap).index) as BlockNumber
? ((item as InputDeriveHashMap).index) as BlockNumber
: (item as BlockNumber));

return {
index,
type: inDeriveType(item)
type: inDeriveType(item as InputDeriveHashMap)
};
});
};
2 changes: 1 addition & 1 deletion packages/api/src/format/output.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/format/output.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/library.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/current.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/current.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/http.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/http.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/provider/ipc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -72,7 +72,7 @@ class Ipc extends EventEmitter {

requestNewToken () {
return new Promise((resolve, reject) => {
// Webview is ready when receivin the ping
// Webview is ready when receiving the ping
ipcRenderer.once('ping', () => {
this.send(METHOD_REQUEST_TOKEN, [], (error, token) => {
if (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/ipc.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/postMessage.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/promise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/sendAsync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/sendAsync.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/ws.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/provider/ws.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/eth/eth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/eth/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/net/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/net/net.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/parity/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/parity/parity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/pubsub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/pubsub/pubsub.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/pubsub/pubsubBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
Expand All @@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

class PubSubBase {
// Provider for websocket pubsub transport
// Provider for Websocket pub-sub transport
constructor (provider) {
this._provider = provider;
}
Expand Down
Loading