Skip to content

Commit d16f203

Browse files
authored
issue-with-storage-location (#56)
* fix `storageLocation` * Simplify handling of storage
1 parent 86f79af commit d16f203

File tree

7 files changed

+193
-7
lines changed

7 files changed

+193
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-solidity",
3-
"version": "1.0.0-alpha.5",
3+
"version": "1.0.0-alpha.6",
44
"description": "prettier plugin for solidity",
55
"main": "src",
66
"scripts": {

src/clean.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// eslint-disable-next-line no-unused-vars
22
const clean = (ast, newObj, parent) => {
3-
['code', 'codeStart', 'loc', 'range', 'storageLocation'].forEach(name => {
3+
['code', 'codeStart', 'loc', 'range'].forEach(name => {
44
delete newObj[name]; // eslint-disable-line no-param-reassign
55
});
66
};

src/printer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,13 @@ function genericPrint(path, options, print) {
290290
}
291291
return join(
292292
' ',
293-
[doc, node.visibility, constantKeyword, node.name].filter(
294-
element => element
295-
)
293+
[
294+
doc,
295+
node.visibility,
296+
constantKeyword,
297+
node.storageLocation,
298+
node.name
299+
].filter(element => element)
296300
);
297301
}
298302
case 'ArrayTypeName':

tests/IndexOf/__snapshots__/jsfmt.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ contract IndexOf {
7979
int whatwastheval = -10; // -2 = not yet tested, as separate from -1, tested but error
8080
8181
function indexOf(string _a, string _b) returns(int) { // _a = string to search, _b = string we want to find
82-
bytes a = bytes(_a);
83-
bytes b = bytes(_b);
82+
bytes memory a = bytes(_a);
83+
bytes memory b = bytes(_b);
8484
8585
if (a.length < 1 || b.length < 1 || (b.length > a.length)) {
8686
whatwastheval = -1;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
pragma solidity ^0.4.24;
2+
3+
import "./MintableCommodity.sol";
4+
import "../participant/ISupplier.sol";
5+
import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol";
6+
7+
contract SplittableCommodity is MintableCommodity {
8+
using SafeMath for uint256;
9+
10+
event Split(address indexed to, uint256 amount, uint64 parentId, address indexed operator, bytes operatorData);
11+
12+
function split(uint _tokenId, address _to, uint256 _amount) public whenNotPaused {
13+
address supplierProxy = IContractRegistry(contractRegistry).getLatestProxyAddr("Supplier");
14+
require(
15+
msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket") ||
16+
ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"),
17+
"Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used."
18+
);
19+
20+
commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount);
21+
22+
CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({
23+
category: uint64(1),
24+
timeRegistered: uint64(now), // solium-disable-line
25+
parentId: _tokenId,
26+
value: _amount,
27+
locked: false,
28+
misc: commodities[_tokenId].misc
29+
});
30+
uint newCRCId = commodities.push(_commodity).sub(1);
31+
require(newCRCId <= 18446744073709551616, "You can only split a commodity if it is within a valid index range");
32+
33+
if(msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket")) {
34+
_transfer(ownerOf(_tokenId), _to, newCRCId);
35+
} else {
36+
_transfer(msg.sender, _to, newCRCId);
37+
}
38+
39+
callRecipient(
40+
msg.sender,
41+
0x0,
42+
_to,
43+
newCRCId,
44+
"",
45+
"",
46+
false
47+
);
48+
49+
emit Split(
50+
_to,
51+
_amount,
52+
uint64(newCRCId),
53+
msg.sender,
54+
""
55+
);
56+
}
57+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SplittableCommodity.sol 1`] = `
4+
pragma solidity ^0.4.24;
5+
6+
import "./MintableCommodity.sol";
7+
import "../participant/ISupplier.sol";
8+
import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol";
9+
10+
contract SplittableCommodity is MintableCommodity {
11+
using SafeMath for uint256;
12+
13+
event Split(address indexed to, uint256 amount, uint64 parentId, address indexed operator, bytes operatorData);
14+
15+
function split(uint _tokenId, address _to, uint256 _amount) public whenNotPaused {
16+
address supplierProxy = IContractRegistry(contractRegistry).getLatestProxyAddr("Supplier");
17+
require(
18+
msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket") ||
19+
ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"),
20+
"Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used."
21+
);
22+
23+
commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount);
24+
25+
CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({
26+
category: uint64(1),
27+
timeRegistered: uint64(now), // solium-disable-line
28+
parentId: _tokenId,
29+
value: _amount,
30+
locked: false,
31+
misc: commodities[_tokenId].misc
32+
});
33+
uint newCRCId = commodities.push(_commodity).sub(1);
34+
require(newCRCId <= 18446744073709551616, "You can only split a commodity if it is within a valid index range");
35+
36+
if(msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr("FifoCrcMarket")) {
37+
_transfer(ownerOf(_tokenId), _to, newCRCId);
38+
} else {
39+
_transfer(msg.sender, _to, newCRCId);
40+
}
41+
42+
callRecipient(
43+
msg.sender,
44+
0x0,
45+
_to,
46+
newCRCId,
47+
"",
48+
"",
49+
false
50+
);
51+
52+
emit Split(
53+
_to,
54+
_amount,
55+
uint64(newCRCId),
56+
msg.sender,
57+
""
58+
);
59+
}
60+
}
61+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62+
pragma solidity ^0.4.24;
63+
64+
import "./MintableCommodity.sol";
65+
import "../participant/ISupplier.sol";
66+
import "../../node_modules/zeppelin-solidity/contracts//math/SafeMath.sol";
67+
68+
contract SplittableCommodity is MintableCommodity {
69+
using SafeMath for uint256;
70+
71+
event Split(
72+
address indexed to,
73+
uint256 amount,
74+
uint64 parentId,
75+
address indexed operator,
76+
bytes operatorData
77+
);
78+
79+
function split(
80+
uint _tokenId,
81+
address _to,
82+
uint256 _amount
83+
) public whenNotPaused {
84+
address supplierProxy = IContractRegistry(
85+
contractRegistry
86+
).getLatestProxyAddr("Supplier");
87+
require(
88+
msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr(
89+
"FifoCrcMarket"
90+
) || ISupplier(supplierProxy).isAllowed(this, "IMintableCommodity"),
91+
"Splitting can only be done when both the ISplittableCommodity interface is enabled and is called by a supplier or the FifoCrcMarket is used."
92+
);
93+
94+
commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount);
95+
96+
CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({
97+
category: uint64(1),
98+
timeRegistered: uint64(now), // solium-disable-line
99+
parentId: _tokenId,
100+
value: _amount,
101+
locked: false,
102+
misc: commodities[_tokenId].misc
103+
});
104+
uint newCRCId = commodities.push(_commodity).sub(1);
105+
require(
106+
newCRCId <= 18446744073709551616,
107+
"You can only split a commodity if it is within a valid index range"
108+
);
109+
110+
if (msg.sender == IContractRegistry(contractRegistry).getLatestProxyAddr(
111+
"FifoCrcMarket"
112+
)) {
113+
_transfer(ownerOf(_tokenId), _to, newCRCId);
114+
} else {
115+
_transfer(msg.sender, _to, newCRCId);
116+
}
117+
118+
callRecipient(msg.sender, 0x0, _to, newCRCId, "", "", false);
119+
120+
emit Split(_to, _amount, uint64(newCRCId), msg.sender, "");
121+
}
122+
}
123+
124+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec(__dirname);

0 commit comments

Comments
 (0)