Check-in [7ffe38e93e]
Overview
Comment:Fixed bugs with computing work
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7ffe38e93ee30c63ecf77932c8c8848220b05d298e5c772bf51509d4c63aa3a5
User & Date: rkeene on 2018-07-11 14:26:22
Other Links: manifest | tags
Context
2018-07-11
16:28
Added a "filter" JSON command to filter out attributes which other implementations hate check-in: 3a03259f8f user: rkeene tags: trunk
14:26
Fixed bugs with computing work check-in: 7ffe38e93e user: rkeene tags: trunk
14:14
Added start of balances and RPC client check-in: 5ed9a692b6 user: rkeene tags: trunk
Changes

Modified nano.man from [625d4d76a6] to [b53f68eda0].

163
164
165
166
167
168
169

170
171
172
173
174
175
176
.I args

.in -2m
.B work::
.in +2m
.B fromWorkData
.I blockHashOrPublicKey

.br
.B fromBlock
.I blockData
.br
.B validate
.I workData
.I work







>







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
.I args

.in -2m
.B work::
.in +2m
.B fromWorkData
.I blockHashOrPublicKey
.RB ? -hex | -binary ?
.br
.B fromBlock
.I blockData
.br
.B validate
.I workData
.I work
716
717
718
719
720
721
722

723
724
725
726
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
.BR previous .
.JB

.SS Work Generation
.TP
.B ::nano::work::fromWorkData
.I blockHashOrPublicKey

.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
account is used, otherwise the hash of the blocks predecessor
.RI ( previous )
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.


.TP
.B ::nano::work::fromBlock
.I blockData
.RI " -> " work

This is a convenience procedure which computes work data (either a block hash







>












>







717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
.BR previous .
.JB

.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
account is used, otherwise the hash of the blocks predecessor
.RI ( previous )
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

This is a convenience procedure which computes work data (either a block hash

Modified nano.tcl from [fc37a0ac35] to [e923d129c3].

727
728
729
730
731
732
733

734
735
736
737
738
739
740
	set blockDict [::nano::block::dict::fromJSON $blockJSON]

	tailcall ::nano::block::dict::verifySignature $blockDict
}

proc ::nano::block::dict::work {blockDict args} {
	set outputMode "work"

	foreach arg $args {
		switch -- $arg {
			"-update" {
				set outputMode "update"
			}
			"-work" {
				set outputMode "work"







>







727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
	set blockDict [::nano::block::dict::fromJSON $blockJSON]

	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"
			}
			"-work" {
				set outputMode "work"
921
922
923
924
925
926
927
928















929
930
931
932
933



934

935
936
937
938
939
940
941
		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]







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|
>
>
>
|
>







922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
		return [::nano::block::json::fromDict $blockDict]
	}

	return $blockDict
}

# Work generation functions
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 [::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} {
	set blockDict [::nano::block::dict::fromBlock $blockData]
	set workData  [dict get $blockDict _workData]