Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi masternodes #517

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"no-constant-condition": "off",
"@typescript-eslint/no-empty-function": "off",
"no-console": "error",
"eqeqeq": ["error", "smart"]
"eqeqeq": ["error", "smart"],
"no-warning-comments": [
"error",
{ "terms": ["fail"], "location": "anywhere" }
]
}
}
12 changes: 12 additions & 0 deletions assets/icons/icon-trash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions locale/cnr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/de/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/en/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "Save Wallet File" # Save Wallet File
proposalOverBudget = "Over Budget" # Over Budget
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "Creating SHIELD transaction..." # Creating SHIELD transaction...
masternodeRestartConfirmation = "Are you sure you want to restart your masternode?" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "Are you sure you want to delete your masternode?" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "Restart Masternode" # Restart Masternode
masternodeDeleteTitle = "Delete Masternode" # Delete Masternode
votedMultiMn = "Voted with {successfulVotes} out of {totalVotes} masternodes" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "Part of your staked balance may be locked for 100 blocks as your reward matures." # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/es-mx/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/fr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/hi/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ shieldAddress = "शील्ड एड्रेस" # Shield address
cantShieldToExc = "यह एड्रेस शील्ड ट्रांसफर का समर्थन नहीं करता" # This address does not support shield transfers
badSaplingRoot = "सिंक करते समय एक त्रुटि हुई। रिसिंकिंग कर रहे हैं स्क्रैच से(खराब सैपलिंग रूट)" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "क्रिएटिंग शील्ड ट्रांजेक्शन..." # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/it/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/nl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/ph/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/pl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/pt-br/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/pt-pt/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/template/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ shieldAddress = "Shield address"
cantShieldToExc = "This address does not support shield transfers"
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)"
creatingShieldTransaction = "Creating SHIELD transaction..."
masternodeRestartConfirmation = "Are you sure you want to restart your masternode?"
masternodeRestartTitle = "Restart Masternode"
masternodeDeleteConfirmation = "Are you sure you want to delete your masternode?"
masternodeDeleteTitle = "Delete Masternode"
votedMultiMn = "Voted with {successfulVotes} out of {totalVotes} masternodes"
immatureRewards = "Part of your staked balance may be locked for 100 blocks as your reward matures."

[ALERTS]
Expand Down
5 changes: 5 additions & 0 deletions locale/uwu/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ saveWalletFile = "Save Wawwet File" # Save Wallet File
proposalOverBudget = "Over Budgey" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
masternodeRestartConfirmation = "" # Are you sure you want to restart your masternode?
masternodeDeleteConfirmation = "" # Are you sure you want to delete your masternode?
masternodeRestartTitle = "" # Restart Masternode
masternodeDeleteTitle = "" # Delete Masternode
votedMultiMn = "" # Voted with {successfulVotes} out of {totalVotes} masternodes
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.

[ALERTS]
Expand Down
17 changes: 10 additions & 7 deletions scripts/charting.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ async function getWalletDataset() {
});
}

const masternode = await (await Database.getInstance()).getMasternode();
const masternodes = await (await Database.getInstance()).getMasternodes();
let masternodeValue = 0;

// Masternode (Locked)
if (masternode) {
for (const masternode of masternodes) {
if (
wallet.isCoinLocked(
new COutpoint({
Expand All @@ -105,13 +106,15 @@ async function getWalletDataset() {
})
)
) {
arrBreakdown.push({
type: 'Masternode',
balance: cChainParams.current.collateralInSats / COIN,
colour: 'rgba(19, 13, 30, 1)',
});
masternodeValue += cChainParams.current.collateralInSats / COIN;
}
}
if (masternodeValue !== 0)
arrBreakdown.push({
type: 'Masternodes',
balance: masternodeValue,
colour: 'rgba(19, 13, 30, 1)',
});
return arrBreakdown;
}

Expand Down
46 changes: 38 additions & 8 deletions scripts/composables/use_masternode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { getEventEmitter } from '../event_bus.js';

export const useMasternode = defineStore('masternode', () => {
/**
* @type{import('vue').Ref<import('../masternode.js').default?>}
* @type{import('vue').Ref<import('../masternode.js').default[]?>}
*/
const masternode = ref(null);
const masternodes = ref([]);
const localProposals = ref([]);
watch(
localProposals,
Expand All @@ -32,13 +32,43 @@ export const useMasternode = defineStore('masternode', () => {

const fetchMasternodeFromDatabase = async () => {
const database = await Database.getInstance();
masternode.value = await database.getMasternode();
masternodes.value = await database.getMasternodes();
};

watch(masternode, async () => {
const database = await Database.getInstance();
await database.addMasternode(toRaw(masternode.value));
});
watch(
masternodes,
async () => {
const database = await Database.getInstance();
// Ideally we would avoid this db read,
// but since adding and removing an array is a relatively rare occurrance
// This shouldn't be much of a problem
const storedMns = await database.getMasternodes();

const hasMn = (mn, array) => {
return array
.map((arrayMn) => arrayMn.mnPrivateKey)
.includes(mn.mnPrivateKey);
};

const toAdd = masternodes.value.filter(
(mn) => !hasMn(mn, storedMns)
);
const toRemove = storedMns.filter(
(storedMn) => !hasMn(storedMn, masternodes.value)
);

for (const mn of toAdd) {
await database.addMasternode(toRaw(mn));
}

for (const mn of toRemove) {
await database.removeMasternode(toRaw(mn));
}
},
{
deep: true,
}
);

getEventEmitter().on('wallet-import', () => {
fetchProposalsFromDatabase().then(() => {});
Expand All @@ -48,5 +78,5 @@ export const useMasternode = defineStore('masternode', () => {
fetchProposalsFromDatabase().then(() => {});
fetchMasternodeFromDatabase().then(() => {});
});
return { masternode, localProposals };
return { masternodes, localProposals };
});
37 changes: 25 additions & 12 deletions scripts/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export class Database {
* Version 5 = Tx shield data (#295)
* Version 6 = Filter unconfirmed txs (#415)
* Version 7 = Store shield params in indexed db (#511)
* Version 8 = Multi MNs (#517)
* @type {number}
*/
static version = 7;
static version = 8;

/**
* @type{import('idb').IDBPDatabase}
Expand All @@ -40,24 +41,22 @@ export class Database {
/**
* Add masternode to the database
* @param {Masternode} masternode
* @param {Masterkey} _masterKey - Masterkey associated to the masternode. Currently unused
*/
async addMasternode(masternode, _masterKey) {
async addMasternode(masternode) {
const store = this.#db
.transaction('masternodes', 'readwrite')
.objectStore('masternodes');
// For now the key is 'masternode' since we don't support multiple masternodes
await store.put(masternode, 'masternode');
await store.put(masternode);
}
/**
* Removes a masternode
* @param {Masterkey} _masterKey - Masterkey associated to the masternode. Currently unused
* @param {Masternode} mn - Masternode to delete
*/
async removeMasternode(_masterKey) {
async removeMasternode(mn) {
const store = this.#db
.transaction('masternodes', 'readwrite')
.objectStore('masternodes');
await store.delete('masternode');
await store.delete(mn.mnPrivateKey);
}

/**
Expand Down Expand Up @@ -301,14 +300,14 @@ export class Database {
}

/**
* @returns {Promise<Masternode?>} the masternode stored in the db
* @returns {Promise<Masternode[]>} the masternodes stored in the db
*/
async getMasternode(_masterKey) {
async getMasternodes() {
const store = this.#db
.transaction('masternodes', 'readonly')
.objectStore('masternodes');
const mnData = await store.get('masternode');
return !mnData ? null : new Masternode(mnData);
const mns = await store.getAll();
return mns.map((mn) => new Masternode(mn));
}

/**
Expand Down Expand Up @@ -473,6 +472,20 @@ export class Database {
if (oldVersion < 7) {
db.createObjectStore('shieldParams');
}
if (oldVersion < 8) {
(async () => {
const store = transaction.objectStore('masternodes');
const mn = await store.get('masternode');

db.deleteObjectStore('masternodes');
const newStore = db.createObjectStore('masternodes', {
keyPath: 'mnPrivateKey',
});
if (mn) {
await newStore.add(mn);
}
})();
}
},
blocking: () => {
// Another instance is waiting to upgrade, and we're preventing it
Expand Down
Loading