Merge two struct members in one mapping in solidity - struct

In my smart contract, I have a struct like this:
struct RewardInfo{
uint256 capitals;
uint256 statics;
uint256 directs;
uint256 diamond;
uint256 royalDiamond;
uint256 luck;
uint256 top;
uint256 royl;
uint256 dvlptFund;
uint256 dvlptFundDebt;
uint256 roi;
uint256 level2Freezed;
uint256 level2Released;
uint256 level3Freezed;
uint256 level3Released;
uint256 level4Freezed;
uint256 level4Released;
uint256 level5Freezed;
uint256 level5Released;
uint256 level6Left;
uint256 level6Freezed;
uint256 level6Released;
}
mapping (address => RewardInfo) public rewardInfo;
But becuase of member limitation of a struct in solidity, its showing stack too deep error. So, I broke the one struct into two as follows:
struct RewardInfo{
uint256 capitals;
uint256 statics;
uint256 directs;
uint256 diamond;
uint256 royalDiamond;
uint256 luck;
uint256 top;
uint256 royl;
uint256 dvlptFund;
uint256 dvlptFundDebt;
uint256 roi;
}
struct LevelInfo{
uint256 level2Freezed;
uint256 level2Released;
uint256 level3Freezed;
uint256 level3Released;
uint256 level4Freezed;
uint256 level4Released;
uint256 level5Freezed;
uint256 level5Released;
uint256 level6Left;
uint256 level6Freezed;
uint256 level6Released;
}
mapping (address => RewardInfo) public rewardInfo;
mapping (address => LevelInfo) public levelInfo;
Now, my problem is I want only one result of the mapping as follows:
mapping (address => RewardInfo) public rewardInfo;
But, since I have broken one struct into two, I have two:
mapping (address => RewardInfo) public rewardInfo;
mapping (address => LevelInfo) public levelInfo;
My question is, how do I merge the mapping into one and get only one as rewardInfo:
mapping (address => RewardInfo) public rewardInfo;
or any workaround? Any suggestion, how do I solve this problem?
Thank you very much in advance.

Related

Trying to get array of phone:balance but got latest value, and balance:balance

import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/utils/Strings.sol";
contract GoTekERC721 is ERC721, Ownable {
constructor() ERC721("Go NFT", "GoN") {}
//Owner to Phone
mapping(address => uint256[]) public phones;
//change
// Phone to Balance
mapping(uint256 => uint256) public balance;
//mapping(uint256 => uint256) public userBalances;
function register(uint256 phone, uint256 Balance) public {
_mint(msg.sender, phone);
phones[msg.sender].push(phone);
balance[phone] = Balance;
}
function details(address owner) public view returns(string memory) {
uint256[] memory ownerPhones = phones[owner];
string memory var1;
string memory var2;
for (uint256 i = 0; i < ownerPhones.length; i++) {
uint256 phone = ownerPhones[i];
mapping(uint256 => uint256) storage userBalances=balance;
var1=Strings.toString(userBalances[phone]);
var2=Strings.toString(balance[phone]);
}
return string(bytes.concat(bytes(var1),":",bytes(var2)));
}
}
I'm trying to get details output 9658965896:199, 8569856985:49, but I get latest value of balance 199:199 or 49:49 not in array also ...
How can I fix it?

solidity smart contract function

I have a simple NFT contract and trying to extract the number of tokens using _tokenIds.current(); but after deployment I call the function and it gives me this : BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null } while I am expecting a uint 256.
this is the contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/utils/Counters.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
//should I add payable here????
contract Main_NFT_contract is ERC721, Ownable {
using Counters for Counters.Counter;
using Strings for uint256;
Counters.Counter private _tokenIds;
mapping(uint256 => string) private _tokenURIs;
constructor() ERC721("NFE collection", "N*F*E") {}
function _setTokenURI(uint256 tokenId, string memory _tokenURI)
internal
virtual
{
_tokenURIs[tokenId] = _tokenURI;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
string memory _tokenURI = _tokenURIs[tokenId];
return _tokenURI;
}
function mint(address recipient, string memory uri)
public
onlyOwner
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, uri);
return newItemId;
}
function burn (uint256 tokenId)
public
onlyOwner
{
_burn(tokenId);
}
function NumberOfTokens()
public
view
returns (uint256)
{
uint256 num_token = _tokenIds.current();
return num_token;
}

Sending value from escrow contract address with transfer function

I want to call transferMoney() function which should send value (requests[_id].value) to an address address(uint160(requests[_id].provider)) with the transfer function of solidity. When I call this function via my DApp-Frontend using MetaMask, first I get the confirmation but the transaction gots reverted by the EVM. On etherscan, I see the status = fail. My aim is to send value from contract owner to another account.
What could cause the problem?
Here is the transaction hash on etherscan ropsten testnet: 0x30cef6bc33a25aeb4693a7c463ddf5dd597e0bd2c2ceb47feb38f29599feb4aa
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.21 <0.7.0;
contract PrinterMarketplace {
uint256 public requestCount = 0;
uint balance;
address payable escrow = msg.sender;
mapping(uint256 => Request) public requests;
struct Request {
uint256 id;
string fileName;
string fileHash;
address payable client;
address payable provider;
string price;
uint256 value;
string status;
}
function purchaseOffer(
uint256 _id,
address payable _client,
address payable _provider,
string memory _fileHash
) public payable{
requests[_id].status = "purchased";
requests[_id].value = msg.value;
emit OrderEvent(_id, _fileHash, _client, _provider, requests[_id].status);
escrow.transfer(msg.value);
}
function transferMoney(
uint256 _id
) public {
address(uint160(requests[_id].provider)).transfer(requests[_id].value);
requests[_id].status = "paid";
}
}

spring-data-cassandra component/complex type denormalized mapping

I'm trying to use spring-data-cassandra (1.1.2.RELEASE) and I'm running into an issue with the lack of embeddable type mapping in JPA parlance.
I have an entity class like this:
#Table
public class Customer {
private UUID id;
private String name;
private Address address;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
and the embeddable Address class:
public class Address {
private String address;
private String city;
private String state;
private String zip;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
}
My cassandra table:
create table customer (
id uuid primary key,
name text,
address text,
city text,
state text,
zip text
);
I want the properties of Address to be mapped into the containing entity, I don't want a separate table for addresses. In JPA, I believe I'd use an #Embeddable annotation. Is there some similar construct in spring-data-cassandra?
Embeddable types are not yet supported by spring-data-cassandra. A feature request is available at DATACASS-167.
The only possible part of an entity to embed is the primary key. If your primary key consists of multiple fields, you can externalize that fields into a separate class and use it afterwards with the #PrimaryKey annotation.
Comment.java
#Table("comments")
public class Comment {
#PrimaryKey
private CommentKey pk;
private String text;
}
CommentKey.java
#PrimaryKeyClass
public class CommentKey implements Serializable {
private static final long serialVersionUID = -7871651389236401141L;
#PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String author;
#PrimaryKeyColumn(ordinal = 1)
private String company;
}
HTH, Mark

How does Windows change Aero Glass color?

I'm using Windows 7 RTM and I wonder how the control panel is able to update the Aero Glass color so smoothly without restarting the DWM (uxsms). DwmSetColorizationColor isn't working any more...
The following methods should be of interest to you:
[DllImport("dwmapi.dll", EntryPoint = "#127", PreserveSig = false)]
public static extern void DwmGetColorizationParameters(out WDM_COLORIZATION_PARAMS parameters);
[DllImport("dwmapi.dll", EntryPoint = "#131", PreserveSig = false)]
public static extern void DwmSetColorizationParameters(WDM_COLORIZATION_PARAMS parameters, uint uUnknown);
public struct WDM_COLORIZATION_PARAMS {
public uint Color1;
public uint Color2;
public uint Intensity;
public uint Unknown1;
public uint Unknown2;
public uint Unknown3;
public uint Opaque;
}
Make sure you make a call to DwmIsCompositionEnabled before calling the DwmSetColorizationParameters method or it will fail.
As you can see some of the arguments/properties are unknown.
For more information, here is a link (in German)

Resources