松露迁移 解析/home/bc/supplychain/contracts/Dictionary.sol时出错:ParsedContract.sol:122:47:ParserError:状态可变性修饰符“常量”已在版本0.5.0中删除。改用“视图”或“纯”。 功能键(数据存储自身)内部常量返回(uint []){ ^ ------ ^ 编译失败。往上看。 松露v5.0.1(核心:5.0.1)
pragma solidity ^ 0.5.0;
library DictionaryUint { uint常数private NULL = 0;
struct Node {
uint prev;
uint next;
bytes data;
bool initialized;
}
struct Data {
mapping(uint => Node) list;
uint firstNodeId;
uint lastNodeId;
uint len;
}
function insertAfter(Data storage self, uint afterId, uint id, bytes data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
self.list[id].prev = afterId;
if (self.list[afterId].next == NULL) {
self.list[id].next = NULL;
self.lastNodeId = id;
} else {
self.list[id].next = self.list[afterId].next;
self.list[self.list[afterId].next].prev = id;
}
self.list[id].data = data;
self.list[id].initialized = true;
self.list[afterId].next = id;
self.len++;
}
function insertBefore(Data storage self, uint beforeId, uint id, bytes data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
self.list[id].next = beforeId;
if (self.list[beforeId].prev == NULL) {
self.list[id].prev = NULL;
self.firstNodeId = id;
} else {
self.list[id].prev = self.list[beforeId].prev;
self.list[self.list[beforeId].prev].next = id;
}
self.list[id].data = data;
self.list[id].initialized = true;
self.list[beforeId].prev = id;
self.len++;
}
function insertBeginning(Data storage self, uint id, bytes data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
if (self.firstNodeId == NULL) {
self.firstNodeId = id;
self.lastNodeId = id;
self.list[id] = Node({ prev: 0, next: 0, data: data, initialized: true });
self.len++;
} else
insertBefore(self, self.firstNodeId, id, data);
}
function insertEnd(Data storage self, uint id, bytes data) internal {
if (self.lastNodeId == NULL) insertBeginning(self, id, data);
else
insertAfter(self, self.lastNodeId, id, data);
}
function set(Data storage self, uint id, bytes data) internal {
if (exists(self, id)) {
self.list[id].data = data;
} else {
insertEnd(self, id, data);
}
}
function exists(Data storage self, uint id) internal view returns (bool) {
return self.list[id].initialized;
}
function get(Data storage self, uint id) internal view returns (bytes) {
return self.list[id].data;
}
function remove(Data storage self, uint id) internal returns (bool) {
uint nextId = self.list[id].next;
uint prevId = self.list[id].prev;
if (prevId == NULL) self.firstNodeId = nextId; //first node
else self.list[prevId].next = nextId;
if (nextId == NULL) self.lastNodeId = prevId; //last node
else self.list[nextId].prev = prevId;
delete self.list[id];
self.len--;
return true;
}
function getSize(Data storage self) internal view returns (uint) {
return self.len;
}
function next(Data storage self, uint id) internal view returns (uint) {
return self.list[id].next;
}
function prev(Data storage self, uint id) internal view returns (uint) {
return self.list[id].prev;
}
function keys(Data storage self) internal constant returns (uint[]) {
uint[] memory arr = new uint[](self.len);
uint node = self.firstNodeId;
for (uint i=0; i < self.len; i++) {
arr[i] = node;
node = next(self, node);
}
return arr;
}
}
库DictionaryBytes32 { bytes32常数private NULL = 0x0;
struct Node {
bytes32 prev;
bytes32 next;
bytes data;
bool initialized;
}
struct Data {
mapping(bytes32 => Node) list;
bytes32 firstNodeId;
bytes32 lastNodeId;
uint len;
}
function insertAfter(Data storage self, bytes32 afterId, bytes32 id, bytes data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
self.list[id].prev = afterId;
if (self.list[afterId].next == NULL) {
self.list[id].next = NULL;
self.lastNodeId = id;
} else {
self.list[id].next = self.list[afterId].next;
self.list[self.list[afterId].next].prev = id;
}
self.list[id].data = data;
self.list[id].initialized = true;
self.list[afterId].next = id;
self.len++;
}
function insertBefore(Data storage self, bytes32 beforeId, bytes32 id, bytes data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
self.list[id].next = beforeId;
if (self.list[beforeId].prev == NULL) {
self.list[id].prev = NULL;
self.firstNodeId = id;
} else {
self.list[id].prev = self.list[beforeId].prev;
self.list[self.list[beforeId].prev].next = id;
}
self.list[id].data = data;
self.list[id].initialized = true;
self.list[beforeId].prev = id;
self.len++;
}
function insertBeginning(Data storage self, bytes32 id, bytes data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
if (self.firstNodeId == NULL) {
self.firstNodeId = id;
self.lastNodeId = id;
self.list[id] = Node({ prev: 0, next: 0, data: data, initialized: true });
self.len++;
} else
insertBefore(self, self.firstNodeId, id, data);
}
function insertEnd(Data storage self, bytes32 id, bytes data) internal {
if (self.lastNodeId == NULL) insertBeginning(self, id, data);
else
insertAfter(self, self.lastNodeId, id, data);
}
function set(Data storage self, bytes32 id, bytes data) internal {
if (exists(self, id)) {
self.list[id].data = data;
} else {
insertEnd(self, id, data);
}
}
function exists(Data storage self, bytes32 id) internal view returns (bool) {
return self.list[id].initialized;
}
function get(Data storage self, bytes32 id) internal view returns (bytes) {
return self.list[id].data;
}
function remove(Data storage self, bytes32 id) internal returns (bool) {
bytes32 nextId = self.list[id].next;
bytes32 prevId = self.list[id].prev;
if (prevId == NULL) self.firstNodeId = nextId; //first node
else self.list[prevId].next = nextId;
if (nextId == NULL) self.lastNodeId = prevId; //last node
else self.list[nextId].prev = prevId;
delete self.list[id];
self.len--;
return true;
}
function getSize(Data storage self) internal view returns (uint) {
return self.len;
}
function next(Data storage self, bytes32 id) internal view returns (bytes32) {
return self.list[id].next;
}
function prev(Data storage self, bytes32 id) internal view returns (bytes32) {
return self.list[id].prev;
}
function keys(Data storage self) internal constant returns (bytes32[]) {
bytes32[] memory arr = new bytes32[](self.len);
bytes32 node = self.firstNodeId;
for (uint i=0; i < self.len; i++) {
arr[i] = node;
node = next(self, node);
}
return arr;
}
}
库DictionaryBytes32Uint { bytes32常数private NULL = 0x0;
struct Node {
bytes32 prev;
bytes32 next;
uint data;
bool initialized;
}
struct Data {
mapping(bytes32 => Node) list;
bytes32 firstNodeId;
bytes32 lastNodeId;
uint len;
}
function insertAfter(Data storage self, bytes32 afterId, bytes32 id, uint data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
self.list[id].prev = afterId;
if (self.list[afterId].next == NULL) {
self.list[id].next = NULL;
self.lastNodeId = id;
} else {
self.list[id].next = self.list[afterId].next;
self.list[self.list[afterId].next].prev = id;
}
self.list[id].data = data;
self.list[id].initialized = true;
self.list[afterId].next = id;
self.len++;
}
function insertBefore(Data storage self, bytes32 beforeId, bytes32 id, uint data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
self.list[id].next = beforeId;
if (self.list[beforeId].prev == NULL) {
self.list[id].prev = NULL;
self.firstNodeId = id;
} else {
self.list[id].prev = self.list[beforeId].prev;
self.list[self.list[beforeId].prev].next = id;
}
self.list[id].data = data;
self.list[id].initialized = true;
self.list[beforeId].prev = id;
self.len++;
}
function insertBeginning(Data storage self, bytes32 id, uint data) internal {
if (self.list[id].initialized) {
self.list[id].data = data;
return;
}
if (self.firstNodeId == NULL) {
self.firstNodeId = id;
self.lastNodeId = id;
self.list[id] = Node({ prev: 0, next: 0, data: data, initialized: true });
self.len++;
} else
insertBefore(self, self.firstNodeId, id, data);
}
function insertEnd(Data storage self, bytes32 id, uint data) internal {
if (self.lastNodeId == NULL) insertBeginning(self, id, data);
else
insertAfter(self, self.lastNodeId, id, data);
}
function set(Data storage self, bytes32 id, uint data) internal {
if (exists(self, id)) {
self.list[id].data = data;
} else {
insertEnd(self, id, data);
}
}
function increment(Data storage self, bytes32 id) internal {
if (exists(self, id)) {
self.list[id].data = self.list[id].data + 1;
} else {
insertEnd(self, id, 1);
}
}
function exists(Data storage self, bytes32 id) internal view returns (bool) {
return self.list[id].initialized;
}
function get(Data storage self, bytes32 id) internal view returns (uint) {
return self.list[id].data;
}
function remove(Data storage self, bytes32 id) internal returns (bool) {
bytes32 nextId = self.list[id].next;
bytes32 prevId = self.list[id].prev;
if (prevId == NULL) self.firstNodeId = nextId; //first node
else self.list[prevId].next = nextId;
if (nextId == NULL) self.lastNodeId = prevId; //last node
else self.list[nextId].prev = prevId;
delete self.list[id];
self.len--;
return true;
}
function getSize(Data storage self) internal view returns (uint) {
return self.len;
}
function next(Data storage self, bytes32 id) internal view returns (bytes32) {
return self.list[id].next;
}
function prev(Data storage self, bytes32 id) internal view returns (bytes32) {
return self.list[id].prev;
}
function keys(Data storage self) internal constant returns (bytes32[]) {
bytes32[] memory arr = new bytes32[](self.len);
bytes32 node = self.firstNodeId;
for (uint i=0; i < self.len; i++) {
arr[i] = node;
node = next(self, node);
}
return arr;
}
}
答案 0 :(得分:0)
constant
在实体^0.5.0
中已弃用,请将其代码中的所有实例均更改为view
或pure
。
或者,设置pragma 0.4.25
,则不必更改代码。