Overview
Comment: | Updated work nomenclature to be more clear |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3aeba5d8efd70b1ec7c112018e76e316 |
User & Date: | rkeene on 2018-07-06 14:53:22 |
Other Links: | manifest | tags |
Context
2018-07-08
| ||
21:17 | "-fcheck-pointer-bounds" requires "-mmpx" check-in: 3de63da81f user: rkeene tags: trunk | |
2018-07-06
| ||
14:53 | Updated work nomenclature to be more clear check-in: 3aeba5d8ef user: rkeene tags: trunk | |
02:35 | Made API more consistent check-in: 6881dd597e user: rkeene tags: trunk | |
Changes
Modified build/nano.txt from [698fe4d7c1] to [038189dc4b].
︙ | ︙ | |||
34 35 36 37 38 39 40 | ::nano::block::verifyBlockHash blockHash signature publicKey -> boolean ::nano::block::verify blockData signature publicKey -> boolean ::nano::block::create::send args -> blockJSON|blockDict ::nano::block::create::receive args -> blockJSON|blockDict ::nano::block::create::setRepresentative args -> blockJSON|blockDict | > | | > | > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ::nano::block::verifyBlockHash blockHash signature publicKey -> boolean ::nano::block::verify blockData signature publicKey -> boolean ::nano::block::create::send args -> blockJSON|blockDict ::nano::block::create::receive args -> blockJSON|blockDict ::nano::block::create::setRepresentative args -> blockJSON|blockDict # Work Generation ::nano::work::fromWorkData blockHashOrPublicKey -> work ::nano::work::fromBlock blockData -> work ::nano::work::validate workData work -> boolean # High Level Account :nano::account::setFrontier account frontierHash balance representative -> nil :nano::account::getFrontier account -> frontierInfo :nano::account::getFrontier account ?frontierHash|balance|representative? -> frontierHash|balance|representative :nano::account::addPending account blockHash amount -> nil :nano::account::receive account blockHash privateKey -> blockJSON|blockDict :nano::account::send fromAccount toAccount amount privateKey -> blockJSON|blockDict :nano::account::receiveAllPending account privateKey -> ListOfBlockJSON|ListOfBlockDict |
Modified build/test/test.tcl from [a74429d687] to [11db632ebe].
︙ | ︙ | |||
237 238 239 240 241 242 243 | puts "\[2.FAIL\] Got: $verify" puts "\[2.FAIL\] Exp: false" return false } # Generation | | | | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | puts "\[2.FAIL\] Got: $verify" puts "\[2.FAIL\] Exp: false" return false } # Generation set workData "1C840FED01000000D8CBCF440CB1E4DF386761E6E66609563BD62A649DF6D0BE" set work [::nano::work::fromWorkData $workData] set verify [::nano::work::validate $workData $work] if {!$verify} { puts "\[3.FAIL\] Got: $verify" puts "\[3.FAIL\] Exp: true" return false } |
︙ | ︙ |
Modified examples/generate-work/generate-work from [9ea0cf83ab] to [1db3d7157f].
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 20 | #! /usr/bin/env tclsh lappend auto_path ../../build/work package require nano if {[llength $argv] == 0} { puts stderr "Usage: generate-work <hash>..." exit 1 } foreach arg $argv { if {[catch { set work [::nano::work::fromWorkData $arg] } err]} { puts stderr "Error generating work for \"$arg\": $err" } else { puts "WORK($arg) = $work" } } |
Modified nano.tcl from [a0ad3d6e3d] to [d9714fb5b7].
︙ | ︙ | |||
325 326 327 328 329 330 331 | set block(link_as_account) [::nano::address::fromPublicKey $block(link) $addressFormatFlag] } } set blockJSONFields { type account source destination previous representative balance | | | | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | 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 _workData work signature _comment } set blockJSONEntries [lmap field $blockJSONFields { if {![info exists block($field)]} { continue } switch -exact -- $field { "source" - "previous" - "link" - "_blockHash" - "_workData" { if {[string length $block($field)] == $::nano::block::hashLength} { set block($field) [binary encode hex $block($field)] } set block($field) [string toupper $block($field)] } "signature" { |
︙ | ︙ | |||
701 702 703 704 705 706 707 | return -code error "Invalid option: $arg" } } } set blockDict [_addBlockHash $blockDict] | | | | 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | return -code error "Invalid option: $arg" } } } set blockDict [_addBlockHash $blockDict] set blockHash [dict get $blockDict _workData] set work [::nano::work::fromWorkData $blockHash -binary] if {$outputMode eq "work"} { if {$outputFormat eq "hex"} { set work [binary encode hex $work] } return $work |
︙ | ︙ | |||
751 752 753 754 755 756 757 | return $retval } proc ::nano::block::dict::validateWork {blockDict} { set blockDict [_addBlockHash $blockDict] | | | 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | return $retval } proc ::nano::block::dict::validateWork {blockDict} { set blockDict [_addBlockHash $blockDict] set blockHash [dict get $blockDict _workData] set work [dict get $blockDict work] tailcall ::nano::work::validate $blockHash $work } proc ::nano::block::json::validateWork {blockJSON} { set blockDict [::nano::block::dict::fromJSON $blockJSON] |
︙ | ︙ | |||
781 782 783 784 785 786 787 | set blockDict [dict create \ "type" state \ "account" $block(from) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link_as_account" $block(to) \ | | | 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 | set blockDict [dict create \ "type" state \ "account" $block(from) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link_as_account" $block(to) \ "_workData" $block(previous) \ "_comment" "Send $block(amount) raw from $block(from) to $block(to)" \ ] if {[info exists block(signKey)]} { set blockDict [::nano::block::dict::sign $blockDict $block(signKey) -update] } |
︙ | ︙ | |||
810 811 812 813 814 815 816 | if {![info exists block(representative)]} { set block(representative) $block(to) } if {![info exists block(previous)]} { set block(previous) "0000000000000000000000000000000000000000000000000000000000000000" set block(previousBalance) 0 | | | | | 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 | if {![info exists block(representative)]} { set block(representative) $block(to) } if {![info exists block(previous)]} { set block(previous) "0000000000000000000000000000000000000000000000000000000000000000" set block(previousBalance) 0 set block(_workData) [::nano::address::toPublicKey $block(to) -hex] } else { set block(_workData) $block(previous) } set block(balance) [expr {$block(previousBalance) + $block(amount)}] set blockDict [dict create \ "type" state \ "account" $block(to) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link" $block(sourceBlock) \ "_workData" $block(_workData) \ "_comment" "Receive $block(amount) raw on $block(to) from hash $block(sourceBlock)" \ ] if {[info exists block(signKey)]} { set blockDict [::nano::block::dict::sign $blockDict $block(signKey) -update] } |
︙ | ︙ | |||
854 855 856 857 858 859 860 | set blockDict [dict create \ "type" state \ "account" $block(account) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link" $block(link) \ | | | | | | | > | | | | | | 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | set blockDict [dict create \ "type" state \ "account" $block(account) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link" $block(link) \ "_workData" $block(previous) \ ] if {[info exists block(signKey)]} { dict set blockDict signKey $block(signKey) } if {[info exists block(signKey)]} { set blockDict [::nano::block::dict::sign $blockDict $block(signKey) -update] } if {[info exists block(-json)] && $block(-json)} { return [::nano::block::json::fromDict $blockDict] } return $blockDict } # Work generation functions proc ::nano::work::fromWorkData {blockHashOrPublicKey} { if {[string length $blockHashOrPublicKey] != $::nano::block::hashLength} { set blockHashOrPublicKey [binary decode hex $blockHashOrPublicKey] } set work [binary encode hex [::nano::internal::generateWork $blockHashOrPublicKey]] set work [string tolower $work] return $work } proc ::nano::work::fromBlock {blockData} { set blockDict [::nano::block::dict::fromBlock $blockData] set workData [dict get $blockDict _workData] tailcall ::nano::work::fromBlockhash $workData } proc ::nano::work::validate {workData work} { if {[string length $workData] != $::nano::block::hashLength} { set workData [binary decode hex $workData] } if {[string length $work] != $::nano::work::workValueLength} { set work [binary decode hex $work] } tailcall ::nano::internal::validateWork $workData $work } # High level account management 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 \ |
︙ | ︙ |