From 7a151880dc59ce1a558b5c3fc82f6178c4a81f0f Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Tue, 14 Jun 2022 12:05:31 -0400 Subject: [PATCH 1/5] [web-monitor] Add burn prefs to API (#1134) * add burn prefs to web-monitor api * update ui * change implementation --- ol/cli/src/commands/query_cmd.rs | 2 +- ol/cli/src/node/account.rs | 4 +- ol/cli/src/node/autopay_view.rs | 2 +- ol/cli/src/node/chain_view.rs | 76 +- ol/cli/web-monitor/public/build/bundle.css | 2 +- ol/cli/web-monitor/public/build/bundle.js | 25814 +--------------- ol/cli/web-monitor/public/build/bundle.js.map | 2 +- .../src/components/validators/Vals.svelte | 3 + 8 files changed, 60 insertions(+), 25845 deletions(-) diff --git a/ol/cli/src/commands/query_cmd.rs b/ol/cli/src/commands/query_cmd.rs index d20dacad21..a270eb87ac 100644 --- a/ol/cli/src/commands/query_cmd.rs +++ b/ol/cli/src/commands/query_cmd.rs @@ -166,7 +166,7 @@ impl Runnable for QueryCmd { } /// get wallet type -pub fn get_wallet_type(account: AccountAddress, mut node: Node) -> WalletType { +pub fn get_wallet_type(account: AccountAddress, node: Node) -> WalletType { match node.get_annotate_account_blob(account) { Ok((Some(r), _)) => { if is_slow_wallet(&r) { diff --git a/ol/cli/src/node/account.rs b/ol/cli/src/node/account.rs index 0a468b1d75..28d2d60d58 100644 --- a/ol/cli/src/node/account.rs +++ b/ol/cli/src/node/account.rs @@ -174,7 +174,7 @@ impl Node { /// Return a full Move-annotated account resource struct pub fn get_annotate_account_blob( - &mut self, + &self, account: AccountAddress, ) -> Result<(Option, Version)> { let (blob, ver) = self.client.get_account_state_blob(&account)?; @@ -248,7 +248,7 @@ impl Node { seq_start.unwrap_or(0), event_handle.count() ) - } + } } /// get balance from AccountView diff --git a/ol/cli/src/node/autopay_view.rs b/ol/cli/src/node/autopay_view.rs index 18618c8305..24fea34d72 100644 --- a/ol/cli/src/node/autopay_view.rs +++ b/ol/cli/src/node/autopay_view.rs @@ -34,7 +34,7 @@ pub struct PayeeStats { impl Node { /// Get all percentage recurring payees stats - pub fn get_autopay_watch_list(&mut self, vals: Vec) -> Option> { + pub fn get_autopay_watch_list(&self, vals: Vec) -> Option> { let mut payees: HashMap = HashMap::new(); let mut total: u64 = 0; diff --git a/ol/cli/src/node/chain_view.rs b/ol/cli/src/node/chain_view.rs index e8a7c49f93..eca69f1b98 100644 --- a/ol/cli/src/node/chain_view.rs +++ b/ol/cli/src/node/chain_view.rs @@ -9,14 +9,14 @@ use diem_types::{ }; use ol_types::{autopay::AutoPayView, validator_config::ValidatorConfigView}; -use super::{node::Node, dictionary::AccountDictionary, autopay_view::PayeeStats}; +use super::{autopay_view::PayeeStats, dictionary::AccountDictionary, node::Node, query}; use serde::{Deserialize, Serialize}; use std::{ - convert::TryFrom, collections::HashMap, + convert::TryFrom, net::{IpAddr, SocketAddr, TcpStream}, + str::FromStr, time::Duration, - str::FromStr }; /// name of chain info key for db @@ -92,6 +92,8 @@ pub struct ValidatorView { pub validator_config: Option, /// autopay instructions pub autopay: Option, + /// burn preferences + pub burn_to_community: bool, /// note pub note: String, } @@ -125,7 +127,7 @@ impl Node { }; let mut cs = ChainView::default(); - // TODO: Uncomment this if the tools are not fetch up to date info + // TODO: Uncomment this if the tools are not fetch up to date info // self.client.update_and_verify_state_proof()?; cs.waypoint = self.client.waypoint().ok(); @@ -192,7 +194,7 @@ impl Node { cs.validator_view = Some(validators.clone()); cs.validators_stats = Some(validators_stats); cs.vals_config_stats = calc_config_stats(validators.clone()).ok(); - cs.autopay_watch_list = self.get_autopay_watch_list(validators.clone()); + cs.autopay_watch_list = self.get_autopay_watch_list(validators.clone()); cs.upgrade = self.client.get_oracle_upgrade_state()?; self.vitals.chain_view = Some(cs.clone()); @@ -204,10 +206,10 @@ impl Node { } fn format_validator_info( - &self, + &mut self, v: &ValidatorInfo, dict: &AccountDictionary, - stats: &ValidatorsStatsResource + stats: &ValidatorsStatsResource, ) -> Result { let vfn_full_ip = match v.config().fullnode_network_addresses() { Ok(ips) => { @@ -223,27 +225,29 @@ impl Node { let vfn_ip = extract_ip(&vfn_full_ip); let validator_full_ip = match v.config().validator_network_addresses() { - Ok(ips) => { - ips.first() - .unwrap() - .clone() - .decrypt( - &diem_types::network_address::encrypted::TEST_SHARED_VAL_NETADDR_KEY, - &v.account_address().clone(), - 0 - )? - .to_string() - }, + Ok(ips) => ips + .first() + .unwrap() + .clone() + .decrypt( + &diem_types::network_address::encrypted::TEST_SHARED_VAL_NETADDR_KEY, + &v.account_address().clone(), + 0, + )? + .to_string(), Err(_) => "--".to_string(), }; let validator_ip = extract_ip(&validator_full_ip); - let ms = self.client.get_miner_state(&v.account_address().clone())?.unwrap(); + let ms = self + .client + .get_miner_state(&v.account_address().clone())? + .unwrap(); let one_val_stat = stats.get_validator_current_stats(v.account_address().clone())?; - let val_config_opt = match self.get_validator_config(v.account_address().clone()){ + let val_config_opt = match self.get_validator_config(v.account_address().clone()) { Ok(v) => Some(v), Err(_) => None, }; @@ -253,6 +257,22 @@ impl Node { Err(_) => None, }; + let burn_to_community = match self.get_annotate_account_blob(v.account_address().clone()) { + Ok((Some(r), _)) => { + match query::find_value_from_state( + &r, + "Burn".to_string(), + "BurnPreference".to_string(), + "send_community".to_string(), + ) { + Some(resource_viewer::AnnotatedMoveValue::Bool(b)) => *b, + _ => false + } + + } + _ => false, + }; + let ports = get_ports_status(&validator_ip); Ok(ValidatorView { @@ -271,15 +291,15 @@ impl Node { epochs_validating_and_mining: ms.epochs_validating_and_mining, contiguous_epochs_validating_and_mining: ms.contiguous_epochs_validating_and_mining, epochs_since_last_account_creation: ms.epochs_since_last_account_creation, - + vote_count_in_epoch: one_val_stat.vote_count, prop_count_in_epoch: one_val_stat.prop_count, validator_config: val_config_opt, autopay: autopay_opt, + burn_to_community, note: dict.get_note_for_address(*v.account_address()), }) } - } fn calc_config_stats(vals: Vec) -> Result { @@ -316,7 +336,7 @@ fn calc_config_stats(vals: Vec) -> Result fn get_ports_status(ip: &String) -> HashMap { let mut result: HashMap = HashMap::new(); - let ports = get_ports_to_test(); + let ports = get_ports_to_test(); for port in ports.iter() { result.insert(port.to_string(), scan_port(&ip, port)); } @@ -330,10 +350,10 @@ fn scan_port(ip: &String, port: &u16) -> bool { let socket_address = SocketAddr::new(address, port.clone()); match TcpStream::connect_timeout(&socket_address, timeout) { Ok(_) => true, - _ => false + _ => false, } - }, - Err(_) => false + } + Err(_) => false, } } @@ -346,6 +366,6 @@ fn extract_ip(full_ip: &String) -> String { let split_str: Vec<&str> = full_ip.split('/').collect(); match split_str.get(2) { Some(ip) => ip.to_string(), - None => full_ip.to_string() + None => full_ip.to_string(), } -} \ No newline at end of file +} diff --git a/ol/cli/web-monitor/public/build/bundle.css b/ol/cli/web-monitor/public/build/bundle.css index 6860b51fa3..20e7dddddc 100644 --- a/ol/cli/web-monitor/public/build/bundle.css +++ b/ol/cli/web-monitor/public/build/bundle.css @@ -1 +1 @@ -.owner.svelte-n6q91t{background:#E6E6E6}#validator-modal-body.svelte-zc3fmg{width:auto !important;max-width:1200px !important}.audit-container.svelte-vi7vi7{margin:auto;max-width:500px}.autopay-summary-container.svelte-1js4my7{margin:auto;max-width:400px}.disable-select{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} \ No newline at end of file +.owner.svelte-n6q91t{background:#E6E6E6}.autopay-summary-container.svelte-1js4my7{margin:auto;max-width:400px}#validator-modal-body.svelte-zc3fmg{width:auto !important;max-width:1200px !important}.audit-container.svelte-vi7vi7{margin:auto;max-width:500px}.disable-select{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} \ No newline at end of file diff --git a/ol/cli/web-monitor/public/build/bundle.js b/ol/cli/web-monitor/public/build/bundle.js index c0a3514a60..c7b8a78e62 100644 --- a/ol/cli/web-monitor/public/build/bundle.js +++ b/ol/cli/web-monitor/public/build/bundle.js @@ -1,786 +1,5 @@ -var app = (function () { - 'use strict'; - - function noop() { } - function add_location(element, file, line, column, char) { - element.__svelte_meta = { - loc: { file, line, column, char } - }; - } - function run(fn) { - return fn(); - } - function blank_object() { - return Object.create(null); - } - function run_all(fns) { - fns.forEach(run); - } - function is_function(thing) { - return typeof thing === 'function'; - } - function safe_not_equal(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); - } - function is_empty(obj) { - return Object.keys(obj).length === 0; - } - function null_to_empty(value) { - return value == null ? '' : value; - } - function append(target, node) { - target.appendChild(node); - } - function insert(target, node, anchor) { - target.insertBefore(node, anchor || null); - } - function detach(node) { - node.parentNode.removeChild(node); - } - function destroy_each(iterations, detaching) { - for (let i = 0; i < iterations.length; i += 1) { - if (iterations[i]) - iterations[i].d(detaching); - } - } - function element(name) { - return document.createElement(name); - } - function text(data) { - return document.createTextNode(data); - } - function space() { - return text(' '); - } - function empty() { - return text(''); - } - function listen(node, event, handler, options) { - node.addEventListener(event, handler, options); - return () => node.removeEventListener(event, handler, options); - } - function attr(node, attribute, value) { - if (value == null) - node.removeAttribute(attribute); - else if (node.getAttribute(attribute) !== value) - node.setAttribute(attribute, value); - } - function children(element) { - return Array.from(element.childNodes); - } - function custom_event(type, detail, bubbles = false) { - const e = document.createEvent('CustomEvent'); - e.initCustomEvent(type, bubbles, false, detail); - return e; - } - - let current_component; - function set_current_component(component) { - current_component = component; - } - function get_current_component() { - if (!current_component) - throw new Error('Function called outside component initialization'); - return current_component; - } - function onDestroy(fn) { - get_current_component().$$.on_destroy.push(fn); - } - - const dirty_components = []; - const binding_callbacks = []; - const render_callbacks = []; - const flush_callbacks = []; - const resolved_promise = Promise.resolve(); - let update_scheduled = false; - function schedule_update() { - if (!update_scheduled) { - update_scheduled = true; - resolved_promise.then(flush); - } - } - function add_render_callback(fn) { - render_callbacks.push(fn); - } - let flushing = false; - const seen_callbacks = new Set(); - function flush() { - if (flushing) - return; - flushing = true; - do { - // first, call beforeUpdate functions - // and update components - for (let i = 0; i < dirty_components.length; i += 1) { - const component = dirty_components[i]; - set_current_component(component); - update(component.$$); - } - set_current_component(null); - dirty_components.length = 0; - while (binding_callbacks.length) - binding_callbacks.pop()(); - // then, once components are updated, call - // afterUpdate functions. This may cause - // subsequent updates... - for (let i = 0; i < render_callbacks.length; i += 1) { - const callback = render_callbacks[i]; - if (!seen_callbacks.has(callback)) { - // ...so guard against infinite loops - seen_callbacks.add(callback); - callback(); - } - } - render_callbacks.length = 0; - } while (dirty_components.length); - while (flush_callbacks.length) { - flush_callbacks.pop()(); - } - update_scheduled = false; - flushing = false; - seen_callbacks.clear(); - } - function update($$) { - if ($$.fragment !== null) { - $$.update(); - run_all($$.before_update); - const dirty = $$.dirty; - $$.dirty = [-1]; - $$.fragment && $$.fragment.p($$.ctx, dirty); - $$.after_update.forEach(add_render_callback); - } - } - const outroing = new Set(); - let outros; - function group_outros() { - outros = { - r: 0, - c: [], - p: outros // parent group - }; - } - function check_outros() { - if (!outros.r) { - run_all(outros.c); - } - outros = outros.p; - } - function transition_in(block, local) { - if (block && block.i) { - outroing.delete(block); - block.i(local); - } - } - function transition_out(block, local, detach, callback) { - if (block && block.o) { - if (outroing.has(block)) - return; - outroing.add(block); - outros.c.push(() => { - outroing.delete(block); - if (callback) { - if (detach) - block.d(1); - callback(); - } - }); - block.o(local); - } - } - - const globals = (typeof window !== 'undefined' - ? window - : typeof globalThis !== 'undefined' - ? globalThis - : global); - function create_component(block) { - block && block.c(); - } - function mount_component(component, target, anchor, customElement) { - const { fragment, on_mount, on_destroy, after_update } = component.$$; - fragment && fragment.m(target, anchor); - if (!customElement) { - // onMount happens before the initial afterUpdate - add_render_callback(() => { - const new_on_destroy = on_mount.map(run).filter(is_function); - if (on_destroy) { - on_destroy.push(...new_on_destroy); - } - else { - // Edge case - component was destroyed immediately, - // most likely as a result of a binding initialising - run_all(new_on_destroy); - } - component.$$.on_mount = []; - }); - } - after_update.forEach(add_render_callback); - } - function destroy_component(component, detaching) { - const $$ = component.$$; - if ($$.fragment !== null) { - run_all($$.on_destroy); - $$.fragment && $$.fragment.d(detaching); - // TODO null out other refs, including component.$$ (but need to - // preserve final state?) - $$.on_destroy = $$.fragment = null; - $$.ctx = []; - } - } - function make_dirty(component, i) { - if (component.$$.dirty[0] === -1) { - dirty_components.push(component); - schedule_update(); - component.$$.dirty.fill(0); - } - component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31)); - } - function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) { - const parent_component = current_component; - set_current_component(component); - const $$ = component.$$ = { - fragment: null, - ctx: null, - // state - props, - update: noop, - not_equal, - bound: blank_object(), - // lifecycle - on_mount: [], - on_destroy: [], - on_disconnect: [], - before_update: [], - after_update: [], - context: new Map(options.context || (parent_component ? parent_component.$$.context : [])), - // everything else - callbacks: blank_object(), - dirty, - skip_bound: false, - root: options.target || parent_component.$$.root - }; - append_styles && append_styles($$.root); - let ready = false; - $$.ctx = instance - ? instance(component, options.props || {}, (i, ret, ...rest) => { - const value = rest.length ? rest[0] : ret; - if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { - if (!$$.skip_bound && $$.bound[i]) - $$.bound[i](value); - if (ready) - make_dirty(component, i); - } - return ret; - }) - : []; - $$.update(); - ready = true; - run_all($$.before_update); - // `false` as a special case of no DOM component - $$.fragment = create_fragment ? create_fragment($$.ctx) : false; - if (options.target) { - if (options.hydrate) { - const nodes = children(options.target); - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - $$.fragment && $$.fragment.l(nodes); - nodes.forEach(detach); - } - else { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - $$.fragment && $$.fragment.c(); - } - if (options.intro) - transition_in(component.$$.fragment); - mount_component(component, options.target, options.anchor, options.customElement); - flush(); - } - set_current_component(parent_component); - } - /** - * Base class for Svelte components. Used when dev=false. - */ - class SvelteComponent { - $destroy() { - destroy_component(this, 1); - this.$destroy = noop; - } - $on(type, callback) { - const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = [])); - callbacks.push(callback); - return () => { - const index = callbacks.indexOf(callback); - if (index !== -1) - callbacks.splice(index, 1); - }; - } - $set($$props) { - if (this.$$set && !is_empty($$props)) { - this.$$.skip_bound = true; - this.$$set($$props); - this.$$.skip_bound = false; - } - } - } - - function dispatch_dev(type, detail) { - document.dispatchEvent(custom_event(type, Object.assign({ version: '3.44.2' }, detail), true)); - } - function append_dev(target, node) { - dispatch_dev('SvelteDOMInsert', { target, node }); - append(target, node); - } - function insert_dev(target, node, anchor) { - dispatch_dev('SvelteDOMInsert', { target, node, anchor }); - insert(target, node, anchor); - } - function detach_dev(node) { - dispatch_dev('SvelteDOMRemove', { node }); - detach(node); - } - function listen_dev(node, event, handler, options, has_prevent_default, has_stop_propagation) { - const modifiers = options === true ? ['capture'] : options ? Array.from(Object.keys(options)) : []; - if (has_prevent_default) - modifiers.push('preventDefault'); - if (has_stop_propagation) - modifiers.push('stopPropagation'); - dispatch_dev('SvelteDOMAddEventListener', { node, event, handler, modifiers }); - const dispose = listen(node, event, handler, options); - return () => { - dispatch_dev('SvelteDOMRemoveEventListener', { node, event, handler, modifiers }); - dispose(); - }; - } - function attr_dev(node, attribute, value) { - attr(node, attribute, value); - if (value == null) - dispatch_dev('SvelteDOMRemoveAttribute', { node, attribute }); - else - dispatch_dev('SvelteDOMSetAttribute', { node, attribute, value }); - } - function set_data_dev(text, data) { - data = '' + data; - if (text.wholeText === data) - return; - dispatch_dev('SvelteDOMSetData', { node: text, data }); - text.data = data; - } - function validate_each_argument(arg) { - if (typeof arg !== 'string' && !(arg && typeof arg === 'object' && 'length' in arg)) { - let msg = '{#each} only iterates over array-like objects.'; - if (typeof Symbol === 'function' && arg && Symbol.iterator in arg) { - msg += ' You can use a spread to convert this iterable into an array.'; - } - throw new Error(msg); - } - } - function validate_slots(name, slot, keys) { - for (const slot_key of Object.keys(slot)) { - if (!~keys.indexOf(slot_key)) { - console.warn(`<${name}> received an unexpected slot "${slot_key}".`); - } - } - } - /** - * Base class for Svelte components with some minor dev-enhancements. Used when dev=true. - */ - class SvelteComponentDev extends SvelteComponent { - constructor(options) { - if (!options || (!options.target && !options.$$inline)) { - throw new Error("'target' is a required option"); - } - super(); - } - $destroy() { - super.$destroy(); - this.$destroy = () => { - console.warn('Component was already destroyed'); // eslint-disable-line no-console - }; - } - $capture_state() { } - $inject_state() { } - } - - /* src/components/layout/Nav.svelte generated by Svelte v3.44.2 */ - - const file$i = "src/components/layout/Nav.svelte"; - - function create_fragment$i(ctx) { - let main; - let nav; - let div; - let ul; - let li0; - let a0; - let t1; - let li1; - let a1; - let t3; - let li2; - let a2; - let t5; - let li3; - let a3; - let t7; - let li4; - let a4; - let t9; - let li5; - let a5; - - const block = { - c: function create() { - main = element("main"); - nav = element("nav"); - div = element("div"); - ul = element("ul"); - li0 = element("li"); - a0 = element("a"); - a0.textContent = "Dash"; - t1 = space(); - li1 = element("li"); - a1 = element("a"); - a1.textContent = "Validators"; - t3 = space(); - li2 = element("li"); - a2 = element("a"); - a2.textContent = "Autopay"; - t5 = space(); - li3 = element("li"); - a3 = element("a"); - a3.textContent = "Watch List"; - t7 = space(); - li4 = element("li"); - a4 = element("a"); - a4.textContent = "Audit"; - t9 = space(); - li5 = element("li"); - a5 = element("a"); - a5.textContent = "Upgrades"; - attr_dev(a0, "href", "#"); - add_location(a0, file$i, 4, 30, 226); - attr_dev(li0, "class", "uk-active"); - add_location(li0, file$i, 4, 8, 204); - attr_dev(a1, "href", "#"); - add_location(a1, file$i, 5, 12, 264); - add_location(li1, file$i, 5, 8, 260); - attr_dev(a2, "href", "#"); - add_location(a2, file$i, 6, 12, 308); - add_location(li2, file$i, 6, 8, 304); - attr_dev(a3, "href", "#"); - add_location(a3, file$i, 7, 12, 349); - add_location(li3, file$i, 7, 8, 345); - attr_dev(a4, "href", "#"); - add_location(a4, file$i, 8, 12, 393); - add_location(li4, file$i, 8, 8, 389); - attr_dev(a5, "href", "#"); - add_location(a5, file$i, 9, 12, 432); - add_location(li5, file$i, 9, 8, 428); - attr_dev(ul, "class", "uk-navbar-nav uk-text-center"); - attr_dev(ul, "uk-switcher", "connect: .switcher-container"); - add_location(ul, file$i, 3, 6, 111); - attr_dev(div, "class", "uk-navbar-center uk-overflow-auto"); - add_location(div, file$i, 2, 4, 57); - attr_dev(nav, "class", "uk-navbar-container"); - attr_dev(nav, "uk-navbar", ""); - add_location(nav, file$i, 1, 2, 9); - add_location(main, file$i, 0, 0, 0); - }, - l: function claim(nodes) { - throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); - }, - m: function mount(target, anchor) { - insert_dev(target, main, anchor); - append_dev(main, nav); - append_dev(nav, div); - append_dev(div, ul); - append_dev(ul, li0); - append_dev(li0, a0); - append_dev(ul, t1); - append_dev(ul, li1); - append_dev(li1, a1); - append_dev(ul, t3); - append_dev(ul, li2); - append_dev(li2, a2); - append_dev(ul, t5); - append_dev(ul, li3); - append_dev(li3, a3); - append_dev(ul, t7); - append_dev(ul, li4); - append_dev(li4, a4); - append_dev(ul, t9); - append_dev(ul, li5); - append_dev(li5, a5); - }, - p: noop, - i: noop, - o: noop, - d: function destroy(detaching) { - if (detaching) detach_dev(main); - } - }; - - dispatch_dev("SvelteRegisterBlock", { - block, - id: create_fragment$i.name, - type: "component", - source: "", - ctx - }); - - return block; - } - - function instance$i($$self, $$props) { - let { $$slots: slots = {}, $$scope } = $$props; - validate_slots('Nav', slots, []); - const writable_props = []; - - Object.keys($$props).forEach(key => { - if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console.warn(`