Index: build/nano.txt ================================================================== --- build/nano.txt +++ build/nano.txt @@ -36,15 +36,18 @@ ::nano::block::create::send args -> blockJSON|blockDict ::nano::block::create::receive args -> blockJSON|blockDict ::nano::block::create::setRepresentative args -> blockJSON|blockDict -::nano::work::fromBlockHash blockHash -> work +# Work Generation +::nano::work::fromWorkData blockHashOrPublicKey -> work ::nano::work::fromBlock blockData -> work -::nano::work::validate blockHash work -> boolean +::nano::work::validate workData work -> boolean +# High Level Account :nano::account::setFrontier account frontierHash balance representative -> nil -:nano::account::getFrontier account args -> frontierInfo +: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 Index: build/test/test.tcl ================================================================== --- build/test/test.tcl +++ build/test/test.tcl @@ -239,13 +239,13 @@ return false } # Generation - set blockhash "1C840FED01000000D8CBCF440CB1E4DF386761E6E66609563BD62A649DF6D0BE" - set work [::nano::work::fromBlockHash $blockhash] - set verify [::nano::work::validate $blockhash $work] + 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 Index: examples/generate-work/generate-work ================================================================== --- examples/generate-work/generate-work +++ examples/generate-work/generate-work @@ -1,7 +1,8 @@ #! /usr/bin/env tclsh +lappend auto_path ../../build/work package require nano if {[llength $argv] == 0} { puts stderr "Usage: generate-work ..." @@ -8,12 +9,12 @@ exit 1 } foreach arg $argv { if {[catch { - set work [::nano::work::fromBlockHash $arg] + set work [::nano::work::fromWorkData $arg] } err]} { puts stderr "Error generating work for \"$arg\": $err" } else { puts "WORK($arg) = $work" } } Index: nano.tcl ================================================================== --- nano.tcl +++ nano.tcl @@ -327,20 +327,20 @@ } } set blockJSONFields { type account source destination previous representative balance - link link_as_account _blockHash _workHash work signature _comment + 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" - "_workHash" { + "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)] @@ -703,13 +703,13 @@ } } set blockDict [_addBlockHash $blockDict] - set blockHash [dict get $blockDict _blockHash] + set blockHash [dict get $blockDict _workData] - set work [::nano::work::fromBlockHash $blockHash -binary] + set work [::nano::work::fromWorkData $blockHash -binary] if {$outputMode eq "work"} { if {$outputFormat eq "hex"} { set work [binary encode hex $work] } @@ -753,11 +753,11 @@ } proc ::nano::block::dict::validateWork {blockDict} { set blockDict [_addBlockHash $blockDict] - set blockHash [dict get $blockDict _blockHash] + set blockHash [dict get $blockDict _workData] set work [dict get $blockDict work] tailcall ::nano::work::validate $blockHash $work } @@ -783,11 +783,11 @@ "account" $block(from) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link_as_account" $block(to) \ - "_workHash" $block(previous) \ + "_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] @@ -812,13 +812,13 @@ } if {![info exists block(previous)]} { set block(previous) "0000000000000000000000000000000000000000000000000000000000000000" set block(previousBalance) 0 - set block(_workHash) [::nano::address::toPublicKey $block(to) -hex] + set block(_workData) [::nano::address::toPublicKey $block(to) -hex] } else { - set block(_workHash) $block(previous) + set block(_workData) $block(previous) } set block(balance) [expr {$block(previousBalance) + $block(amount)}] set blockDict [dict create \ @@ -826,11 +826,11 @@ "account" $block(to) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link" $block(sourceBlock) \ - "_workHash" $block(_workHash) \ + "_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] @@ -856,11 +856,11 @@ "account" $block(account) \ "previous" $block(previous) \ "representative" $block(representative) \ "balance" $block(balance) \ "link" $block(link) \ - "_workHash" $block(previous) \ + "_workData" $block(previous) \ ] if {[info exists block(signKey)]} { dict set blockDict signKey $block(signKey) } @@ -875,37 +875,38 @@ return $blockDict } # Work generation functions -proc ::nano::work::fromBlockHash {blockHash} { - if {[string length $blockHash] != $::nano::block::hashLength} { - set blockHash [binary decode hex $blockHash] +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 $blockHash]] + set work [binary encode hex [::nano::internal::generateWork $blockHashOrPublicKey]] set work [string tolower $work] return $work } proc ::nano::work::fromBlock {blockData} { - set blockHash [::nano::block::hash $blockData -binary] + set blockDict [::nano::block::dict::fromBlock $blockData] + set workData [dict get $blockDict _workData] - tailcall ::nano::work::fromBlockhash $blockHash + tailcall ::nano::work::fromBlockhash $workData } -proc ::nano::work::validate {blockHash work} { - if {[string length $blockHash] != $::nano::block::hashLength} { - set blockHash [binary decode hex $blockHash] +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 $blockHash $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]