︙ | | |
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
proc ::nano::block::json::toBlock {blockJSON} {
set blockDict [::nano::block::dict::fromJSON $blockJSON]
tailcall ::nano::block::dict::toBlock $blockDict
}
proc ::nano::block::dict::fromJSON {blockJSON} {
tailcall ::json::json2dict $blockJSON
set retval [::json::json2dict $blockJSON]
if {[dict get $retval "type"] eq "send"} {
set balance [dict get $retval "balance"]
set balance [format %lli "0x$balance"]
dict set retval "balance" $balance
}
# Parse out the work data
if {[dict get $retval "type"] in {send receive change state}} {
set workDataBasedOn "previous"
}
if {[dict get $retval "type"] eq "state" && [dict get $retval "previous"] eq "0000000000000000000000000000000000000000000000000000000000000000" && [dict get $retval "link"] eq "0000000000000000000000000000000000000000000000000000000000000000"} {
set workDataBasedOn "account"
}
if {[dict get $retval "type"] eq "open"} {
set workDataBasedOn "account"
}
if {[info exists workDataBasedOn]} {
if {$workDataBasedOn eq "previous"} {
dict set retval "_workData" [dict get $retval "previous"]
} else {
dict set retval "_workData" [::nano::address::toPublicKey [dict get $retval "account"]]
}
}
return $retval
}
proc ::nano::block::json::fromDict {blockDict} {
array set block $blockDict
if {$block(type) eq "state"} {
if {![info exists block(link)]} {
|
︙ | | |
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
+
+
+
+
+
+
+
+
|
"work" {
if {[string length $block($field)] == $::nano::work::workValueLength} {
set block($field) [binary encode hex $block($field)]
}
set block($field) [string tolower $block($field)]
}
"balance" {
if {$block(type) in {send receive change open}} {
set balanceFormatStr %032llx
} else {
set balanceFormatStr %lli
}
set block($field) [string toupper [format $balanceFormatStr "$block($field)"]]
}
}
return -level 0 [list $field [json::write string $block($field)]]
}]
set blockJSONEntries [join $blockJSONEntries]
set blockJSON [json::write object {*}$blockJSONEntries]
|
︙ | | |
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
+
+
+
+
+
+
+
+
|
}
}
"open" {
binary scan $blockData H64a32a32 \
block(source) \
block(representative) \
block(account)
set block(_workData) $block(account)
}
"send" {
binary scan $blockData H64a32H32 \
block(previous) \
block(destination) \
block(balance)
set block(_workData) $block(previous)
}
"receive" {
binary scan $blockData H64H64 \
block(previous) \
block(source)
set block(_workData) $block(previous)
}
"change" {
binary scan $blockData H64a32 \
block(previous) \
block(representative)
set block(_workData) $block(previous)
}
default {
return -code error "Invalid block type: $block(type)"
}
}
foreach field {account representative link_as_account destination balance} {
|
︙ | | |
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
|
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
|
-
+
|
tailcall ::nano::work::validate $blockHash $work
}
proc ::nano::block::json::validateWork {blockJSON} {
set blockDict [::nano::block::dict::fromJSON $blockJSON]
tailcall ::nano::block::dict::validate $blockDict
tailcall ::nano::block::dict::validateWork $blockDict
}
# send from <account> to <account> previousBalance <balance>
# amount <amount> sourceBlock <sourceBlockHash>
# previous <previousBlockHash> ?representative <representative>?
proc ::nano::block::create::send {args} {
array set block $args
|
︙ | | |