Skip to content

Commit

Permalink
Merge pull request #1 from ethereum/1.0
Browse files Browse the repository at this point in the history
Update 1.0
  • Loading branch information
AlexanderC authored Feb 5, 2019
2 parents 7ff0082 + 9feb075 commit 5f2d965
Show file tree
Hide file tree
Showing 21 changed files with 263 additions and 69 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ jest.config.js
jest.preprocessor.js
W3cWebsocket.js
packages/**/rollup.config.js
angular-patch.js
4 changes: 2 additions & 2 deletions docs/web3-eth-ens.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The ``web3.eth.ens`` functions let you interacting with Ens.
import Web3 from 'web3';
import {Ens} from 'web3-eth-ens';
import {Accounts} from 'web3-eth-accounts;
import {Accounts} from 'web3-eth-accounts';
// "Web3.givenProvider" will be set if in an Ethereum supported browser.
const eth = new Ens(
Expand Down Expand Up @@ -388,7 +388,7 @@ Example

.. code-block:: javascript
web3.eth.ens.getText('ethereum.eth', 'key).then((result) => {
web3.eth.ens.getText('ethereum.eth', 'key').then((result) => {
console.log(result);
});
> "0000000000000000000000000000000000000000000000000000000000000000"
Expand Down
4 changes: 3 additions & 1 deletion docs/web3-eth-personal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ sign
web3.eth.personal.sign(dataToSign, address, password [, callback])
Signs data using a specific account.
Signs data using a specific account. This data is before UTF-8 HEX decoded and enveloped as follows: ``"\x19Ethereum Signed Message:\n" + message.length + message``.



.. note:: Sending your account password over an unsecured HTTP RPC connection is highly unsecure.

Expand Down
9 changes: 3 additions & 6 deletions docs/web3-shh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ Example
.. code-block:: javascript
const identities = [],
subscription = null;
const identities = [];
Promise.all([
web3.shh.newSymKey().then((id) => {identities.push(id);}),
Expand All @@ -771,7 +770,7 @@ Example
]).then(() => {
// will receive also its own message send, below
subscription = shh.subscribe("messages", {
const subscription = shh.subscribe("messages", {
symKeyID: identities[0],
topics: ['0xffaadd11']
}).on('data', console.log);
Expand All @@ -785,7 +784,7 @@ Example
payload: '0xffffffdddddd1122',
powTime: 3,
powTarget: 0.5
}).then(hash => console.log(`Message with hash ${h} was successfuly sent`))
}).then(hash => console.log(`Message with hash ${hash} was successfuly sent`))
.catch(err => console.log("Error: ", err));
});
Expand Down Expand Up @@ -1023,5 +1022,3 @@ Example
"topic": "0x01020304",
"ttl": 50
},{...}]
2 changes: 2 additions & 0 deletions packages/web3-bzz/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @date 2018
*/

import {Buffer} from 'buffer';

export class Bzz {
constructor(provider: string | {});

Expand Down
8 changes: 8 additions & 0 deletions packages/web3-core-method/src/methods/CallMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @date 2018
*/

import isFunction from 'lodash/isFunction';
import AbstractCallMethod from '../../lib/methods/AbstractCallMethod';

export default class CallMethod extends AbstractCallMethod {
Expand All @@ -42,6 +43,13 @@ export default class CallMethod extends AbstractCallMethod {
*/
beforeExecution(moduleInstance) {
this.parameters[0] = this.formatters.inputCallFormatter(this.parameters[0], moduleInstance);

// Optional second parameter 'defaultBlock' could also be the callback
if (isFunction(this.parameters[1])) {
this.callback = this.parameters[1];
this.parameters[1] = moduleInstance.defaultBlock;
}

this.parameters[1] = this.formatters.inputDefaultBlockNumberFormatter(this.parameters[1], moduleInstance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class NewAccountMethod extends AbstractCallMethod {
* @constructor
*/
constructor(utils, formatters) {
super('personal_newAccount', 0, utils, formatters);
super('personal_newAccount', 1, utils, formatters);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/web3-core-method/tests/src/methods/CallMethodTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,25 @@ describe('CallMethodTest', () => {

expect(formatters.inputCallFormatter).toHaveBeenCalledWith({}, {});
});

it('calls beforeExecution with a callback instead of the optional paramter and it calls the inputCallFormatter and inputDefaultBlockNumberFormatter', () => {
const callback = jest.fn();
method.parameters = [{}, callback];

formatters.inputCallFormatter.mockReturnValueOnce({empty: true});

formatters.inputDefaultBlockNumberFormatter.mockReturnValueOnce('0x0');

method.beforeExecution({defaultBlock: 'latest'});

expect(method.callback).toEqual(callback);

expect(method.parameters[0]).toEqual({empty: true});

expect(method.parameters[1]).toEqual('0x0');

expect(formatters.inputCallFormatter).toHaveBeenCalledWith({}, {defaultBlock: 'latest'});

expect(formatters.inputDefaultBlockNumberFormatter).toHaveBeenCalledWith('latest', {defaultBlock: 'latest'});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('NewAccountMethodTest', () => {

expect(method.rpcMethod).toEqual('personal_newAccount');

expect(method.parametersAmount).toEqual(0);
expect(method.parametersAmount).toEqual(1);

expect(method.utils).toEqual(Utils);

Expand Down
2 changes: 2 additions & 0 deletions packages/web3-core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @date 2018
*/

///<reference path='../node_modules/@types/node/index.d.ts'/>
import * as net from 'net';
import {
BatchRequest,
Expand Down Expand Up @@ -123,6 +124,7 @@ export interface RLPEncodedTransaction {
}

export interface TransactionReceipt {
status: boolean;
transactionHash: string;
transactionIndex: number;
blockHash: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/Accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Accounts extends AbstractWeb3Module {
_addAccountFunctions(account) {
// add sign functions
account.signTransaction = (tx, callback) => {
return this.signTransaction(tx, account.privateKey, callback);
return this.signTransaction(tx, account.privateKey, callback).bind(this);
};

account.sign = (data) => {
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth-contract/src/models/AbiItemModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class AbiItemModel {
this.abiItem = abiItem;
this.signature = this.abiItem.signature;
this.name = this.abiItem.name;
this.payable = this.abiItem.payable;
this.anonymous = this.abiItem.anonymous;
this.contractMethodParameters = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('AbiItemModelTest', () => {
signature: 'signature',
name: 'name',
anonymous: false,
payable: true,
type: 'function',
constant: true
};
Expand Down
49 changes: 38 additions & 11 deletions packages/web3-eth-personal/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,55 @@
*/
/**
* @file index.d.ts
* @author Huan Zhang <huanzhang30@gmail.com>
* @author Huan Zhang <huanzhang30@gmail.com>,
* @author Josh Stevens <joshstevens19@hotmail.co.uk>
* @date 2018
*/

import {Accounts} from 'web3-eth-accounts'
import {Accounts} from 'web3-eth-accounts';
import {provider} from 'web3-providers';
import {AbstractWeb3Module, Providers, RLPEncodedTransaction, Transaction, Web3ModuleOptions} from 'web3-core';

export class Personal extends AbstractWeb3Module {
constructor(
provider: provider,
accounts: Accounts,
options?: Web3ModuleOptions
);
constructor(provider: provider, accounts: Accounts, options?: Web3ModuleOptions);

newAccount(password: string, callback?: (error: Error, address: string) => void): Promise<string>;

sign(dataToSign: string, address: string, password: string, callback?: (error: Error, signature: string) => void): Promise<string>;
sign(
dataToSign: string,
address: string,
password: string,
callback?: (error: Error, signature: string) => void
): Promise<string>;

ecRecover(dataThatWasSigned: string, signature: string, callback?: (error: Error, address: string) => void): Promise<string>;
ecRecover(
dataThatWasSigned: string,
signature: string,
callback?: (error: Error, address: string) => void
): Promise<string>;

signTransaction(transation: Transaction, password: string, callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void): Promise<RLPEncodedTransaction>;
signTransaction(
transation: Transaction,
password: string,
callback?: (error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => void
): Promise<RLPEncodedTransaction>;

unlockAccount(address: string, password: string, unlockDuration: number, callback?: (error: Error) => void): Promise<boolean>;
sendTransaction(
transation: Transaction,
password: string,
callback?: (error: Error, transactionHash: string) => void
): Promise<string>;

unlockAccount(
address: string,
password: string,
unlockDuration: number,
callback?: (error: Error) => void
): Promise<boolean>;

lockAccount(address: string, callback?: (error: Error, success: boolean) => void): Promise<boolean>;

getAccounts(callback?: (error: Error, accounts: string[]) => void): Promise<string[]>;

importRawKey(privateKey: string, password: string): Promise<string>;
}
60 changes: 51 additions & 9 deletions packages/web3-eth-personal/types/tests/personal-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@
*/
/**
* @file personal-tests.ts
* @author Huan Zhang <huanzhang30@gmail.com>, Samuel Furter <samuel@ethereum.org>
* @author Huan Zhang <huanzhang30@gmail.com>
* @author Samuel Furter <samuel@ethereum.org>
* @author Josh Stevens <joshstevens19@hotmail.co.uk>
* @date 2018
*/

import {RLPEncodedTransaction} from 'web3-core';
import {Personal} from 'web3-eth-personal';
import {HttpProvider} from 'web3-providers';
import {Accounts} from 'web3-eth-accounts';

const personal = new Personal(
'http://localhost:7545',
new Accounts('http://localhost:7545', {}),
{}
);
const personal = new Personal('http://localhost:7545', new Accounts('http://localhost:7545'));

// $ExpectType Promise<string>
personal.newAccount('test password');
Expand All @@ -36,7 +33,12 @@ personal.newAccount('test password', (error: Error, address: string) => {});
// $ExpectType Promise<string>
personal.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!');
// $ExpectType Promise<string>
personal.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', (error: Error, signature: string) => {});
personal.sign(
'Hello world',
'0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
'test password!',
(error: Error, signature: string) => {}
);

// $ExpectType Promise<string>
personal.ecRecover('Hello world', '0x30755ed65396facf86c53e6217c52b4daebe72aa');
Expand Down Expand Up @@ -67,9 +69,49 @@ personal.signTransaction(
},
'test password',
(error: Error, RLPEncodedTransaction: RLPEncodedTransaction) => {}
)
);

// $ExpectType Promise<string>
personal.sendTransaction(
{
from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0',
gasPrice: '20000000000',
gas: '21000',
to: '0x3535353535353535353535353535353535353535',
value: '1000000000000000000',
data: ''
},
'test password'
);

// $ExpectType Promise<string>
personal.sendTransaction(
{
from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0',
gasPrice: '20000000000',
gas: '21000',
to: '0x3535353535353535353535353535353535353535',
value: '1000000000000000000',
data: ''
},
'test password',
(error: Error, transactionHash: string) => {}
);

// $ExpectType Promise<boolean>
personal.unlockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', 600);
// $ExpectType Promise<boolean>
personal.unlockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', 'test password!', 600, (error: Error) => {});

// $ExpectType Promise<boolean>
personal.lockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe');
// $ExpectType Promise<boolean>
personal.lockAccount('0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', (error: Error, sucess: boolean) => {});

// $ExpectType Promise<string[]>
personal.getAccounts();
// $ExpectType Promise<string[]>
personal.getAccounts((error: Error, accounts: string[]) => {});

// $ExpectType Promise<string>
personal.importRawKey('privateKey', 'blah2');
Loading

0 comments on commit 5f2d965

Please sign in to comment.