Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit edd801b

Browse files
committed
Merge branch '1.0' of github.com:ethereum/web3.js into 1.0
2 parents 10a80ff + f640061 commit edd801b

File tree

8 files changed

+157
-27
lines changed

8 files changed

+157
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ bower_components
1212
/bower
1313
.idea/
1414
.npm/
15+
.vscode/

docs/web3-eth.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ Example
633633

634634
.. code-block:: javascript
635635
636-
web3.eth.getBlock(3150);
636+
web3.eth.getBlock(3150)
637637
.then(console.log);
638638
639639
> {
@@ -1401,7 +1401,7 @@ Example
14011401

14021402
.. code-block:: javascript
14031403
1404-
web3.eth.getCompilers();
1404+
web3.eth.getCompilers()
14051405
.then(console.log);
14061406
> ["lll", "solidity", "serpent"]
14071407
@@ -1444,7 +1444,7 @@ Example
14441444
" }\n" +
14451445
"}\n";
14461446
1447-
web3.eth.compile.solidity(source);
1447+
web3.eth.compile.solidity(source)
14481448
.then(console.log);
14491449
14501450
> {
@@ -1521,7 +1521,7 @@ Example
15211521
15221522
var source = "...";
15231523
1524-
web3.eth.compile.lll(source);
1524+
web3.eth.compile.lll(source)
15251525
.then(console.log);
15261526
> "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056"
15271527
@@ -1556,7 +1556,7 @@ Returns
15561556
15571557
var source = "...";
15581558
1559-
var code = web3.eth.compile.serpent(source);
1559+
var code = web3.eth.compile.serpent(source)
15601560
.then(console.log);
15611561
> "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056"
15621562
@@ -1596,7 +1596,7 @@ Example
15961596

15971597
.. code-block:: javascript
15981598
1599-
web3.eth.getWork();
1599+
web3.eth.getWork()
16001600
.then(console.log);
16011601
> [
16021602
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
@@ -1642,7 +1642,7 @@ Example
16421642
"0x0000000000000001",
16431643
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
16441644
"0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000"
1645-
]);
1645+
])
16461646
.then(console.log);
16471647
> true
16481648

docs/web3-shh.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Example
206206

207207
.. code-block:: javascript
208208
209-
web3.shh.setMinPoW(0.9);
209+
web3.shh.setMinPoW(0.9)
210210
.then(console.log);
211211
> true
212212
@@ -247,7 +247,7 @@ Example
247247

248248
.. code-block:: javascript
249249
250-
web3.shh.markTrustedPeer();
250+
web3.shh.markTrustedPeer()
251251
.then(console.log);
252252
> true
253253
@@ -285,7 +285,7 @@ Example
285285

286286
.. code-block:: javascript
287287
288-
web3.shh.newKeyPair();
288+
web3.shh.newKeyPair()
289289
.then(console.log);
290290
> "5e57b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f"
291291
@@ -324,7 +324,7 @@ Example
324324

325325
.. code-block:: javascript
326326
327-
web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15');
327+
web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15')
328328
.then(console.log);
329329
> "3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f"
330330
@@ -363,7 +363,7 @@ Example
363363

364364
.. code-block:: javascript
365365
366-
web3.shh.deleteKeyPair('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
366+
web3.shh.deleteKeyPair('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
367367
.then(console.log);
368368
> true
369369
@@ -402,7 +402,7 @@ Example
402402

403403
.. code-block:: javascript
404404
405-
web3.shh.hasKeyPair('fe22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
405+
web3.shh.hasKeyPair('fe22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
406406
.then(console.log);
407407
> true
408408
@@ -441,7 +441,7 @@ Example
441441

442442
.. code-block:: javascript
443443
444-
web3.shh.getPublicKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
444+
web3.shh.getPublicKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
445445
.then(console.log);
446446
> "0x04d1574d4eab8f3dde4d2dc7ed2c4d699d77cbbdd09167b8fffa099652ce4df00c4c6e0263eafe05007a46fdf0c8d32b11aeabcd3abbc7b2bc2bb967368a68e9c6"
447447
@@ -480,7 +480,7 @@ Example
480480

481481
.. code-block:: javascript
482482
483-
web3.shh.getPrivateKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
483+
web3.shh.getPrivateKey('3e22b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
484484
.then(console.log);
485485
> "0x234234e22b9ffc2387e18636e0534534a3d0c56b0243567432453264c16e78a2adc"
486486
@@ -519,7 +519,7 @@ Example
519519

520520
.. code-block:: javascript
521521
522-
web3.shh.newSymKey();
522+
web3.shh.newSymKey()
523523
.then(console.log);
524524
> "cec94d139ff51d7df1d228812b90c23ec1f909afa0840ed80f1e04030bb681e4"
525525
@@ -558,7 +558,7 @@ Example
558558

559559
.. code-block:: javascript
560560
561-
web3.shh.addSymKey('0x5e11b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
561+
web3.shh.addSymKey('0x5e11b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
562562
.then(console.log);
563563
> "fea94d139ff51d7df1d228812b90c23ec1f909afa0840ed80f1e04030bb681e4"
564564
@@ -597,7 +597,7 @@ Example
597597

598598
.. code-block:: javascript
599599
600-
web3.shh.generateSymKeyFromPassword('Never use this password - password!');
600+
web3.shh.generateSymKeyFromPassword('Never use this password - password!')
601601
.then(console.log);
602602
> "2e57b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f"
603603
@@ -636,7 +636,7 @@ Example
636636

637637
.. code-block:: javascript
638638
639-
web3.shh.hasSymKey('f6dcf21ed6a17bd78d8c4c63195ab997b3b65ea683705501eae82d32667adc92');
639+
web3.shh.hasSymKey('f6dcf21ed6a17bd78d8c4c63195ab997b3b65ea683705501eae82d32667adc92')
640640
.then(console.log);
641641
> true
642642
@@ -675,7 +675,7 @@ Example
675675

676676
.. code-block:: javascript
677677
678-
web3.shh.getSymKey('af33b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
678+
web3.shh.getSymKey('af33b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
679679
.then(console.log);
680680
> "0xa82a520aff70f7a989098376e48ec128f25f767085e84d7fb995a9815eebff0a"
681681
@@ -714,7 +714,7 @@ Example
714714

715715
.. code-block:: javascript
716716
717-
web3.shh.deleteSymKey('bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f');
717+
web3.shh.deleteSymKey('bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f')
718718
.then(console.log);
719719
> true
720720

packages/web3-eth-abi/src/formatters.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ var formatInputBytes = function (value) {
6262
throw new Error('Given parameter bytes has an invalid length: "'+ value + '"');
6363
}
6464

65+
if (result.length > 64) {
66+
throw new Error('Given parameter bytes is too long: "' + value + '"');
67+
}
68+
6569
var l = Math.floor((result.length + 63) / 64);
6670
result = utils.padRight(result, l * 64);
6771
return new SolidityParam(result);

packages/web3/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare class Web3 {
1010
Shh: new (provider: t.Provider) => t.Shh
1111
Bzz: new (provider: t.Provider) => t.Bzz
1212
}
13-
constructor(provider: t.Provider)
13+
constructor(provider: t.Provider | string)
1414
version: string
1515
BatchRequest: new () => t.BatchRequest
1616
extend(methods: any): any // TODO

packages/web3/types.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ export declare interface TransactionReceipt {
112112
logs?: Array<Log>
113113
events?: {
114114
[eventName: string]: EventLog
115+
},
116+
status: string
117+
}
118+
export declare interface EncodedTransaction {
119+
raw: string,
120+
tx: {
121+
nonce: string,
122+
gasPrice: string,
123+
gas: string,
124+
to: string,
125+
value: string,
126+
input: string,
127+
v: string,
128+
r: string,
129+
s: string,
130+
hash: string
115131
}
116132
}
117133
export declare interface BlockHeader {
@@ -265,6 +281,10 @@ export declare interface Contract {
265281
options: {
266282
address: string
267283
jsonInterface: ABIDefinition[]
284+
data: string
285+
from: string
286+
gasPrice: string
287+
gas: number
268288
}
269289
methods: {
270290
[fnName: string]: (...args) => TransactionObject<any>
@@ -313,7 +333,7 @@ export declare class Eth {
313333
}
314334
accounts: {
315335
'new'(entropy?: string): Account
316-
privateToAccount(privKey: string): Account
336+
privateKeyToAccount(privKey: string): Account
317337
publicToAddress(key: string): string
318338
signTransaction(tx: Tx, privateKey: string, returnSignature?: boolean, cb?: (err: Error, result: string | Signature) => void): Promise<string> | Signature
319339
recoverTransaction(signature: string | Signature): string
@@ -376,6 +396,7 @@ export declare class Eth {
376396
isSyncing(cb?: Callback<boolean>): Promise<boolean>
377397
net: Net
378398
personal: Personal
399+
signTransaction(tx: Tx, address?: string, cb?: Callback<string>): Promise<EncodedTransaction>
379400
sendSignedTransaction(data: string, cb?: Callback<string>): PromiEvent<TransactionReceipt>
380401
sendTransaction(tx: Tx, cb?: Callback<string>): PromiEvent<TransactionReceipt>
381402
submitWork(nonce: string, powHash: string, digest: string, cb?: Callback<boolean>): Promise<boolean>

test/abi.encodeParameter.js

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/contract.encodeABI.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
var chai = require('chai');
2+
var assert = chai.assert;
3+
var Eth = require('../packages/web3-eth');
4+
var sha3 = require('../packages/web3-utils').sha3;
5+
var FakeIpcProvider = require('./helpers/FakeIpcProvider');
6+
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
7+
var Promise = require('bluebird');
8+
9+
var abi = [
10+
{
11+
constant: true,
12+
inputs: [
13+
{
14+
name: "a",
15+
type: "bytes32"
16+
},
17+
{
18+
name: "b",
19+
type: "bytes32"
20+
}
21+
],
22+
name: "takesTwoBytes32",
23+
outputs: [
24+
{
25+
name: "",
26+
type: "bytes32"
27+
}
28+
],
29+
payable: false,
30+
type: "function",
31+
stateMutability: "view"
32+
}
33+
];
34+
35+
describe('contract', function () {
36+
describe('method.encodeABI', function () {
37+
it('should handle bytes32 arrays that only contain 1 byte', function () {
38+
var provider = new FakeIpcProvider();
39+
var eth = new Eth(provider);
40+
41+
var contract = new eth.Contract(abi);
42+
43+
var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(2)), '0x'.concat('b'.repeat(2))).encodeABI();
44+
45+
assert.equal(result, [
46+
'0x1323517e',
47+
'aa00000000000000000000000000000000000000000000000000000000000000',
48+
'bb00000000000000000000000000000000000000000000000000000000000000'
49+
].join(''));
50+
});
51+
52+
it('should handle bytes32 arrays that are short 1 byte', function () {
53+
var provider = new FakeIpcProvider();
54+
var eth = new Eth(provider);
55+
56+
var contract = new eth.Contract(abi);
57+
58+
var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(62)), '0x'.concat('b'.repeat(62))).encodeABI();
59+
60+
assert.equal(result, [
61+
'0x1323517e',
62+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa00',
63+
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00'
64+
].join(''));
65+
});
66+
67+
it('should throw an exception on bytes32 arrays that have an invalid length', function () {
68+
var provider = new FakeIpcProvider();
69+
var eth = new Eth(provider);
70+
71+
var contract = new eth.Contract(abi);
72+
73+
var test = function () {
74+
contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(63)), '0x'.concat('b'.repeat(63))).encodeABI();
75+
}
76+
77+
assert.throws(test, 'Given parameter bytes has an invalid length: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"');
78+
});
79+
80+
it('should handle bytes32 arrays that are full', function () {
81+
var provider = new FakeIpcProvider();
82+
var eth = new Eth(provider);
83+
84+
var contract = new eth.Contract(abi);
85+
86+
var result = contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(64)), '0x'.concat('b'.repeat(64))).encodeABI();
87+
88+
assert.equal(result, [
89+
'0x1323517e',
90+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
91+
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
92+
].join(''));
93+
});
94+
95+
it('should throw an exception on bytes32 arrays that are too long', function () {
96+
var provider = new FakeIpcProvider();
97+
var eth = new Eth(provider);
98+
99+
var contract = new eth.Contract(abi);
100+
101+
var test = function() {
102+
contract.methods.takesTwoBytes32('0x'.concat('a'.repeat(66)), '0x'.concat('b'.repeat(66))).encodeABI();
103+
}
104+
105+
assert.throws(test, 'Given parameter bytes is too long: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"');
106+
});
107+
});
108+
});

0 commit comments

Comments
 (0)