getLocksStatus fix
This commit is contained in:
parent
8f51b7841c
commit
4c8016080d
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/c2945254d468f158cf92840fd9e49825.json"
|
||||
"buildInfo": "../../build-info/4a149f14ea0fec7293fb79d89ccb9fe7.json"
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -872,11 +872,7 @@ contract P2PIX is
|
|||
}
|
||||
|
||||
/// @notice External getter that returns the status of a lockIDs array.
|
||||
/// @dev The `ids` array gets sorted in descending order
|
||||
/// if a non-initialized counter value is provided as an array item.
|
||||
/// @dev The `ids` array gets sorted in ascending order
|
||||
/// if all provided array items are initialized.
|
||||
/// @dev Call will not revert if provided with an empty array.
|
||||
/// @dev Call will not revert if provided with an empty array as parameter.
|
||||
/// @dev Function sighash: 0x49ef8448
|
||||
function getLocksStatus(uint256[] memory ids)
|
||||
external
|
||||
|
@ -896,9 +892,6 @@ contract P2PIX is
|
|||
uint256 len =
|
||||
ids.length;
|
||||
|
||||
(ids, len, c) = sort(ids);
|
||||
|
||||
if (c == 0x00) {
|
||||
bool[] memory status =
|
||||
new bool[](len);
|
||||
uint256[] memory sortedIDs =
|
||||
|
@ -917,85 +910,6 @@ contract P2PIX is
|
|||
}
|
||||
return(sortedIDs, status);
|
||||
}
|
||||
else if (c == len - 1) {
|
||||
uint256 p;
|
||||
bool[] memory status =
|
||||
new bool[](len - 1);
|
||||
uint256[] memory sortedIDs =
|
||||
new uint256[](len - 1);
|
||||
while (c != 0) {
|
||||
if(
|
||||
mapLocks[ids[c]].expirationBlock
|
||||
< block.number ||
|
||||
mapLocks[ids[c]].amount == 0x0) {
|
||||
sortedIDs[p] = ids[c];
|
||||
status[p] = false; c--; ++p;
|
||||
} else {
|
||||
sortedIDs[p] = ids[c];
|
||||
status[p] = true; c--; ++p;
|
||||
}
|
||||
}
|
||||
return(sortedIDs, status);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Adapted from Solady's LibSort.
|
||||
/// (https://github.com/vectorized/solady/blob/main/src/utils/Sort.sol)
|
||||
function sort(uint256[] memory _ids)
|
||||
private
|
||||
view
|
||||
returns(
|
||||
uint256[] memory _sorted,
|
||||
uint256 _len,
|
||||
uint256 _c
|
||||
)
|
||||
{
|
||||
uint256 index;
|
||||
uint256 len = _ids.length;
|
||||
while (index < len)
|
||||
{ if(mapLocks[_ids[index]].sellerKey == 0x0)
|
||||
{ delete _ids[index]; ++index; } else ++index; }
|
||||
|
||||
assembly {
|
||||
let n := mload(_ids)
|
||||
mstore(_ids, 0)
|
||||
for { let i := add(_ids, 32) }
|
||||
iszero(0) {} {
|
||||
i := add(i, 32)
|
||||
if gt(i, add(
|
||||
_ids,
|
||||
mul(n, 32))) { break }
|
||||
let k := mload(i)
|
||||
let j := sub(i, 32)
|
||||
let v := mload(j)
|
||||
if iszero(gt(v, k)) { continue }
|
||||
for {} iszero(0) {} {
|
||||
mstore(add(j, 32), v)
|
||||
j := sub(j, 32)
|
||||
v := mload(j)
|
||||
if iszero(gt(v, k)) { break }}
|
||||
mstore(add(j, 32), k) }
|
||||
mstore(_ids, n)
|
||||
if iszero(lt(mload(_ids), 2)) {
|
||||
let x := add(_ids, 32)
|
||||
let y := add(_ids, 64)
|
||||
let end := add(
|
||||
_ids,
|
||||
mul(add(mload(_ids), 1), 32))
|
||||
for {} iszero(0) {} {
|
||||
if iszero(eq(mload(x), mload(y))) {
|
||||
x := add(x, 32)
|
||||
mstore(x, mload(y)) }
|
||||
y := add(y, 32)
|
||||
if eq(y, end) { break }}
|
||||
mstore(_ids, div(sub(x, _ids), 32)) }
|
||||
_sorted := _ids
|
||||
_len := mload(_ids)
|
||||
switch iszero(mload(add(_ids,32)))
|
||||
case 0 { _c := 0 }
|
||||
case 1 { _c := sub(_len, 1) }
|
||||
}
|
||||
}
|
||||
|
||||
/// @notice Public method that handles `address`
|
||||
/// to `uint256` safe type casting.
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -937,35 +937,54 @@ describe("P2PIX", () => {
|
|||
const key = await p2pix.callStatic._castAddrToKey(owner.address);
|
||||
|
||||
const lockStatus1 = await p2pix.callStatic.getLocksStatus([1,7,7,2,3,4,5,5,2,3]);
|
||||
const lockStatus2 = await p2pix.callStatic.getLocksStatus([1,2,3]);
|
||||
const lockStatus3 = await p2pix.callStatic.getLocksStatus([7,7,5,14,666]);
|
||||
const lockStatus2 = await p2pix.callStatic.getLocksStatus([0,1,2,3]);
|
||||
const lockStatus3 = await p2pix.callStatic.getLocksStatus([7,7,333,14,777]);
|
||||
const lockStatus4 = await p2pix.callStatic.getLocksStatus([]);
|
||||
|
||||
const ls1: [BigNumber[], boolean[]] = [
|
||||
[
|
||||
ethers.BigNumber.from(3),
|
||||
ethers.constants.Two,
|
||||
ethers.constants.One,
|
||||
], [true, true, true] ];
|
||||
ethers.BigNumber.from(7),
|
||||
ethers.BigNumber.from(7),
|
||||
ethers.constants.Two,
|
||||
ethers.BigNumber.from(3),
|
||||
ethers.BigNumber.from(4),
|
||||
ethers.BigNumber.from(5),
|
||||
ethers.BigNumber.from(5),
|
||||
ethers.constants.Two,
|
||||
ethers.BigNumber.from(3),
|
||||
],
|
||||
[
|
||||
true, false,
|
||||
false, true,
|
||||
true, false,
|
||||
false, false,
|
||||
true, true,
|
||||
]];
|
||||
|
||||
const ls2: [BigNumber[], boolean[]] = [
|
||||
[
|
||||
ethers.constants.Zero,
|
||||
ethers.constants.One,
|
||||
ethers.constants.Two,
|
||||
ethers.BigNumber.from(3),
|
||||
], [true, true, true] ];
|
||||
], [false, true, true, true] ];
|
||||
|
||||
const ls3: [BigNumber[], boolean[]] = [
|
||||
[
|
||||
ethers.constants.Zero,
|
||||
], [false] ];
|
||||
ethers.BigNumber.from(7),
|
||||
ethers.BigNumber.from(7),
|
||||
ethers.BigNumber.from(333),
|
||||
ethers.BigNumber.from(14),
|
||||
ethers.BigNumber.from(777),
|
||||
], [false, false, false, false, false] ];
|
||||
|
||||
const ls4 = [[],[]];
|
||||
|
||||
expect(tx1).to.be.ok;
|
||||
expect(tx2).to.be.ok;
|
||||
expect(tx3).to.be.ok;
|
||||
|
||||
|
||||
expect(lockStatus1[0].toString()).to.equal(ls1[0].toString());
|
||||
expect(lockStatus1[1].toString()).to.equal(ls1[1].toString());
|
||||
expect(lockStatus2[0].toString()).to.equal(ls2[0].toString());
|
||||
|
|
Loading…
Reference in New Issue