Skip to content

Commit

Permalink
Merge pull request #33 from elimu-ai/13-distribution-queue
Browse files Browse the repository at this point in the history
closes #13
  • Loading branch information
jo-elimu authored Jun 30, 2024
2 parents f961f79 + 6d1e9c0 commit 7614365
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 6 deletions.
78 changes: 78 additions & 0 deletions backend/contracts/DistributionQueue.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

enum DistributionStatus {
DeviceDelivered,
Approved,
Rejected,
Paid
}

struct Distribution {
uint256 timestamp;
address distributor;
DistributionStatus status;
}

contract DistributionQueue {
address public owner;
address public attestationHandler;
Distribution[] public queue;

event OwnerUpdated(address owner);
event AttestationHandlerUpdated(address attestationHandler);
event DistributionAdded(Distribution distribution);
event DistributionStatusUpdated(Distribution distribution);

error OnlyOwner();
error OnlyAttestationHandler();

modifier onlyOwner() {
if (msg.sender != owner) {
revert OnlyOwner();
}
_;
}

modifier onlyAttestationHandler() {
if (msg.sender != attestationHandler) {
revert OnlyAttestationHandler();
}
_;
}

constructor(address _attestationHandler) {
owner = msg.sender;
attestationHandler = _attestationHandler;
}

function updateOwner(address _owner) public onlyOwner() {
owner = _owner;
emit OwnerUpdated(_owner);
}

function updateAttestationHandler(address _attestationHandler) public onlyOwner() {
attestationHandler = _attestationHandler;
emit AttestationHandlerUpdated(_attestationHandler);
}

function addDistribution() public {
Distribution memory distribution = Distribution(
block.timestamp,
msg.sender,
DistributionStatus.DeviceDelivered
);
queue.push(distribution);
emit DistributionAdded(distribution);
}

function updateDistributionStatus(uint256 queueIndex, DistributionStatus _distributionStatus) public onlyAttestationHandler() {
Distribution memory distribution = queue[queueIndex];
distribution.status = _distributionStatus;
emit DistributionStatusUpdated(distribution);
}

function getQueueCount() public view returns (uint256) {
return queue.length;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "..\\build-info\\28f2aa4941c0aad7b62d982815fbe57b.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "DistributionQueue",
"sourceName": "contracts/DistributionQueue.sol",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_attestationHandler",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "OnlyAttestationHandler",
"type": "error"
},
{
"inputs": [],
"name": "OnlyOwner",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "attestationHandler",
"type": "address"
}
],
"name": "AttestationHandlerUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"internalType": "address",
"name": "distributor",
"type": "address"
},
{
"internalType": "enum DistributionStatus",
"name": "status",
"type": "uint8"
}
],
"indexed": false,
"internalType": "struct Distribution",
"name": "distribution",
"type": "tuple"
}
],
"name": "DistributionAdded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"internalType": "address",
"name": "distributor",
"type": "address"
},
{
"internalType": "enum DistributionStatus",
"name": "status",
"type": "uint8"
}
],
"indexed": false,
"internalType": "struct Distribution",
"name": "distribution",
"type": "tuple"
}
],
"name": "DistributionStatusUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "OwnerUpdated",
"type": "event"
},
{
"inputs": [],
"name": "addDistribution",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "attestationHandler",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getQueueCount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "queue",
"outputs": [
{
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"internalType": "address",
"name": "distributor",
"type": "address"
},
{
"internalType": "enum DistributionStatus",
"name": "status",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_attestationHandler",
"type": "address"
}
],
"name": "updateAttestationHandler",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "queueIndex",
"type": "uint256"
},
{
"internalType": "enum DistributionStatus",
"name": "_distributionStatus",
"type": "uint8"
}
],
"name": "updateDistributionStatus",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_owner",
"type": "address"
}
],
"name": "updateOwner",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b50604051610bc5380380610bc58339818101604052810190610032919061011c565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610a6d806101586000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c80638da5cb5b1161005b5780638da5cb5b146100ed578063acf8c9081461010b578063ddf0b00914610127578063fd38f0431461015957610088565b80633471b3371461008d578063503702f4146100ab5780637c55f0bd146100c7578063880cdc31146100d1575b600080fd5b610095610177565b6040516100a2919061073d565b60405180910390f35b6100c560048036038101906100c091906107ae565b610184565b005b6100cf610343565b005b6100eb60048036038101906100e6919061084c565b610474565b005b6100f5610573565b6040516101029190610888565b60405180910390f35b6101256004803603810190610120919061084c565b610597565b005b610141600480360381019061013c91906108a3565b610697565b60405161015093929190610947565b60405180910390f35b6101616106fe565b60405161016e9190610888565b60405180910390f35b6000600280549050905090565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461020b576040517f6253c6d500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000600283815481106102215761022061097e565b5b9060005260206000209060020201604051806060016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820160149054906101000a900460ff1660038111156102bf576102be6108d0565b5b60038111156102d1576102d06108d0565b5b81525050905081816040019060038111156102ef576102ee6108d0565b5b90816003811115610303576103026108d0565b5b815250507f38b8d2462768eb0c867b00a633de7efc9e7892ea2170c8c81328d8cb30fa0529816040516103369190610a1c565b60405180910390a1505050565b600060405180606001604052804281526020013373ffffffffffffffffffffffffffffffffffffffff16815260200160006003811115610386576103856108d0565b5b815250905060028190806001815401808255809150506001900390600052602060002090600202016000909190919091506000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160010160146101000a81548160ff02191690836003811115610433576104326108d0565b5b021790555050507f87b960ecf11eeabe0b9e2fa4843437f392f9ce16103e0001ff7ce1dd676f6250816040516104699190610a1c565b60405180910390a150565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104f9576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507f4ffd725fc4a22075e9ec71c59edf9c38cdeb588a91b24fc5b61388c5be41282b816040516105689190610888565b60405180910390a150565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461061c576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507f2ca1c89584b77268c72eefab1286890b5d8131e0b9629125aa856ade746deaa68160405161068c9190610888565b60405180910390a150565b600281815481106106a757600080fd5b90600052602060002090600202016000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010160149054906101000a900460ff16905083565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000819050919050565b61073781610724565b82525050565b6000602082019050610752600083018461072e565b92915050565b600080fd5b61076681610724565b811461077157600080fd5b50565b6000813590506107838161075d565b92915050565b6004811061079657600080fd5b50565b6000813590506107a881610789565b92915050565b600080604083850312156107c5576107c4610758565b5b60006107d385828601610774565b92505060206107e485828601610799565b9150509250929050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610819826107ee565b9050919050565b6108298161080e565b811461083457600080fd5b50565b60008135905061084681610820565b92915050565b60006020828403121561086257610861610758565b5b600061087084828501610837565b91505092915050565b6108828161080e565b82525050565b600060208201905061089d6000830184610879565b92915050565b6000602082840312156108b9576108b8610758565b5b60006108c784828501610774565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600481106109105761090f6108d0565b5b50565b6000819050610921826108ff565b919050565b600061093182610913565b9050919050565b61094181610926565b82525050565b600060608201905061095c600083018661072e565b6109696020830185610879565b6109766040830184610938565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6109b681610724565b82525050565b6109c58161080e565b82525050565b6109d481610926565b82525050565b6060820160008201516109f060008501826109ad565b506020820151610a0360208501826109bc565b506040820151610a1660408501826109cb565b50505050565b6000606082019050610a3160008301846109da565b9291505056fea264697066735822122030319c65cb4fa4341dc29db65ae48ce9348d09d5c160e5dbf4c0ea2b2806194464736f6c63430008180033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100885760003560e01c80638da5cb5b1161005b5780638da5cb5b146100ed578063acf8c9081461010b578063ddf0b00914610127578063fd38f0431461015957610088565b80633471b3371461008d578063503702f4146100ab5780637c55f0bd146100c7578063880cdc31146100d1575b600080fd5b610095610177565b6040516100a2919061073d565b60405180910390f35b6100c560048036038101906100c091906107ae565b610184565b005b6100cf610343565b005b6100eb60048036038101906100e6919061084c565b610474565b005b6100f5610573565b6040516101029190610888565b60405180910390f35b6101256004803603810190610120919061084c565b610597565b005b610141600480360381019061013c91906108a3565b610697565b60405161015093929190610947565b60405180910390f35b6101616106fe565b60405161016e9190610888565b60405180910390f35b6000600280549050905090565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461020b576040517f6253c6d500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000600283815481106102215761022061097e565b5b9060005260206000209060020201604051806060016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820160149054906101000a900460ff1660038111156102bf576102be6108d0565b5b60038111156102d1576102d06108d0565b5b81525050905081816040019060038111156102ef576102ee6108d0565b5b90816003811115610303576103026108d0565b5b815250507f38b8d2462768eb0c867b00a633de7efc9e7892ea2170c8c81328d8cb30fa0529816040516103369190610a1c565b60405180910390a1505050565b600060405180606001604052804281526020013373ffffffffffffffffffffffffffffffffffffffff16815260200160006003811115610386576103856108d0565b5b815250905060028190806001815401808255809150506001900390600052602060002090600202016000909190919091506000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160010160146101000a81548160ff02191690836003811115610433576104326108d0565b5b021790555050507f87b960ecf11eeabe0b9e2fa4843437f392f9ce16103e0001ff7ce1dd676f6250816040516104699190610a1c565b60405180910390a150565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146104f9576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507f4ffd725fc4a22075e9ec71c59edf9c38cdeb588a91b24fc5b61388c5be41282b816040516105689190610888565b60405180910390a150565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461061c576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507f2ca1c89584b77268c72eefab1286890b5d8131e0b9629125aa856ade746deaa68160405161068c9190610888565b60405180910390a150565b600281815481106106a757600080fd5b90600052602060002090600202016000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010160149054906101000a900460ff16905083565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000819050919050565b61073781610724565b82525050565b6000602082019050610752600083018461072e565b92915050565b600080fd5b61076681610724565b811461077157600080fd5b50565b6000813590506107838161075d565b92915050565b6004811061079657600080fd5b50565b6000813590506107a881610789565b92915050565b600080604083850312156107c5576107c4610758565b5b60006107d385828601610774565b92505060206107e485828601610799565b9150509250929050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610819826107ee565b9050919050565b6108298161080e565b811461083457600080fd5b50565b60008135905061084681610820565b92915050565b60006020828403121561086257610861610758565b5b600061087084828501610837565b91505092915050565b6108828161080e565b82525050565b600060208201905061089d6000830184610879565b92915050565b6000602082840312156108b9576108b8610758565b5b60006108c784828501610774565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600481106109105761090f6108d0565b5b50565b6000819050610921826108ff565b919050565b600061093182610913565b9050919050565b61094181610926565b82525050565b600060608201905061095c600083018661072e565b6109696020830185610879565b6109766040830184610938565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6109b681610724565b82525050565b6109c58161080e565b82525050565b6109d481610926565b82525050565b6060820160008201516109f060008501826109ad565b506020820151610a0360208501826109bc565b506040820151610a1660408501826109cb565b50505050565b6000606082019050610a3160008301846109da565b9291505056fea264697066735822122030319c65cb4fa4341dc29db65ae48ce9348d09d5c160e5dbf4c0ea2b2806194464736f6c63430008180033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"SponsorshipQueueModule#SponsorshipQueue": "0x9Af2E73663968fdfb9791b7D6Bd40cd259f0388a"
"SponsorshipQueueModule#SponsorshipQueue": "0x9Af2E73663968fdfb9791b7D6Bd40cd259f0388a",
"DistributionQueueModule#DistributionQueue": "0xB84dcB33eAEAaC81723d91A50674b27f3c5380eD"
}
Loading

0 comments on commit 7614365

Please sign in to comment.