extends layout

block headContent
	title Node Status
	
block content
	h1(class="h2") Node Status
	hr

	if (getblockchaininfo)
		p Data from RPC commands 
			a(href="/rpc-browser?method=getblockchaininfo") getblockchaininfo
			span , 
			a(href="/rpc-browser?method=getnetworkinfo") getnetworkinfo
			span , and 
			a(href="/rpc-browser?method=getnettotals") getnettotals

		if (false)
			pre
				code #{JSON.stringify(getblockchaininfo, null, 4)}

		if (true)
			table(class="table")
				tr
					th(class="table-active properties-header") Host : Port
					td(class="monospace") #{env.rpc.host + " : " + env.rpc.port}

				tr
					th(class="table-active properties-header") Chain
					td(class="monospace") #{getblockchaininfo.chain}
				tr
					th(class="table-active properties-header") Version
					td(class="monospace") #{getnetworkinfo.version}
						span(class="monospace")  (#{getnetworkinfo.subversion})
				tr
					th(class="table-active properties-header") Protocol Version
					td(class="monospace") #{getnetworkinfo.protocolversion}

				if (getblockchaininfo.size_on_disk)
					tr
						th(class="table-active properties-header") Blockchain Size
						td(class="monospace") #{utils.formatBytes(getblockchaininfo.size_on_disk)}
							span(class="text-muted")  (pruned: #{getblockchaininfo.pruned})
				tr
					th(class="table-active properties-header") Connections
					td(class="monospace") #{getnetworkinfo.connections.toLocaleString()}
				tr
					th(class="table-active properties-header") Block Count
					td(class="monospace") #{getblockchaininfo.blocks.toLocaleString()}
						span(class="text-muted")  (header count: #{getblockchaininfo.headers.toLocaleString()})
				tr
					- var scales = [ {val:1000000000000000, name:"quadrillion"}, {val:1000000000000, name:"trillion"}, {val:1000000000, name:"billion"}, {val:1000000, name:"million"} ];
					- var scaleDone = false;
					th(class="table-active properties-header") Difficulty
					td(class="monospace")
						span #{parseFloat(getblockchaininfo.difficulty).toLocaleString()}
						each item in scales
							if (!scaleDone)
								- var fraction = Math.floor(getblockchaininfo.difficulty / item.val);
								if (fraction >= 1)
									- scaleDone = true;
									span(class="text-muted")  (#{fraction} #{item.name})

				tr
					th(class="table-active properties-header") Status
					td(class="monospace")
						if (getblockchaininfo.initialblockdownload || getblockchaininfo.headers > getblockchaininfo.blocks)
							span Initial block download progress #{(100 * getblockchaininfo.verificationprogress).toLocaleString()}%
						else
							span Synchronized with network

				- var startTimeAgo = moment.duration(uptimeSeconds * 1000);
				tr
					th(class="table-active properties-header") Uptime
					td(class="monospace") #{startTimeAgo.format()}

				tr
					th(class="table-active properties-header") Network Traffic
					td(class="monospace")
						span Total Download: #{utils.formatBytes(getnettotals.totalbytesrecv)}
						span(class="text-muted")  (avg #{utils.formatBytes(getnettotals.totalbytesrecv / uptimeSeconds)}/s)
						br
						span Total Upload: #{utils.formatBytes(getnettotals.totalbytessent)}
						span(class="text-muted")  (avg #{utils.formatBytes(getnettotals.totalbytessent / uptimeSeconds)}/s)

				tr
					th(class="table-active properties-header") Warnings
					td(class="monospace")
						if (getblockchaininfo.warnings && getblockchaininfo.warnings.trim().length > 0)
							span #{getblockchaininfo.warnings}
						else
							span None