1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
// Created by Caduceus.foundation
pragma solidity ^0.8.4;
contract ConsensusContract {
struct CommitBlockInfo {
uint256 block_number;
address miner;
bytes block_hash;
bytes state_root;
bytes receipts_root;
bytes tx_root;
}
mapping(uint256=>CommitBlockInfo) committedBlocks;
struct VirtualBlockInfo {
uint256 block_number;
uint256 block_time;
bytes batch_txs;
}
uint256 nextBlockNumber;
mapping(uint256=>VirtualBlockInfo) virtualblocks;
address private _owner;
modifier onlyOwner() {
require(msg.sender == _owner, "Only owner can do it");
_;
}
constructor() {
_owner = msg.sender;
nextBlockNumber = 1;
}
function LimitInfo() public pure returns (uint256, uint256) {
return (100,20);
}
function SubmitTx(bytes memory batchtxs) public returns (bool) {
virtualblocks[nextBlockNumber].block_number = nextBlockNumber;
virtualblocks[nextBlockNumber].block_time = block.timestamp;
virtualblocks[nextBlockNumber].batch_txs = batchtxs;
nextBlockNumber += 1;
return true;
}
function GetNewVirtualBlock(uint256 lastblock) public view returns (VirtualBlockInfo memory) {
return virtualblocks[lastblock+1];
}
function CommitBlock(CommitBlockInfo memory blockinfo) public returns (bool) {
committedBlocks[blockinfo.block_number] = blockinfo;
return true;
}
function GetConfirmedBlock(uint256 block_number) public view returns (CommitBlockInfo memory) {
return committedBlocks[block_number];
}
}