Index: nano.man ================================================================== --- nano.man +++ nano.man @@ -165,10 +165,11 @@ .in -2m .B work:: .in +2m .B fromWorkData .I blockHashOrPublicKey +.RB ? -hex | -binary ? .br .B fromBlock .I blockData .br .B validate @@ -718,10 +719,11 @@ .SS Work Generation .TP .B ::nano::work::fromWorkData .I blockHashOrPublicKey +.RB ? -hex | -binary ? .RI " -> " work Create proof-of-work (PoW) from a block hash or public key. Which one is used depends on whether or not there are any other blocks in this account's chain. If this is the first block in this account's chain then the public key of the @@ -730,10 +732,11 @@ is used. The specific value needed should be accessible from the .B _workData member of a JSON object or Tcl dictionary. Note that this attribute (and all attributes that begin with an underscore) should be discarded when sending the block outside of the Tcl process. +.HB .TP .B ::nano::work::fromBlock .I blockData .RI " -> " work Index: nano.tcl ================================================================== --- nano.tcl +++ nano.tcl @@ -729,10 +729,11 @@ tailcall ::nano::block::dict::verifySignature $blockDict } proc ::nano::block::dict::work {blockDict args} { set outputMode "work" + set outputFormat "hex" foreach arg $args { switch -- $arg { "-update" { set outputMode "update" } @@ -923,17 +924,36 @@ return $blockDict } # Work generation functions -proc ::nano::work::fromWorkData {blockHashOrPublicKey} { +proc ::nano::work::fromWorkData {blockHashOrPublicKey args} { + set outputFormat "hex" + foreach arg $args { + switch -- $arg { + "-hex" { + set outputFormat "hex" + } + "-binary" { + set outputFormat "bytes" + } + default { + return -code error "Invalid option: $arg" + } + } + } + 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] + set work [::nano::internal::generateWork $blockHashOrPublicKey] + + if {$outputFormat eq "hex"} { + set work [binary encode hex $work] + set work [string tolower $work] + } return $work } proc ::nano::work::fromBlock {blockData} {