Overview
Comment: | Added high-level work interfaces |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
5c0fe18b67ba5b68c06e5af8181132cb |
User & Date: | rkeene on 2018-07-05 14:56:33 |
Other Links: | manifest | tags |
Context
2018-07-05
| ||
15:02 | Improvements to handling of patched dependencies check-in: b90a759587 user: rkeene tags: trunk | |
14:56 | Added high-level work interfaces check-in: 5c0fe18b67 user: rkeene tags: trunk | |
2018-07-03
| ||
19:52 | Add an example for a batch offline signing/sweep system check-in: c316c57485 user: rkeene tags: trunk | |
Changes
Modified build/test/test.tcl from [14c732d43e] to [1ad7f525dc].
︙ | ︙ | |||
218 219 220 221 222 223 224 | } proc test_work {} { # Verification ## Positive set blockhash "0CF7F1E71B6C692BD8CBCF440CB1E4DF386761E6E66609563BD62A649DF6D0BE" set work "01A87EEC1B6C692B" | | | | | | 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 | } proc test_work {} { # Verification ## Positive set blockhash "0CF7F1E71B6C692BD8CBCF440CB1E4DF386761E6E66609563BD62A649DF6D0BE" set work "01A87EEC1B6C692B" set verify [::nano::work::validate $blockhash $work] if {!$verify} { puts "\[1.FAIL\] Got: $verify" puts "\[1.FAIL\] Exp: true" return false } ## Negative set work "11A87EEC1B6C692B" set verify [::nano::work::validate $blockhash $work] if {$verify} { puts "\[2.FAIL\] Got: $verify" puts "\[2.FAIL\] Exp: false" return false } # Generation set blockhash "1C840FED01000000D8CBCF440CB1E4DF386761E6E66609563BD62A649DF6D0BE" set work [::nano::work::fromBlockhash $blockhash] set verify [::nano::work::validate $blockhash $work] if {!$verify} { puts "\[3.FAIL\] Got: $verify" puts "\[3.FAIL\] Exp: true" return false } |
︙ | ︙ |
Modified examples/generate-work/generate-work from [5e6bfb3da3] to [dad84c19fb].
1 2 3 4 5 6 7 8 9 10 11 12 | #! /usr/bin/env tclsh package require nano if {[llength $argv] == 0} { puts stderr "Usage: generate-work <hash>..." exit 1 } foreach arg $argv { if {[catch { | | < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #! /usr/bin/env tclsh package require nano if {[llength $argv] == 0} { puts stderr "Usage: generate-work <hash>..." exit 1 } foreach arg $argv { if {[catch { set work [::nano::work::fromBlockhash $arg] } err]} { puts stderr "Error generating work for \"$arg\": $err" } else { puts "WORK($arg) = $work" } } |
Modified nano.tcl from [594189ec1a] to [0eebec2f4c].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #! /usr/bin/env tclsh package require json package require json::write namespace eval ::nano {} namespace eval ::nano::address {} namespace eval ::nano::key {} namespace eval ::nano::block {} namespace eval ::nano::block::create {} namespace eval ::nano::account {} set ::nano::block::hashLength 32 set ::nano::block::signatureLength 64 set ::nano::key::publicKeyLength 32 set ::nano::key::privateKeyLength 32 set ::nano::key::seedLength 32 | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #! /usr/bin/env tclsh package require json package require json::write namespace eval ::nano {} namespace eval ::nano::address {} namespace eval ::nano::key {} namespace eval ::nano::block {} namespace eval ::nano::block::create {} namespace eval ::nano::work {} namespace eval ::nano::account {} set ::nano::block::hashLength 32 set ::nano::block::signatureLength 64 set ::nano::key::publicKeyLength 32 set ::nano::key::privateKeyLength 32 set ::nano::key::seedLength 32 |
︙ | ︙ | |||
369 370 371 372 373 374 375 | set block(link_as_account) [::nano::address::fromPublicKey $block(link) $addressFormatFlag] } } set blockJSONFields { type account source destination previous representative balance | | | 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | set block(link_as_account) [::nano::address::fromPublicKey $block(link) $addressFormatFlag] } } set blockJSONFields { type account source destination previous representative balance link link_as_account _blockHash _workHash work signature _comment } set blockJSONEntries [lmap field $blockJSONFields { if {![info exists block($field)]} { continue } |
︙ | ︙ | |||
626 627 628 629 630 631 632 633 634 635 636 637 638 639 | if {[info exists block(signKey)]} { dict set blockDict signKey $block(signKey) } tailcall ::nano::block::jsonFromDict $blockDict } # -- Tracked accounts -- proc ::nano::account::setFrontier {account frontierHash balance representative} { set accountPubKey [::nano::address::toPublicKey $account -hex] set ::nano::account::frontiers($accountPubKey) [dict create \ frontierHash $frontierHash balance $balance representative $representative \ ] | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | if {[info exists block(signKey)]} { dict set blockDict signKey $block(signKey) } tailcall ::nano::block::jsonFromDict $blockDict } proc ::nano::work::fromBlockhash {blockhash} { if {[string length $blockhash] != 32} { set blockhash [binary decode hex $blockhash] } set work [binary encode hex [::nano::internal::generateWork $blockhash]] set work [string tolower $work] return $work } proc ::nano::work::fromBlock {blockJSON} { set blockDict [::json::json2dict $blockJSON] set workhash [dict get $blockDict _workHash] tailcall ::nano::work::fromBlockhash $workhash } proc ::nano::work::updateBlock {blockJSON} { set blockDict [::json::json2dict $blockJSON] set workhash [dict get $blockDict _workHash] set work [::nano::work::fromBlockhash $workhash] dict set blockDict work $work tailcall ::nano::block::_dictToJSON $blockDict } proc ::nano::work::validate {blockhash work} { if {[string length $blockhash] != 32} { set blockhash [binary decode hex $blockhash] } if {[string length $work] != 8} { set work [binary decode hex $work] } tailcall ::nano::internal::validateWork $blockhash $work } # -- Tracked accounts -- proc ::nano::account::setFrontier {account frontierHash balance representative} { set accountPubKey [::nano::address::toPublicKey $account -hex] set ::nano::account::frontiers($accountPubKey) [dict create \ frontierHash $frontierHash balance $balance representative $representative \ ] |
︙ | ︙ |