Overview
Comment: | Better handling of old blocks and tests on old blocks |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
84b2dbcb6f8993e9585d853373fcc1b6 |
User & Date: | rkeene on 2018-07-09 04:53:30 |
Other Links: | manifest | tags |
Context
2018-07-09
| ||
04:59 | Updated to include man page as part of release engineering and include it with "make install" check-in: b3ed301bc1 user: rkeene tags: trunk | |
04:53 | Better handling of old blocks and tests on old blocks check-in: 84b2dbcb6f user: rkeene tags: trunk | |
04:06 | Added start of man page check-in: ab46e73bd2 user: rkeene tags: trunk | |
Changes
Modified nano.tcl from [c76ed0146c] to [1fa3e80c07].
︙ | ︙ | |||
293 294 295 296 297 298 299 | proc ::nano::block::json::toBlock {blockJSON} { set blockDict [::nano::block::dict::fromJSON $blockJSON] tailcall ::nano::block::dict::toBlock $blockDict } proc ::nano::block::dict::fromJSON {blockJSON} { | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | proc ::nano::block::json::toBlock {blockJSON} { set blockDict [::nano::block::dict::fromJSON $blockJSON] tailcall ::nano::block::dict::toBlock $blockDict } proc ::nano::block::dict::fromJSON {blockJSON} { set retval [::json::json2dict $blockJSON] if {[dict get $retval "type"] eq "send"} { set balance [dict get $retval "balance"] set balance [format %lli "0x$balance"] dict set retval "balance" $balance } # Parse out the work data if {[dict get $retval "type"] in {send receive change state}} { set workDataBasedOn "previous" } if {[dict get $retval "type"] eq "state" && [dict get $retval "previous"] eq "0000000000000000000000000000000000000000000000000000000000000000" && [dict get $retval "link"] eq "0000000000000000000000000000000000000000000000000000000000000000"} { set workDataBasedOn "account" } if {[dict get $retval "type"] eq "open"} { set workDataBasedOn "account" } if {[info exists workDataBasedOn]} { if {$workDataBasedOn eq "previous"} { dict set retval "_workData" [dict get $retval "previous"] } else { dict set retval "_workData" [::nano::address::toPublicKey [dict get $retval "account"]] } } return $retval } proc ::nano::block::json::fromDict {blockDict} { array set block $blockDict if {$block(type) eq "state"} { if {![info exists block(link)]} { |
︙ | ︙ | |||
355 356 357 358 359 360 361 362 363 364 365 366 367 368 | "work" { if {[string length $block($field)] == $::nano::work::workValueLength} { set block($field) [binary encode hex $block($field)] } set block($field) [string tolower $block($field)] } } return -level 0 [list $field [json::write string $block($field)]] }] set blockJSONEntries [join $blockJSONEntries] set blockJSON [json::write object {*}$blockJSONEntries] | > > > > > > > > | 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | "work" { if {[string length $block($field)] == $::nano::work::workValueLength} { set block($field) [binary encode hex $block($field)] } set block($field) [string tolower $block($field)] } "balance" { if {$block(type) in {send receive change open}} { set balanceFormatStr %032llx } else { set balanceFormatStr %lli } set block($field) [string toupper [format $balanceFormatStr "$block($field)"]] } } return -level 0 [list $field [json::write string $block($field)]] }] set blockJSONEntries [join $blockJSONEntries] set blockJSON [json::write object {*}$blockJSONEntries] |
︙ | ︙ | |||
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | } } "open" { binary scan $blockData H64a32a32 \ block(source) \ block(representative) \ block(account) } "send" { binary scan $blockData H64a32H32 \ block(previous) \ block(destination) \ block(balance) } "receive" { binary scan $blockData H64H64 \ block(previous) \ block(source) } "change" { binary scan $blockData H64a32 \ block(previous) \ block(representative) } default { return -code error "Invalid block type: $block(type)" } } foreach field {account representative link_as_account destination balance} { | > > > > > > > > | 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | } } "open" { binary scan $blockData H64a32a32 \ block(source) \ block(representative) \ block(account) set block(_workData) $block(account) } "send" { binary scan $blockData H64a32H32 \ block(previous) \ block(destination) \ block(balance) set block(_workData) $block(previous) } "receive" { binary scan $blockData H64H64 \ block(previous) \ block(source) set block(_workData) $block(previous) } "change" { binary scan $blockData H64a32 \ block(previous) \ block(representative) set block(_workData) $block(previous) } default { return -code error "Invalid block type: $block(type)" } } foreach field {account representative link_as_account destination balance} { |
︙ | ︙ | |||
760 761 762 763 764 765 766 | tailcall ::nano::work::validate $blockHash $work } proc ::nano::block::json::validateWork {blockJSON} { set blockDict [::nano::block::dict::fromJSON $blockJSON] | | | 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | tailcall ::nano::work::validate $blockHash $work } proc ::nano::block::json::validateWork {blockJSON} { set blockDict [::nano::block::dict::fromJSON $blockJSON] tailcall ::nano::block::dict::validateWork $blockDict } # send from <account> to <account> previousBalance <balance> # amount <amount> sourceBlock <sourceBlockHash> # previous <previousBlockHash> ?representative <representative>? proc ::nano::block::create::send {args} { array set block $args |
︙ | ︙ |
Modified test/test.tcl from [11db632ebe] to [f9d5f0aa5f].
︙ | ︙ | |||
207 208 209 210 211 212 213 214 215 216 217 218 219 220 | # Verifying a block set signature [::nano::block::json::sign $block $key -hex] set verify [::nano::block::json::verifySignature $block] if {!$verify} { puts "\[4.FAIL\] Got: $verify" puts "\[4.FAIL\] Exp: true" return false } return true } proc test_work {} { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | # Verifying a block set signature [::nano::block::json::sign $block $key -hex] set verify [::nano::block::json::verifySignature $block] if {!$verify} { puts "\[4.FAIL\] Got: $verify" puts "\[4.FAIL\] Exp: true" return false } # JSON Parse an old-style block ## Parsing set block [::nano::block::dict::fromJSON { { "account" : "xrb_13ezf4od79h1tgj9aiu4djzcmmguendtjfuhwfukhuucboua8cpoihmh8byo", "destination" : "xrb_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb", "type" : "send", "previous" : "F685856D73A488894F7F3A62BC3A88E17E985F9969629FF3FDD4A0D4FD823F24", "work" : "efe5bf06a43d0e0a", "signature" : "E373A1A38C9A239F4D2AAE52B40EF6DFC8BFEDCEB476588958073B7F462746854282FFE4B98FA6782E92798DAD0E5483C3356550A31339E1D7934B487EF4570D", "balance" : "00F035A9C7D818E7C34148C524FFFFEE" } }] ## Convert to JSON set block [::nano::block::json::fromDict $block] ## Convert back and verify signature set verify [::nano::block::json::verifySignature $block] if {!$verify} { puts "\[5.FAIL\] Got: $verify" puts "\[5.FAIL\] Exp: true" return false } ## Verify Proof of Work set verify [::nano::block::json::validateWork $block] if {!$verify} { puts "\[6.FAIL\] Got: $verify" puts "\[6.FAIL\] Exp: true" return false } return true } proc test_work {} { |
︙ | ︙ |