Verified contractExactMIT
SwaputerQueue
Address0x0e095b67ea3addfbf92fa0dcbcb0326a828cb33d
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.34
- Same code
Only this contract
Details
- Compiler
- solc 0.8.34+commit.80d5c536
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,945,715
- Creation transaction
- 0x21d439d970…04a2b58ade
files (24) 2/InstructionQueue.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// .----------------.
// | > swaputer_ | SWAPUTER | x.com/swaputer
// |________________| the swap is the computer
/* swaputer : InstructionQueue.sol */
//
// A real first-in-first-out queue per program. Push instructions
// onto the tail, pop or skip from the head. Anyone can flush the
// whole thing at any time — this machine has no supervisor mode.
contract SwaputerQueue {
struct Instruction {
string opcode;
uint256 operand;
address pusher;
uint64 pushedAt;
}
mapping(uint256 => mapping(uint256 => Instruction)) private _queue;
mapping(uint256 => uint256) public headIndex;
mapping(uint256 => uint256) public tailIndex;
event NoOp(string reason);
event InstructionPushed(uint256 indexed programId, uint256 indexed index, string opcode);
event InstructionPopped(uint256 indexed programId, string opcode);
event QueueFlushed(uint256 indexed programId);
event InstructionRequeued(uint256 indexed programId, uint256 newIndex);
event InstructionSkipped(uint256 indexed programId);
function pushInstruction(uint256 programId, string calldata opcode, uint256 operand) external {
uint256 idx = tailIndex[programId];
_queue[programId][idx] = Instruction({
opcode: opcode,
operand: operand,
pusher: msg.sender,
pushedAt: uint64(block.timestamp)
});
tailIndex[programId] = idx + 1;
emit InstructionPushed(programId, idx, opcode);
}
function popInstruction(uint256 programId) external {
if (headIndex[programId] >= tailIndex[programId]) {
emit NoOp("queue empty");
return;
}
uint256 idx = headIndex[programId];
string memory opcode = _queue[programId][idx].opcode;
delete _queue[programId][idx];
headIndex[programId] = idx + 1;
emit InstructionPopped(programId, opcode);
}
function flushQueue(uint256 programId) external {
headIndex[programId] = tailIndex[programId];
emit QueueFlushed(programId);
}
function requeueLast(uint256 programId) external {
if (tailIndex[programId] <= headIndex[programId]) {
emit NoOp("queue empty");
return;
}
Instruction memory last = _queue[programId][tailIndex[programId] - 1];
uint256 idx = tailIndex[programId];
_queue[programId][idx] = Instruction({
opcode: last.opcode,
operand: last.operand,
pusher: msg.sender,
pushedAt: uint64(block.timestamp)
});
tailIndex[programId] = idx + 1;
emit InstructionRequeued(programId, idx);
}
function skipInstruction(uint256 programId) external {
if (headIndex[programId] >= tailIndex[programId]) {
emit NoOp("queue empty");
return;
}
headIndex[programId] += 1;
emit InstructionSkipped(programId);
}
function queueLength(uint256 programId) external view returns (uint256) {
if (tailIndex[programId] <= headIndex[programId]) return 0;
return tailIndex[programId] - headIndex[programId];
}
function peekNext(uint256 programId) external view returns (Instruction memory) {
return _queue[programId][headIndex[programId]];
}
function instructionAt(uint256 programId, uint256 index) external view returns (Instruction memory) {
return _queue[programId][index];
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.