forked from ethereum/solc-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abi.js
63 lines (53 loc) · 1.42 KB
/
abi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var semver = require('semver');
function update (compilerVersion, abi) {
var hasConstructor = false;
var hasFallback = false;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type === 'constructor') {
hasConstructor = true;
// <0.4.5 assumed every constructor to be payable
if (semver.lt(compilerVersion, '0.4.5')) {
item.payable = true;
}
} else if (item.type === 'fallback') {
hasFallback = true;
}
if (item.type !== 'event') {
// add 'payable' to everything
if (semver.lt(compilerVersion, '0.4.0')) {
item.payable = true;
}
// add stateMutability field
if (semver.lt(compilerVersion, '0.4.16')) {
if (item.payable) {
item.stateMutability = 'payable';
} else if (item.constant) {
item.stateMutability = 'view';
} else {
item.stateMutability = 'nonpayable';
}
}
}
}
// 0.1.2 from Aug 2015 had it. The code has it since May 2015 (e7931ade)
if (!hasConstructor && semver.lt(compilerVersion, '0.1.2')) {
abi.push({
type: 'constructor',
payable: true,
stateMutability: 'payable',
inputs: []
});
}
if (!hasFallback && semver.lt(compilerVersion, '0.4.0')) {
abi.push({
type: 'fallback',
payable: true,
stateMutability: 'payable'
});
}
return abi;
}
module.exports = {
update: update
};