Diff

Differences From Artifact [1d335ca4b1]:

To Artifact [7a1ec5be31]:


1188
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1188
1189
1190
1191
1192
1193
1194

1195
1196
1197
1198
1199
1200
1201
1202







-
+








	set envHandle [dict get $lmdbInfo envHandle]
	set dbHandle [lmdb open -env $envHandle -name $table]
	set sessionHandle [$envHandle txn -readonly $readOnly]
	set cursor [$dbHandle cursor -txn $sessionHandle]

	uplevel 1 [list set $cursorVar $cursor]
	set retcode [catch [list uplevel 1 $code] retval options]
	set retcode [catch {uplevel 1 $code} retval options]

	$cursor close
	if {$retcode == 0} {
		$sessionHandle commit
	} else {
		if {$readOnly} {
			$sessionHandle reset
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
1251


1252
1253
1254
1255
1256
1257
1258




1259
1260
1261


1262
1263
1264


1265
1266

1267


1268








1269
1270
1271
1272
1273
1274
1275
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
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307



1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329




1330
1331
1332
1333






1334
1335
1336
1337
1338
1339
1340
1341




1342
1343
1344
1345
1346


1347
1348


1349




1350
1351
1352
1353
1354


1355
1356
1357


1358
1359
1360

1361
1362
1363
1364

1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+














-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+
-
-

-
-
-
-
+
+
+
+

-
-
+
+

-
-
+
+

-
+

+
+
-
+
+
+
+
+
+
+
+







	if {$retcode == 0} {
		return $retval
	}

	return {*}$options $retval
}

proc ::nano::ledger::lmdb::_foreach {lmdbInfo table cursorVar keyVar valueVar args} {
	set code [lindex $args end]
	set args [lrange $args 0 end-1]

	if {[llength $args] == 0} {
		set initialize [list getBinary "-first"]
	} else {
		if {[lindex $args 0] eq "-set"} {
			set checkKeyEqual [lindex $args 1]
		}

		set initialize [list getBinary {*}$args]
	}
	set iterate [list getBinary "-next"]

	_transaction $lmdbInfo $table cursor {
		if {$cursorVar ne ""} {
			uplevel 1 [list set $cursorVar $cursor]
		}

		for {
			if {[catch {
				set work [$cursor {*}$initialize]
			} err]} {
				if {[string match "ERROR: MDB_NOTFOUND: *" $err]} {
					return
				}

				return -code error $err
			}
		} true {
			if {[catch {
				set work [$cursor {*}$iterate]
			} err]} {
				if {[string match "ERROR: MDB_NOTFOUND: *" $err]} {
					break
				}

				return -code error $err
			}
		} {
			unset -nocomplain key

			if {[info exists checkKeyEqual]} {
				set key [lindex $work 0]
				if {$key ne $checkKeyEqual} {
					break
				}
			}

			if {$keyVar ne ""} {
				if {![info exists key]} {
					set key [lindex $work 0]
				}
				uplevel 1 [list set $keyVar $key]
			}

			if {$valueVar ne ""} {
				set value [lindex $work 1]
				uplevel 1 [list set $valueVar $value]
			}

			catch {uplevel 1 $code} retval options

			switch -- [dict get $options "-code"] {
				4 - 0 {
					# TCL_CONTINUE or TCL_OK
					continue
				}
				1 {
					# TCL_ERROR, pass it on
					dict set options "-level" 1
					return {*}$options $retval
				}
				2 {
					# TCL_RETURN
					return -level 2 $retval
				}
				3 {
					# TCL_BREAK
					break
				}
			}
		}
	}

	return
}

interp alias {} ::nano::ledger::lmdb::_magicSpeedup {} time

proc ::nano::ledger::lmdb::getPending {lmdbInfo account args} {
	set accountPubKey [::nano::address::toPublicKey $account -binary]
	set searchKey $accountPubKey
proc ::nano::ledger::lmdb::getPending {lmdbInfo args} {
	if {[llength $args] > 0} {
		set account [lindex $args 0]
		set accountPubKey [::nano::address::toPublicKey $account -binary]
		append searchKey $accountPubKey

		set args [lrange $args 1 end]
	}

	if {[llength $args] > 0} {
		set blockHash [lindex $args 0]
		if {[string length $blockHash] != $::nano::block::hashLength} {
			set blockHash [binary decode hex $blockHash]

			append searchKey $blockHash
		}

		set args [lrange $args 1 end]
	}

	set retval [list]

	_transaction $lmdbInfo "pending" cursor {
		set work [$cursor getBinary -set_range $searchKey]
		while true {
			set key [lindex $work 0]
	if {[info exists searchKey]} {
		set searchKey [list "-set_range" $searchKey]
	} else {
		set searchKey [list]
			set value [lindex $work 1]

			set keyAccountPubKey [string range $key 0 31]
			if {$keyAccountPubKey ne $accountPubKey} {
				break
			}
	}

	_foreach $lmdbInfo "pending" cursor key value {*}$searchKey {
		set keyAccountPubKey [string range $key 0 31]
		if {[info exists accountPubKey] && $keyAccountPubKey ne $accountPubKey} {
			break
		}

			set keyBlockHash [string range $key 32 63]
			if {[info exists blockHash] && $keyBlockHash ne $blockHash} {
				break
			}
		set keyBlockHash [string range $key 32 63]
		if {[info exists blockHash] && $keyBlockHash ne $blockHash} {
			break
		}

			set from [string range $value 0 31]
			set amount [string range $value 32 47]
		set from [string range $value 0 31]
		set amount [string range $value 32 47]

			set work [$cursor getBinary -next]

			set itemDict [dict create \
				amount [format "%lli" 0x[binary encode hex $amount]] \
				from   [::nano::address::fromPublicKey $from] \
			]
		set itemDict [dict create \
			amount [format "%lli" 0x[binary encode hex $amount]] \
			from   [::nano::address::fromPublicKey $from] \
		]

			if {[info exists blockHash]} {
				set retval $itemDict
		if {[info exists blockHash]} {
			set retval $itemDict

				break
			}
			break
		}

			set keyBlockHashHex [string toupper [binary encode hex $keyBlockHash]]
		set keyBlockHashHex [string toupper [binary encode hex $keyBlockHash]]

		if {[info exists accountPubKey]} {
			_magicSpeedup {
			dict set retval $keyBlockHashHex $itemDict
				dict set retval $keyBlockHashHex [set itemDict]
			}
		} else {
			set keyAccountPubKeyHex [string toupper [binary encode hex $keyAccountPubKey]]

			_magicSpeedup {
				dict set retval $keyAccountPubKeyHex $keyBlockHashHex $itemDict
			}
		}
	}

	if {[info exists blockHash] && [llength $args] > 0} {
		set retval [dict get $retval {*}$args]
	}

1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302


1303
1304
1305
1306

1307
1308

1309
1310
1311
1312
1313
1314
1315
1316
1391
1392
1393
1394
1395
1396
1397









1398
1399




1400
1401

1402

1403
1404
1405
1406
1407
1408
1409







-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+

-
+
-







		set blockHash [lindex $args 0]
		if {[string length $blockHash] != $::nano::block::hashLength} {
			set blockHash [binary decode hex $blockHash]
		}
		set searchKey "${accountPubKey}${blockHash}"

		set numberOfRowsDeleted 0
		_transaction $lmdbInfo "pending/write" cursor {
			while true {
				if {[catch {
					$cursor getBinary -set $searchKey
				} err]} {
					if {[string match "ERROR: MDB_NOTFOUND: *" $err]} {
						break
					}


		_foreach $lmdbInfo "pending/write" cursor "" "" -set $searchKey {
					return -code error $err
				}

				$cursor del
			$cursor del

				incr numberOfRowsDeleted
			incr numberOfRowsDeleted
			}
		}

		return $numberOfRowsDeleted
	}

	set numberOfRowsDeleted 0
	set blockHashDict [getPending $lmdbInfo $account]
1329
1330
1331
1332
1333
1334
1335






1336
1337
1338
1339






1340
1341
1342
1343
1344
1345
1346
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434




1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447







+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+







	}

	set lmdbKey "${accountPubKey}${blockHash}"
	set fromHex [::nano::address::toPublicKey [dict get $args from] -hex]
	set amountHex [format %032llx [dict get $args amount]]
	set lmdbData [binary format H64H32 $fromHex $amountHex]

	set keyExists false
	_foreach $lmdbInfo "pending" "" "" "" -set $lmdbKey {
		set keyExists true
	}

	if {!$keyExists} {
	_transaction $lmdbInfo "pending/write" cursor {
		$cursor putBinary $lmdbKey $lmdbData
	}
	
		_transaction $lmdbInfo "pending/write" cursor {
			$cursor putBinary $lmdbKey $lmdbData
		}
	}

	return
}

# Node Configuration
proc ::nano::node::_configDictToJSON {configDict {prefix ""}} {
	set values [list]
	foreach key [dict keys $configDict] {
		set value [dict get $configDict $key]