如何解决松露迁移错误



块菌迁移解析/home/bc/supplychain/contracts/Dictionary.sol:ParsedContract.sol:122:47:ParserError:在0.5.0版本中删除了状态可变性修饰符"constant"。请改用"view"或"pure"。函数键(数据存储自身)内部常量返回(uint[]){^------^编译失败。请参见上文。Truffle v5.0.1(核心:5.0.1)

实用主义稳固性^0.5.0;

图书馆词典Uint{uint常量私有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;
}

}

图书馆词典字节32{字节32常量私有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;
}

}

库词典字节32Uint{字节32常量私有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;
}

}

constant在solidity^0.5.0中已弃用,请将代码中的所有实例适当更改为viewpure

或者,设置pragma 0.4.25,您就不必更改代码。

最新更新