169 похожих чатов

Hi all! 1. I have a struct with nested mappings and

an additional mapping to work with its instances.

struct Vote {
uint256 startTimestamp;
bool isActive;
address winner;
mapping(address => address) voterToNominee;
mapping(address => uint32) nomineeToVoteCount;
}

mapping(uint32 => Vote) public votes;

2. I have a function called startVote(), which starts the vote:

function startVote() external onlyOwner {
uint32 voteId = voteCount++;
uint256 _startTimestamp = block.timestamp;
Vote storage _vote = votes[voteId];

_vote.startTimestamp = _startTimestamp;
_vote.isActive = true;
}

3. I also have a function vote() which allowsthe user to vote:

function vote(uint32 voteId, address nominee) external {
Vote storage _vote = votes[voteId];

_vote.voterToNominee[msg.sender] = nominee;
_vote.nomineeToVoteCount[nominee]++;
}

When I call startVote(), vote 0 starts.
When I call vote(0, %someAddress%), votes[0] doesn't reflect the changes.

Could anyone help me to understand what am I doing wrong, please?

6 ответов

10 просмотров

Hi there! Looked at your code and I'd like to see the whole thing. Looks interesting. But when you call startVote(), I don't think vote 0 starts. This is because your startVote() function says Uint32 voteId = voteCount++ Which as you know, ups the count by one. So unless you had voteCount initialized to -1 (which you can't because 'unsigned intger' -- unit) somewhere else your voteId would most definitely start with 1. Now don't take my word for it. I'm still a newbie but just pointing that out.

What do you think about the code? I think there might be a little flaw in it

Sfy-Mantissa Автор вопроса
Melchizedek
Hi there! Looked at your code and I'd like to see ...

Thank you! I'll send you the code when I finish this up.

VoteId = voteCount++ means very first voteID will be 1 right?

Sfy-Mantissa Автор вопроса
Hyun
VoteId = voteCount++ means very first voteID will ...

1. It works with 0, but even if it didn't, that is not my main concern. 2. The main concern is that I don't see the mappings inside struct updated anywhere.

Sfy Mantissa
screenshot 1. It works with 0, but even if it didn't, that is...

1. You don't update the winner 2. To access those mappings, you hafta write a getter function for them. It's a like a two dimensional array

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
program test; {$mode delphi} procedure proc(v: int32); overload; begin end; procedure proc(v: int64); overload; begin end; var x: uint64; begin proc(x); end. Уж не знаю...
notme
6
Как передать управляющий символ в открытую через CreateProcess консоль? Собсна, есть процедура: procedure TRedirectThread.WriteData(Data: OEMString); var Written: Cardinal;...
Serjone
6
вы делали что-то подобное и как? может есть либы готовые? увидел картинку нокода, где всё линиями соединено и стало интересно попробовать то же в ddl на lua сделать. решил с ч...
Victor
8
Ребят в СИ можно реализовать ООП?
Николай
33
Подскажите пожалуйста, как в CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); получить наз...
A Z
7
Карта сайта