简体   繁体   English

如何解决松露迁移错误?

[英]how to solve truffle migrate erro?

truffle migrate Error parsing /home/bc/supplychain/contracts/Dictionary.sol: ParsedContract.sol:122:47: ParserError: The state mutability modifier "constant" was removed in version 0.5.0. 松露迁移错误解析/home/bc/supplychain/contracts/Dictionary.sol:ParsedContract.sol:122:47:ParserError:状态可变性修饰符“常量”已在版本0.5.0中删除。 Use "view" or "pure" instead. 改用“视图”或“纯”。 function keys(Data storage self) internal constant returns (uint[]) { ^------^ Compilation failed. 功能键(数据存储自身)内部常量返回(uint []){^ ------ ^编译失败。 See above. 往上看。 Truffle v5.0.1 (core: 5.0.1) 松露v5.0.1(核心:5.0.1)

pragma solidity ^0.5.0; 语用强度^ 0.5.0;

library DictionaryUint { uint constant private NULL = 0; 库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;
}

} }

library DictionaryBytes32 { bytes32 constant private NULL = 0x0; 库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;
}

} }

library DictionaryBytes32Uint { bytes32 constant private NULL = 0x0; 库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;
}

} }

constant is deprecated in solidity ^0.5.0 , change all the instances of it in your code to view or pure appropriately. constant ^0.5.0已弃用constant ,请在代码中更改其所有实例以进行view或适当地pure

Alternatively, set pragma 0.4.25 and you will not have to change your code. 或者,设置pragma 0.4.25 ,而不必更改代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM