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
962
963
964
965
966
967
|
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
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
|
}
proc ::nano::account::addPending {account blockHash amount} {
set accountPubKey [::nano::address::toPublicKey $account -hex]
dict set ::nano::account::pending $accountPubKey $blockHash amount $amount
}
proc ::nano::account::getPending {account args} {
set accountPubKey [::nano::address::toPublicKey $account -hex]
set retval [dict create]
catch {
set retval [dict get $::nano::account::pending $accountPubKey {*}$args]
}
return $retval
}
proc ::nano::account::clearPending {account args} {
set accountPubKey [::nano::address::toPublicKey $account -hex]
catch {
dict unset ::nano::account::pending $accountPubKey {*}$args
}
return
}
proc ::nano::account::receive {account blockHash signKey} {
set accountPubKey [::nano::address::toPublicKey $account -hex]
set frontierInfo [getFrontier $account]
dict with frontierInfo {}
set blockInfo [dict get $::nano::account::pending $accountPubKey $blockHash]
set blockInfo [getPending $account $blockHash]
set amount [dict get $blockInfo amount]
set blockArgs [list to $account previousBalance $balance \
amount $amount sourceBlock $blockHash \
signKey $signKey representative $representative]
if {[info exists frontierHash]} {
lappend blockArgs previous $frontierHash
}
dict set blockArgs -json true
set block [::nano::block::create::receive {*}$blockArgs]
set newFrontierHash [dict get [json::json2dict $block] "_blockHash"]
set balance [expr {$balance + $amount}]
setFrontier $account $newFrontierHash $balance $representative
dict unset ::nano::account::pending $accountPubKey $blockHash
clearPending $account $blockHash
return $block
}
proc ::nano::account::send {fromAccount toAccount amount signKey} {
set fromAccountPubKey [::nano::address::toPublicKey $fromAccount -hex]
set toAccountPubKey [::nano::address::toPublicKey $fromAccount -hex]
|
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
|
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
|
+
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
proc ::nano::account::receiveAllPending {key {accountPubKey ""}} {
set outBlocks [list]
if {$accountPubKey eq ""} {
set accountPubKey [::nano::key::publicKeyFromPrivateKey $key -hex]
}
set account [::nano::address::fromPublicKey $accountPubKey]
if {![dict exists $::nano::account::pending $accountPubKey]} {
set pendingBlocks [getPending $account]
if {[llength $pendingBlocks] == 0} {
return $outBlocks
}
set signKey [binary encode hex $key]
set account [::nano::address::fromPublicKey $accountPubKey]
foreach blockHash [dict keys [dict get $::nano::account::pending $accountPubKey]] {
foreach blockHash [dict keys $pendingBlocks] {
lappend outBlocks [receive $account $blockHash $signKey]
}
return $outBlocks
}
proc ::nano::account::setRepresentative {account representative signKey} {
set accountPubKey [::nano::address::toPublicKey $account -hex]
set frontierInfo [getFrontier $account]
dict with frontierInfo {}
set blockArgs [list account $account \
representative $representative \
signKey $signKey \
previous $frontierHash \
]
dict set blockArgs -json true
set block [::nano::block::create::setRepresentative {*}$blockArgs]
set newFrontierHash [dict get [json::json2dict $block] "_blockHash"]
setFrontier $account $newFrontierHash $balance $representative
return $block
}
|