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. Use "view" or "pure" instead.
function keys(Data storage self) internal constant returns (uint[]) {
^------^
Compilation failed. See above.
Truffle v5.0.1 (core: 5.0.1)
pragma solidity ^0.5.0;
library DictionaryUint {
uint constant 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;
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;
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.
Alternatively, set pragma 0.4.25 and you will not have to change your code.
Related
I just copied a smart contract in Arbitum Goerli and tried to deploy it in Remix IDE.
https://arbiscan.io/token/0xdd8e557c8804d326c72074e987de02a23ae6ef84#code
But I received this error.
I tried adjusting the Gas limit and WEI. No luck.
This is the error message.
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error.
{
"code": -32000,
"message": "execution reverted"
}
I appreciate your help in advance.
pragma solidity ^0.8.7;
pragma experimental ABIEncoderV2;
import "#openzeppelin/contracts/token/ERC20/IERC20.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/utils/math/SafeMath.sol";
import "#openzeppelin/contracts/utils/Address.sol";
import "#uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "#uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import "#uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
contract LamboArbInu is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
address private constant DEAD = 0x000000000000000000000000000000000000dEaD;
string private _name;
string private _symbol;
uint8 private _decimals;
address public router;
address public basePair;
uint256 public prevDevFee;
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromDevFee;
mapping(address => bool) private _isExcludedFromMaxAmount;
mapping(address => bool) private _isDevWallet;
address[] private _excluded;
address public _devWalletAddress;
uint256 private _tTotal;
uint256 public _devFee;
uint256 private _previousDevFee = _devFee;
uint256 public _maxTxAmount;
uint256 public _maxHeldAmount;
IUniswapV2Router02 public uniswapV2Router;
IUniswapV2Pair public uniswapV2Pair;
constructor(
address tokenOwner,
address devWalletAddress_,
address _router,
address _basePair
) {
_name = "LamboArbInu";
_symbol = "LAMBOARBINU";
_decimals = 18;
_tTotal = 1000000000 * 10**_decimals;
_tOwned[tokenOwner] = _tTotal;
_devFee = 4;
_previousDevFee = _devFee;
_devWalletAddress = devWalletAddress_;
_maxHeldAmount = _tTotal.mul(20).div(1000); // 2%
_maxTxAmount = _maxHeldAmount;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(_router);
// Create a uniswap pair for this new token
uniswapV2Pair = IUniswapV2Pair(
IUniswapV2Factory(_uniswapV2Router.factory()).createPair(
address(this),
_basePair
)
);
// set the rest of the contract variables
uniswapV2Router = _uniswapV2Router;
//exclude owner and this contract from fee
_isExcludedFromDevFee[owner()] = true;
_isExcludedFromDevFee[address(this)] = true;
_isExcludedFromDevFee[_devWalletAddress] = true;
_isExcludedFromMaxAmount[owner()] = true;
_isExcludedFromMaxAmount[address(this)] = true;
_isExcludedFromMaxAmount[_devWalletAddress] = true;
//set wallet provided to true
_isDevWallet[_devWalletAddress] = true;
emit Transfer(address(0), tokenOwner, _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _tOwned[account];
}
function getBasePairAddr() public view returns (address) {
return basePair;
}
function transfer(address recipient, uint256 amount)
public
override
returns (bool)
{
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address _owner, address spender)
public
view
override
returns (uint256)
{
return _allowances[_owner][spender];
}
function approve(address spender, uint256 amount)
public
override
returns (bool)
{
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
public
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].add(addedValue)
);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue)
public
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(
subtractedValue,
"ERC20: decreased allowance below zero"
)
);
return true;
}
function excludeFromFee(address account) public onlyOwner {
require(!_isExcludedFromDevFee[account], "Account is already excluded");
_isExcludedFromDevFee[account] = true;
}
function includeInFee(address account) public onlyOwner {
require(_isExcludedFromDevFee[account], "Account is already included");
_isExcludedFromDevFee[account] = false;
}
function excludeFromMaxAmount(address account) public onlyOwner {
require(
!_isExcludedFromMaxAmount[account],
"Account is already excluded"
);
_isExcludedFromMaxAmount[account] = true;
}
function includeInMaxAmount(address account) public onlyOwner {
require(
_isExcludedFromMaxAmount[account],
"Account is already included"
);
_isExcludedFromMaxAmount[account] = false;
}
function setDevFeePercent(uint256 devFee) external onlyOwner {
require(devFee >= 0, "teamFee out of range");
_devFee = devFee;
}
function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner {
require(maxTxPercent <= 100, "maxTxPercent out of range");
_maxTxAmount = _tTotal.mul(maxTxPercent).div(10**2);
}
function setDevWalletAddress(address _addr) public onlyOwner {
require(!_isDevWallet[_addr], "Wallet address already set");
if (!_isExcludedFromDevFee[_addr]) {
excludeFromFee(_addr);
}
_isDevWallet[_addr] = true;
_devWalletAddress = _addr;
}
function replaceDevWalletAddress(address _addr, address _newAddr)
external
onlyOwner
{
require(_isDevWallet[_addr], "Wallet address not set previously");
if (_isExcludedFromDevFee[_addr]) {
includeInFee(_addr);
}
_isDevWallet[_addr] = false;
if (_devWalletAddress == _addr) {
setDevWalletAddress(_newAddr);
}
}
//to recieve ETH from uniswapV2Router when swaping
receive() external payable {}
function _getValues(uint256 tAmount)
private
view
returns (uint256, uint256)
{
uint256 tDev = calculateDevFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tDev);
return (tTransferAmount, tDev);
}
function _takeDev(uint256 tDev) private {
_tOwned[_devWalletAddress] = _tOwned[_devWalletAddress].add(tDev);
}
function calculateDevFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_devFee).div(10**2);
}
function removeAllFee() private {
if (_devFee == 0) return;
_previousDevFee = _devFee;
_devFee = 0;
}
function restoreAllFee() private {
_devFee = _previousDevFee;
}
function isExcludedFromFee(address account) public view returns (bool) {
return _isExcludedFromDevFee[account];
}
function isExcludedFromMaxAmount(address account)
public
view
returns (bool)
{
return _isExcludedFromMaxAmount[account];
}
function _approve(
address _owner,
address spender,
uint256 amount
) private {
require(_owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[_owner][spender] = amount;
emit Approval(_owner, spender, amount);
}
function _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
// Only limit max TX for swaps, not for standard transactions
if (
from == address(uniswapV2Router) || to == address(uniswapV2Router)
) {
if (
!_isExcludedFromMaxAmount[from] && !_isExcludedFromMaxAmount[to]
)
require(
amount <= _maxTxAmount,
"Transfer amount exceeds the maxTxAmount."
);
}
//indicates if fee should be deducted from transfer
bool takeFee = true;
//if any account belongs to _isExcludedFromDevFee account then remove the fee
if (_isExcludedFromDevFee[from] || _isExcludedFromDevFee[to]) {
takeFee = false;
}
if (!_isExcludedFromMaxAmount[to]) {
require(
_tOwned[to].add(amount) <= _maxHeldAmount,
"Recipient already owns maximum amount of tokens."
);
}
//transfer amount, it will take dev, liquidity fee
_tokenTransfer(from, to, amount, takeFee);
//reset tax fees
restoreAllFee();
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> WHT
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = getBasePairAddr();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ETHAmount) private {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(uniswapV2Router), tokenAmount);
// add the liquidity
uniswapV2Router.addLiquidityETH{value: ETHAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
DEAD,
block.timestamp
);
}
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(
address sender,
address recipient,
uint256 amount,
bool takeFee
) private {
if (!takeFee) removeAllFee();
(uint256 tTransferAmount, uint256 tDev) = _getValues(amount);
_tOwned[sender] = _tOwned[sender].sub(amount);
_tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
_takeDev(tDev);
emit Transfer(sender, recipient, tTransferAmount);
}
function disableFees() public onlyOwner {
removeAllFee();
}
function enableFees() public onlyOwner {
restoreAllFee();
}
}
I am trying to create a function that returns an array of strings. Sadly instead of returning an array that has N number of elements of type string, it just appends all my string values to the first and only element in the array.
pragma solidity ^0.8.7;
contract Store is Ownable {
struct Product {
string name;
uint32 quantity;
bool exists;
}
uint64 private productId;
mapping(uint => Product) private products;
constructor() {
productId = 1;
}
function addProduct(string calldata name, uint32 quantity) public onlyOwner
require(quantity > 0, "Quantity cannot be negative integer");
productId = productId + 1;
products[productId] = Product(name, quantity, true);
}
function listProducts() external view returns (string[] memory){
string[] memory productsInfo = new string[](productId);
if(productId < 1){
return productsInfo;
}
for(uint i = 0; i < productId; i++){
string memory info = products[i + 1].name;
productsInfo[i] = info;
}
return productsInfo;
}
}
If I add products a, b, c. The json result from colling listProducts() looks like this:
{
"0": "string[]: a,b,c"
}
the contract is working.
Solidity display the elements in array with commas between them.
Array return start with "0" string[].
Hope it will help
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
contract Store{
struct Product {
string name;
uint32 quantity;
bool exists;
}
address private Owner;
uint64 private productId;
mapping(uint => Product) private products;
constructor() {
productId = 1;
Owner = msg.sender;
}
modifier onlyOwner{
require(msg.sender == Owner, "Fail! only admin can access this
function!");
_;
}
function addProduct(string calldata _name, uint32 _quantity) public
onlyOwner{
Product memory _strucObj;
_strucObj.name = _name;
_strucObj.quantity = _quantity;
products[productId -1] = _strucObj;
productId++;
}
function listProducts() external view returns (string[] memory){
string[] memory productsInfo = new string[](productId);
if(productId < 1){
return productsInfo;
}
//dash symbol used for concatenation
string memory dash = "-";
for(uint i = 0; i < productId; i++){
string memory info = products[i].name;
productsInfo[i] = info;
}
return productsInfo;
}
function CheckProductsByIndex(uint index) public view returns(string memory name)
{
string[] memory productsInfo = new string[](productId);
for(uint i = 0; i < productId; i++)
{
string memory _toArray = products[i].name;
productsInfo[i] = _toArray;
}
return productsInfo[index];
}
}
I created a Solidity Contract. What information should go in "Enter the Solidity Contract Code below?"
Below I am also listing the solidity code I used.
I tried putting the code in directly and the website errors out on me.
I am also attaching the link to the contract on polygonscan
https://polygonscan.com/token/0xd1a8ee4c74e0153aa1282967336b4a35f60a8dab
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract EmbassyBuddhas is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.05 ether;
uint256 public presaleCost = 0.03 ether;
uint256 public maxSupply = 10000;
uint256 public maxMintAmount = 20;
bool public paused = false;
mapping(address => bool) public whitelisted;
mapping(address => bool) public presaleWallets;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
mint(msg.sender, 20);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function mint(address _to, uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
if (whitelisted[msg.sender] != true) {
if (presaleWallets[msg.sender] != true) {
//general public
require(msg.value >= cost * _mintAmount);
} else {
//presale
require(msg.value >= presaleCost * _mintAmount);
}
}
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(_to, supply + i);
}
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
//only owner
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setPresaleCost(uint256 _newCost) public onlyOwner {
presaleCost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function whitelistUser(address _user) public onlyOwner {
whitelisted[_user] = true;
}
function removeWhitelistUser(address _user) public onlyOwner {
whitelisted[_user] = false;
}
function addPresaleUser(address _user) public onlyOwner {
presaleWallets[_user] = true;
}
function add100PresaleUsers(address[100] memory _users) public onlyOwner {
for (uint256 i = 0; i < 2; i++) {
presaleWallets[_users[i]] = true;
}
}
function removePresaleUser(address _user) public onlyOwner {
presaleWallets[_user] = false;
}
function withdraw() public payable onlyOwner {
(bool success, ) = payable(msg.sender).call{
value: address(this).balance
}("");
require(success);
}
}
if you are having problems verifying contract code is because in your contract you are importing code from others contract, but you are not pasting that code there, I'll recommend you to check how to "flatten" a contract in the tool you are using and paste the flattened contract there
I would prefer to use frameworks such as truffle and hardhat to verify the contract because it will help you to make it easy.
So you can read more details How to verify contract on this link
Here is the Json Result :
"[{\"EmpId\":1,\"Full_Name\":\"Parth Dave\",\"City\":\"\"},{\"EmpId\":2,\"Full_Name\":\"Chirag\",\"City\":\"\"},{\"EmpId\":3,\"Full_Name\":\"Jay\",\"City\":\"\"}]"
Here is my code:
public string GetProducts()
{
var empQuery = from emp in objEmployeeEntities.Employees
select new EmployeeClass() { EmpId = emp.EmpId, Full_Name = emp.Full_Name };
var settings = new JsonSerializerSettings() { ContractResolver = new NullToEmptyStringResolver() };
var str = JsonConvert.SerializeObject(empQuery.ToList(), settings);
return str;
}
public class NullToEmptyStringValueProvider : IValueProvider
{
PropertyInfo _MemberInfo;
public NullToEmptyStringValueProvider(PropertyInfo memberInfo)
{
_MemberInfo = memberInfo;
}
public object GetValue(object target)
{
object result = _MemberInfo.GetValue(target);
if (_MemberInfo.PropertyType == typeof(string) && result == null) result = "";
return result;
}
public void SetValue(object target, object value)
{
_MemberInfo.SetValue(target, value);
}
}
public class NullToEmptyStringResolver : Newtonsoft.Json.Serialization.DefaultContractResolver
{
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
return type.GetProperties()
.Select(p =>
{
var jp = base.CreateProperty(p, memberSerialization);
jp.ValueProvider = new NullToEmptyStringValueProvider(p);
return jp;
}).ToList();
}
}
I am building a Windows Phone Application using Mango with SQLCE 4.0 (I think).
I get this error when I am trying to submit a new OrderItem, with context.SubmitChanges() command.
A duplicate value cannot be inserted into a unique index. [Table
name = Order,Constraint name = PK_Order]
Here is some code:
[Table]
public partial class Order : BCSDataContextBase //Base only icludes NotifyProperty....
{
private int _id;
private int _orderId;
private EntitySet<OrderItem> _items;
private DateTime _dateCreated = DateTime.Now;
private DateTime _dateModified = DateTime.Now;
[Column(IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int Id
{
get { return _id; }
set {
if (_id != value) {
NotifyPropertyChanging("Id");
_id = value;
NotifyPropertyChanged("Id");
}
}
}
[Column(IsPrimaryKey = true, DbType = "INT NOT NULL", CanBeNull = false)]
public int OrderId
{
get { return _orderId; }
set
{
if (_orderId != value) {
NotifyPropertyChanging("OrderId");
_orderId = value;
NotifyPropertyChanged("OrderId");
}
}
}
[Association(Storage = "_items", ThisKey="OrderId", OtherKey = "OrderId")]
public EntitySet<OrderItem> Items
{
get { return this._items; }
set { this._items.Assign(value); }
}
// Version column aids update performance.
[Column(IsVersion = true)]
private Binary _version;
public Order()
{
this._items = new EntitySet<OrderItem>(
new Action<OrderItem>(this.attach_Item),
new Action<OrderItem>(this.detach_Item)
);
}
private void attach_Item(OrderItem entity)
{
NotifyPropertyChanging("OrderItem");
entity.Order = this;
}
private void detach_Item(OrderItem entity)
{
NotifyPropertyChanging("OrderItem");
entity.Order = null;
}
}
[Table]
public partial class OrderItem : BCSDataContextBase
{
private int _id;
private int _orderId;
private string _productId;
private int _quantity;
private EntityRef<Order> _order;
public OrderItem()
{
this._order = default(EntityRef<Order>);
}
[Column(IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int Id
{
get { return _id; }
set
{
if (_id != value) {
NotifyPropertyChanging("Id");
_id = value;
NotifyPropertyChanged("Id");
}
}
}
[Column(Storage = "_orderId", DbType = "Int NOT NULL", AutoSync = AutoSync.OnInsert)]
public int OrderId
{
get { return this._orderId; }
set
{
if (this._orderId != value)
{
NotifyPropertyChanging("OrderId");
this._orderId = value;
NotifyPropertyChanged("OrderId");
}
}
}
[Column(Storage = "_productId", IsPrimaryKey = true)]
public string ProductId
{
get { return _productId; }
set
{
if (_productId != value)
{
NotifyPropertyChanging("ProductId");
_productId = value;
NotifyPropertyChanged("ProductId");
}
}
}
[Column(Storage = "_quantity", DbType = "Int NOT NULL")]
public int Quantity
{
get { return this._quantity; }
set
{
if (this._quantity != value)
{
NotifyPropertyChanging("Quantity");
this._quantity = value;
NotifyPropertyChanged("Quantity");
}
}
}
// Entity reference, to identity the Order "storage" table
[Association(Name = "Order_Order_Item", Storage = "_order", ThisKey = "OrderId", OtherKey = "OrderId", IsForeignKey = true)]
public Order Order
{
get { return this._order.Entity; }
set
{
NotifyPropertyChanging("Order");
this._order.Entity = value;
if (value != null)
{
value.Items.Add(this);
this._orderId = value.OrderId;
}
else { this._orderId = default(int); }
NotifyPropertyChanging("Order");
}
}
}
I cant see what I am doing wrong.
Here's the L2SQL code:
public bool SaveOrderItemByOrder(OrderItem newItem)
{
bool successfullySaved = false;
using (var context = DataObjectFactory.CreateContext())
{
var item = db.OrderItems.Where(i => i.ProductId == newItem.ProductId).FirstOrDefault();
try
{
if (item != null)
{
item.Quantity = newItem.Quantity;
db.SubmitChanges();
}
else
{
db.OrderItems.InsertOnSubmit(newItem);
db.SubmitChanges();
}
successfullySaved = true;
}
catch (Exception ex)
{
throw ex;
successfullySaved = false;
}
}
return successfullySaved;
}
I Hope someone can help me out, i have already put to many hours on this problem!
EDIT:
I tried this code:
context.OrderItems.InsertOnSubmit(new OrderItem { Order = (new Order { OrderId = 1234567 }), ProductId = "sdfsdf3dsf", Quantity = Quantity });
context.SubmitChanges();
And i got same error, but when I changed the OrderId to whatever it works. The problem is that if I submitting an orderitem on that order, it will be that orderId, so I guess there are some problem in the association ?