8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
+
+
+
|
namespace eval ::nano::key {}
namespace eval ::nano::block {}
namespace eval ::nano::block::json {}
namespace eval ::nano::block::dict {}
namespace eval ::nano::block::create {}
namespace eval ::nano::work {}
namespace eval ::nano::account {}
namespace eval ::nano::node {}
namespace eval ::nano::ledger {}
namespace eval ::nano::ledger::lmdb {}
namespace eval ::nano::rpc {}
namespace eval ::nano::rpc::client {}
namespace eval ::nano::balance {}
# Constants
set ::nano::block::stateBlockPreamble [binary decode hex "0000000000000000000000000000000000000000000000000000000000000006"]
set ::nano::address::base32alphabet {13456789abcdefghijkmnopqrstuwxyz}
|
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
|
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
set newFrontierHash [dict get [json::json2dict $block] "_blockHash"]
setFrontier $account $newFrontierHash $balance $representative
return $block
}
# Ledger
proc ::nano::ledger::setNodeBackend {handle} {
}
proc ::nano::ledger::lmdb::openDatabase {} {
}
# Node Configuration
proc ::nano::node::_configDictToJSON {configDict {prefix ""}} {
set values [list]
foreach key [dict keys $configDict] {
set value [dict get $configDict $key]
switch -- ${prefix}${key} {
"rpc" - "node" - "opencl" - "node/logging" {
set value [_configDictToJSON $value "$key/"]
}
"node/preconfigured_peers" - "node/preconfigured_representatives" - "node/work_peers" {
set value [json::write array {*}[lmap item $value {
json::write string $item
}]]
}
default {
set value [json::write string $value]
}
}
lappend values $key $value
}
set json [json::write object {*}$values]
return $json
}
proc ::nano::node::_defaultConfig {network} {
return [dict create \
"version" 2 \
"rpc_enable" false \
"rpc" [dict create \
"address" "::ffff:127.0.0.1" \
"port" 7076 \
] \
]
}
proc ::nano::node::_loadConfigFile {file network} {
set json "{}"
catch {
set fd [open $file]
set json [read $fd]
}
catch {
close $fd
}
if {![info exists ::nano::node::configuration]} {
set ::nano::node::configuration [_defaultConfig $network]
}
set configuration [::json::json2dict $json]
set ::nano::node::configuration [dict merge $::nano::node::configuration $configuration]
return $::nano::node::configuration
}
proc ::nano::node::_saveConfigFile {file args} {
if {[llength $args] == 0} {
set configDict $::nano::node::configuration
} elseif {[llength $args] == 1} {
set configDict [lindex $args 0]
} else {
return -code error "wrong # args: _saveConfigFile <file> ?<configDict>?"
}
set json [_configDictToJSON $configDict]
set tmpfile "${file}.new"
set fd [open "${tmpfile}" "w"]
puts $fd $json
close $fd
file rename -force -- "${tmpfile}" "${file}"
return true
}
proc ::nano::node::configure {network args} {
# Set default options
set info(-configDirectory) [file normalize ~/RaiBlocks]
# Parse options to the configure
array set info $args
# Load configuration file
set configFile [file join $info(-configDirectory) "config.json"]
_loadConfigFile $configFile $network
}
# RPC Client
proc ::nano::rpc::client::init args {
if {![info exists ::nano::rpc::client::config]} {
set ::nano::rpc::client::config [dict create \
url {http://localhost:7076/} \
]
|