当前位置:网站首页>Merkletree builds QT implementation UI
Merkletree builds QT implementation UI
2022-07-29 06:37:00 【Dtsuv】
MerkleTree structure QT Realization UI
Blockchain learning notes ( 3、 ... and )
Use qt Realization Merkle Tree Construction and existence verification
Catalog
Preface
After the first two chapters blog Code writing , The interaction of the console and the corresponding backend are preliminarily realized , This article blog On the basis of the previous two articles, the front end is realized .
The first two blog:
Merkle Tree The existential function is modified for the first time
Merkle Tree structure (C++ Realization )
One 、 There are... On the tree

Two 、 The tree does not exist

3、 ... and 、 Part of the code
mainwindow.cpp
#include "mainwindow.h"
#include "truenode.h"
#include "falsenode.h"
#include "outbide.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <time.h>
#include "tree.h"
#include "sha256.h"
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
tree ntree;
void MainWindow::on_MerkleTreeButton_clicked()
{
ui->Num->clear();
ui->AllHASH->clear();
vector<string> v; // The leaf node is string class
vector<long> v2;
long long k=20;
if(!ui->LeafCount->text().isEmpty()){
k=ui->LeafCount->text().toInt();
}
// Generate random k A digital
srand(time(NULL));
for (int i = 0; i <k; i++) {
long t = rand() % 100001;// The generated number is 0-100000
v2.push_back(t);
}
string temp="",temp1="";
for (int i = 0; i < v2.size(); i++) {
v.push_back(to_string(v2[i]));
temp=to_string(v2[i]);
temp1=sha256::hash256_hex_string(temp);
QTreeWidgetItem * liItem = new QTreeWidgetItem(QStringList()<<QString::fromStdString(temp)<<QString::fromStdString(temp1));
ui->Num->addTopLevelItem(liItem);
}
ntree.buildBaseLeafes(v);
ntree.buildTree();
for(int j=0;j<ntree.base.size();j++){
for (int i = 0; i < ntree.base[j].size(); i++) {
QTreeWidgetItem * liItem = new QTreeWidgetItem(QStringList()<<QString::fromStdString(ntree.base[j][i]->getHash()));
ui->AllHASH->addTopLevelItem(liItem);
}
}
}
void MainWindow::on_pushButton_clicked()
{
ui->VHASH->clear();
ui->UseHASH->clear();
ntree.base2.clear();
string check_str = "";
check_str=ui->VNum->text().toStdString(); // Enter the leaf node you want to verify
check_str = sha256::hash256_hex_string(check_str);
QTreeWidgetItem * liItem = new QTreeWidgetItem(QStringList()<<QString::fromStdString(check_str));
ui->VHASH->addTopLevelItem(liItem);
if (ntree.verify(check_str))// Verify whether this node exists
{
for(int i=0;i<ntree.base2.size();i++){
QTreeWidgetItem * liItem = new QTreeWidgetItem(QStringList()<<QString::fromStdString(ntree.base2[i]));
ui->UseHASH->addTopLevelItem(liItem);
}
truenode *configWindow = new truenode;
configWindow->show();
}
else
{
if(ntree.base2.empty()){
Outbide *configWindow = new Outbide;
configWindow->show();
}
else{
for(int i=0;i<ntree.base2.size();i++){
QTreeWidgetItem * liItem = new QTreeWidgetItem(QStringList()<<QString::fromStdString(ntree.base2[i]));
ui->UseHASH->addTopLevelItem(liItem);
}
falsenode *configWindow = new falsenode;
configWindow->show();
}
}
}
mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1468</width>
<height>763</height>
</rect>
</property>
<property name="windowTitle">
<string>Merkle Tree UI</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>401</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string> Please enter a build Merkle Tree Number of random numbers ( Default 20 A digital ):</string>
</property>
</widget>
<widget class="QLineEdit" name="LeafCount">
<property name="geometry">
<rect>
<x>400</x>
<y>10</y>
<width>91</width>
<height>51</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="MerkleTreeButton">
<property name="geometry">
<rect>
<x>210</x>
<y>590</y>
<width>201</width>
<height>91</height>
</rect>
</property>
<property name="text">
<string> structure Merkle Tree</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>231</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string> The corresponding random number and hash value generated :</string>
</property>
</widget>
<widget class="QTreeWidget" name="Num">
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<width>731</width>
<height>141</height>
</rect>
</property>
<column>
<property name="text">
<string> random number </string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>HASH value </string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
</widget>
<widget class="QTreeWidget" name="AllHASH">
<property name="geometry">
<rect>
<x>10</x>
<y>340</y>
<width>731</width>
<height>231</height>
</rect>
</property>
<column>
<property name="text">
<string>HASH value </string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
</widget>
<widget class="QTreeWidget" name="UseHASH">
<property name="geometry">
<rect>
<x>770</x>
<y>320</y>
<width>681</width>
<height>171</height>
</rect>
</property>
<column>
<property name="text">
<string>HASH value </string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>300</y>
<width>351</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string> structure Merkle Tree All produced in the process HASH:</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>760</x>
<y>270</y>
<width>171</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string> Used in the validation process HASH:</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>990</x>
<y>520</y>
<width>241</width>
<height>91</height>
</rect>
</property>
<property name="text">
<string> verification </string>
</property>
</widget>
<widget class="QLineEdit" name="VNum">
<property name="geometry">
<rect>
<x>880</x>
<y>30</y>
<width>121</width>
<height>61</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>770</x>
<y>50</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string> Validation data :</string>
</property>
</widget>
<widget class="QTreeWidget" name="VHASH">
<property name="geometry">
<rect>
<x>770</x>
<y>160</y>
<width>671</width>
<height>71</height>
</rect>
</property>
<column>
<property name="text">
<string>HASH value </string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>770</x>
<y>120</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string> Data validation HASH value :</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Four 、 Related code resources
At the end
The above is the Merkle Tree Of qt Realization , For reference only . If there are relevant professional questions , Please leave a message in the comment area .
边栏推荐
- What are the advantages of software testing? See how much you know
- 不安全的第三方组件的漏洞如何做前置规避?
- FPGA里两个数的大小直接进行比较就可以吗?
- Is it OK to directly compare the size of two numbers in FPGA?
- 盘点 | 全球关键信息基础设施网络安全大事件
- Common server faults and their solutions
- [leetcode skimming] array 1 - double pointer
- On defect description style
- FPGA - odd even frequency division and decimal frequency division code routine
- Circular linked list and bidirectional linked list
猜你喜欢
![[interview questions] the latest software test interview questions in 2022 (400) [with answers] continue to update](/img/72/445d78bdd6c921cc5a0843f056c435.png)
[interview questions] the latest software test interview questions in 2022 (400) [with answers] continue to update

自动化测试的生命周期是什么?
![Self study understanding of [chain forward star]](/img/b4/7f66026a482540bf27f088c321a840.png)
Self study understanding of [chain forward star]

基于FPGA的4位减法器设计及仿真代码

day13_多线程下

On defect description style

MerkleTree 构建QT实现UI

使用STP生成树协议解决网络中的二层环路问题

Day16 set

软件测试的优势有哪些?看看你了解多少.....
随机推荐
day12_多线程
Use of for statement in Verilog
day09_ Static & Final & code block & abstract class & Interface & internal class
What is the lifecycle of automated testing?
Noi online 2022 popular group problem solving & personal understanding
[leetcode skimming] array 2 - binary search
How to judge whether a business is attacked by DDoS? What harm will it cause?
右值引用和移动构造
Joint use skills of joiner.on and stream().Map
NoClassDefFoundError processing
RAW高级套接口实验
虹科教您 | 想进入TSN领域?虹科教您如何搭建TSN测试系统
What are the advantages of software testing? See how much you know
基于FPGA的IIR型滤波器设计
盘点 | 全球关键信息基础设施网络安全大事件
The performance and viewing methods of websites attacked by DDoS
day03_2_作业
Maya aces workflow configuration (Arnold and redshift map configuration specification - restore the correct effect of the map under the SP aces process) PS restore the rendered map under the aces proc
day15_泛型
虹科分享 | FPGA 实现的直通与存储转发切换延迟