Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ece598pv-sp2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
zhihuas2
ece598pv-sp2020
Commits
736f5174
Commit
736f5174
authored
4 years ago
by
zhihua0322
Browse files
Options
Downloads
Patches
Plain Diff
ready for demo
parent
584b596d
Branches
master
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/blockchain.rs
+4
-4
4 additions, 4 deletions
src/blockchain.rs
src/generator.rs
+1
-1
1 addition, 1 deletion
src/generator.rs
src/network/worker.rs
+4
-4
4 additions, 4 deletions
src/network/worker.rs
with
9 additions
and
9 deletions
src/blockchain.rs
+
4
−
4
View file @
736f5174
...
...
@@ -68,7 +68,7 @@ impl Blockchain {
let
old_sender_value
=
new_state
.get_value
(
sender
);
let
old_recipient_value
=
new_state
.get_value
(
recipient
);
let
old_recipient_nonce
=
new_state
.get_nonce
(
recipient
);
println!
(
"value is {}, account_nonce is {}"
,
value
,
account_nonce
);
//
println!("value is {}, account_nonce is {}", value, account_nonce);
new_state
.put_entry
(
sender
,
(
account_nonce
,
old_sender_value
-
value
));
new_state
.put_entry
(
recipient
,
(
old_recipient_nonce
,
old_recipient_value
+
value
));
}
...
...
@@ -86,13 +86,13 @@ impl Blockchain {
let
sender
=
t
.get_sender
();
// let recipient = t.get_recipient();
let
value
=
t
.get_value
();
let
account_nonce
=
t
.get_nonce
();
//
let account_nonce = t.get_nonce();
let
old_sender_value
=
parent_state
.get_value
(
sender
);
// let old_recipient_value = parent_state.get_value(recipient);
let
old_sender_nonce
=
parent_state
.get_nonce
(
sender
);
//
let old_sender_nonce = parent_state.get_nonce(sender);
// let old_recipient_nonce = parent_state.get_nonce(recipient);
if
!
verify_withbytes
(
&
t
,
pub_key
,
signature_bytes
)
||
old_sender_value
<
value
||
old_sender_nonce
!=
account_nonce
-
1
{
if
!
verify_withbytes
(
&
t
,
pub_key
,
signature_bytes
)
||
old_sender_value
<
value
{
// if !verify_withbytes(&t, pub_key, signature_bytes) {
is_valid
=
false
;
break
;
...
...
This diff is collapsed.
Click to expand it.
src/generator.rs
+
1
−
1
View file @
736f5174
...
...
@@ -56,7 +56,7 @@ impl Generator {
// println!("index is {}", index);
let
signed_t
=
generate_transaction
(
&
self
.self_key
,
self
.address
,
nonce
,
*
recipients
.get
(
index
as
usize
)
.unwrap
());
mempool
.add
(
&
signed_t
);
println!
(
"size of mempool is {}"
,
mempool
.len
());
//
println!("size of mempool is {}", mempool.len());
let
mut
transaction_vec
=
Vec
::
new
();
transaction_vec
.push
(
signed_t
.hash
());
let
msg
:
Message
=
Message
::
NewTransactionHashes
(
transaction_vec
);
...
...
This diff is collapsed.
Click to expand it.
src/network/worker.rs
+
4
−
4
View file @
736f5174
...
...
@@ -152,13 +152,13 @@ impl Context {
debug!
(
"Pong: {}"
,
nonce
);
}
Message
::
Address
(
account
)
=>
{
println!
(
"receive Addr"
);
//
println!("receive Addr");
let
mut
blockchain
=
self
.mut_blockchain
.lock
()
.unwrap
();
let
tip
=
blockchain
.tip
();
let
old_state
=
blockchain
.get_state
(
tip
);
let
mut
new_state
=
old_state
.clone
();
new_state
.put_entry
(
account
,
(
0
,
10000
));
println!
(
"current length of state is {}"
,
new_state
.get_len
());
//
println!("current length of state is {}", new_state.get_len());
blockchain
.put_state
(
tip
,
new_state
);
}
Message
::
NewBlockHashes
(
block_hash
)
=>
{
...
...
@@ -194,7 +194,7 @@ impl Context {
// println!("receive getBlocks");
let
blockchain
=
self
.mut_blockchain
.lock
()
.unwrap
();
let
blocks
=
blockchain
.get_block
(
not_exist_hash
);
println!
(
"not_exist_hash {}"
,
blocks
.len
());
//
println!("not_exist_hash {}", blocks.len());
if
blocks
.len
()
>
0
{
peer
.write
(
Message
::
Blocks
(
blocks
));
}
...
...
@@ -206,7 +206,7 @@ impl Context {
// thread::spawn(move || {
// println!("receive Blocks");
let
mut
blockchain
=
self
.mut_blockchain
.lock
()
.unwrap
();
println!
(
"blocks size {}"
,
blocks
.len
());
//
println!("blocks size {}", blocks.len());
let
mut
new_hash
:
Vec
<
H256
>
=
Vec
::
new
();
let
mut
not_exist_hash
:
Vec
<
H256
>
=
Vec
::
new
();
for
block
in
blocks
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment