DEV Community

Cover image for Stalk datastruct smartcontract deployed on XinFin Network.
MahaLakshmi Perumal
MahaLakshmi Perumal

Posted on

Stalk datastruct smartcontract deployed on XinFin Network.

Lots of #smartcontracts available around but datastructure has special importance as it is used widely. Today I have deployed a stalk datastructure #smartcontract on XinFin #XDC Network under injected web3 environment.

Check my code:
pragma solidity ^0.4.11;
contract Stack {
event Popped(bytes32 top, uint number, string name);
event Pushed(bytes32 top, uint number, string name);
uint public height = 0;
bytes32 public top;
struct Object {
bytes32 next;
uint number;
string name;
}
mapping(bytes32 => Object) public objects;
function Stack() public {
}
function push(uint _number,string _name) public returns (bool) {
Object memory newObj = Object(top, _number, _name);
bytes32 id = keccak256(newObj.number, newObj.name, now, height);
objects[id] = newObj;
top = id;
height = height + 1;
Pushed(top, newObj.number, newObj.name);
}
function pop() public returns (bool) {
require(height > 0);
bytes32 _top = top;
top = objects[top].next;
Popped(top, objects[_top].number, objects[_top].name);
delete objects[_top];
}
}

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay