Diff

Differences From Artifact [594189ec1a]:

To Artifact [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
376
377
378
379
380
381
382
383

			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 signature _comment
	}

	set blockJSONEntries [lmap field $blockJSONFields {
		if {![info exists block($field)]} {
			continue
		}








|







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 \
	]