I am trying to create a smart contract which stores a list of users. Further, a joint account can be created between any two users. My code is given below. edge_list maps each of the linked neighbours to the balance on that link.
contract MyContract{
struct User{
uint user_id;
string user_name;
mapping(uint=>uint) edge_list;
}
mapping(uint=>User) users;
function registerUser(uint user_id, string user_name) public{
users[user_id] = User(user_id, user_name);
}
function createAcc(uint user_id_1, uint user_id_2) public{
users[user_id_1].edge_list[user_id_2] = 50;
users[user_id_2].edge_list[user_id_1] = 50;
}
When I create two users with ID 1 and 2, and try to create an account between them, I would expect users[1].edge_list[2]=50
and users[2].edge_list[1]=50
. But for some reason the output I see is users[1].edge_list[2]=50
and users[2].edge_list[2]=50
. [I am calling registerUser(1), registerUser(2) and createAcc(1,2)]
I've been trying to figure it out for the past 6 hours but haven't understood. Is there something I am missing?
users[1][2] == 50,
users[1][1] == 0
users[2][1] == 50
andusers[2][2] == 0
are all true.