Commit 2f99be07 authored by Eriksson Monteiro's avatar Eriksson Monteiro

update millix node: fix wallet auto-creation. increase ad payment frequence

parent 98c0209a
...@@ -53,8 +53,8 @@ class _PMW9LXqUv7vXLpbA extends Endpoint { ...@@ -53,8 +53,8 @@ class _PMW9LXqUv7vXLpbA extends Endpoint {
res.send({ res.send({
api_status: 'success', api_status: 'success',
wallet : { wallet : {
id : walletID, id : walletID,
address : `${keyIdentifier}${addressVersion}${keyIdentifier}`, address : `${keyIdentifier}${addressVersion}${keyIdentifier}`,
address_key_identifier: keyIdentifier address_key_identifier: keyIdentifier
} }
}); });
...@@ -63,7 +63,10 @@ class _PMW9LXqUv7vXLpbA extends Endpoint { ...@@ -63,7 +63,10 @@ class _PMW9LXqUv7vXLpbA extends Endpoint {
}; };
eventBus.once('wallet_unlock', authenticationSuccessHandler); eventBus.once('wallet_unlock', authenticationSuccessHandler);
services.stop(); services.stop();
services.initialize({initialize_wallet_event: false}).catch(e => { services.initialize({
initialize_wallet_event: false,
auto_create_wallet : false
}).catch(e => {
eventBus.removeListener('wallet_authentication_error', authenticationErrorHandler); eventBus.removeListener('wallet_authentication_error', authenticationErrorHandler);
eventBus.removeListener('wallet_unlock', authenticationSuccessHandler); eventBus.removeListener('wallet_unlock', authenticationSuccessHandler);
res.send({ res.send({
......
...@@ -772,7 +772,7 @@ export const DATABASE_ENGINE = 'sqlite'; ...@@ -772,7 +772,7 @@ export const DATABASE_ENGINE = 'sqlite';
export const DATABASE_CONNECTION = {}; export const DATABASE_CONNECTION = {};
export const MILLIX_CIRCULATION = 9e15; export const MILLIX_CIRCULATION = 9e15;
export const NODE_MILLIX_BUILD_DATE = 1640009160; export const NODE_MILLIX_BUILD_DATE = 1640009160;
export const NODE_MILLIX_VERSION = '1.13.0-tangled'; export const NODE_MILLIX_VERSION = '1.13.1-tangled';
export const DATA_BASE_DIR_MAIN_NETWORK = './millix-tangled'; export const DATA_BASE_DIR_MAIN_NETWORK = './millix-tangled';
export const DATA_BASE_DIR_TEST_NETWORK = './millix-tangled'; export const DATA_BASE_DIR_TEST_NETWORK = './millix-tangled';
let DATA_BASE_DIR = MODE_TEST_NETWORK ? DATA_BASE_DIR_TEST_NETWORK : DATA_BASE_DIR_MAIN_NETWORK; let DATA_BASE_DIR = MODE_TEST_NETWORK ? DATA_BASE_DIR_TEST_NETWORK : DATA_BASE_DIR_MAIN_NETWORK;
......
...@@ -17,10 +17,11 @@ class Service { ...@@ -17,10 +17,11 @@ class Service {
} }
initialize(options = {}) { initialize(options = {}) {
const { let {
mode, mode,
initialize_wallet_event: initializeWalletEvent initialize_wallet_event: initializeWalletEvent,
} = options; auto_create_wallet : createWalletIfNotExists
} = options;
if (this.initialized) { if (this.initialized) {
return Promise.resolve(); return Promise.resolve();
} }
...@@ -28,9 +29,13 @@ class Service { ...@@ -28,9 +29,13 @@ class Service {
if (mode) { if (mode) {
this.mode = mode; this.mode = mode;
} }
if (createWalletIfNotExists === undefined) {
createWalletIfNotExists = true;
}
return logManager.initialize() return logManager.initialize()
.then(() => server.initialize()) .then(() => server.initialize())
.then(() => wallet.setMode(this.mode).initialize(initializeWalletEvent)) .then(() => wallet.setMode(this.mode).initialize(initializeWalletEvent, createWalletIfNotExists))
.then(() => cache.initialize()) .then(() => cache.initialize())
.then(() => network.initialize()) .then(() => network.initialize())
.then(() => peer.initialize()) .then(() => peer.initialize())
...@@ -41,6 +46,9 @@ class Service { ...@@ -41,6 +46,9 @@ class Service {
.catch(e => { .catch(e => {
console.log(`[services] ${e.message}`); console.log(`[services] ${e.message}`);
this.initialized = false; this.initialized = false;
if (e.cause === 'wallet_not_found') {
return;
}
return this.initialize(options); return this.initialize(options);
}); });
} }
......
...@@ -122,7 +122,7 @@ class Wallet { ...@@ -122,7 +122,7 @@ class Wallet {
return mnemonic.phrase; return mnemonic.phrase;
} }
getMnemonic() { getMnemonic(createIfNotExits) {
return new Promise((resolve) => { return new Promise((resolve) => {
walletUtils.loadMnemonic() walletUtils.loadMnemonic()
.then(([passphrase, isNewMnemonic]) => resolve([ .then(([passphrase, isNewMnemonic]) => resolve([
...@@ -130,11 +130,19 @@ class Wallet { ...@@ -130,11 +130,19 @@ class Wallet {
isNewMnemonic isNewMnemonic
])) ]))
.catch(() => { .catch(() => {
console.log('Creating new mnemonic'); console.log('[wallet] ' + (createIfNotExits ? 'Creating new mnemonic' : 'No wallet found in the system'));
let passphrase = this.createMnemonic(); let passphrase = undefined;
resolve([ if (createIfNotExits) {
passphrase = this.createMnemonic();
console.log('[wallet] creating a new mnemonic. please backup these 24 words to be able to recover you wallet.');
console.log('[wallet] mnemonic phrase => ', passphrase);
}
resolve(createIfNotExits ? [
passphrase, passphrase,
true true
] : [
undefined,
false
]); ]);
}); });
}); });
...@@ -864,7 +872,7 @@ class Wallet { ...@@ -864,7 +872,7 @@ class Wallet {
delete this._transactionReceivedFromNetwork[transaction.transaction_id]; delete this._transactionReceivedFromNetwork[transaction.transaction_id];
delete this._transactionRequested[transaction.transaction_id]; delete this._transactionRequested[transaction.transaction_id];
const cachedValidation = cache.getCacheItem('validation', transaction.transaction_id); const cachedValidation = cache.getCacheItem('validation', transaction.transaction_id);
if(cachedValidation && cachedValidation.cause === 'transaction_not_found') { if (cachedValidation && cachedValidation.cause === 'transaction_not_found') {
cache.removeCacheItem('validation', transaction.transaction_id); cache.removeCacheItem('validation', transaction.transaction_id);
} }
}); });
...@@ -1716,26 +1724,43 @@ class Wallet { ...@@ -1716,26 +1724,43 @@ class Wallet {
}); });
} }
initialize(initializeEventsOnly) { initialize(initializeEventsOnly, createWalletIfNotExists) {
if (!initializeEventsOnly) { if (!initializeEventsOnly) {
return this.getMnemonic() return this.getMnemonic(createWalletIfNotExists)
.then(([mnemonicPhrase, isNewMnemonic]) => .then(([mnemonicPhrase, isNewMnemonic]) => {
this.getWalletPrivateKey(mnemonicPhrase, isNewMnemonic).then(xPrivkey => [
if (mnemonicPhrase === undefined) { // not wallet found
return Promise.resolve(null);
}
return this.getWalletPrivateKey(mnemonicPhrase, isNewMnemonic).then(xPrivkey => [
xPrivkey, xPrivkey,
isNewMnemonic isNewMnemonic
]) ])
.then(([xPrivkey, isNewMnemonic]) => this.isCreateWallet(xPrivkey, isNewMnemonic)) .then(([xPrivkey, isNewMnemonic]) => this.isCreateWallet(xPrivkey, isNewMnemonic))
.then(([xPrivkey, isCreated]) => this.activateWalletByMasterKey(xPrivkey, isCreated)) .then(([xPrivkey, isCreated]) => this.activateWalletByMasterKey(xPrivkey, isCreated))
.then((walletID) => { .then((walletID) => {
if (isNewMnemonic) { if (isNewMnemonic) {
return walletUtils.storeMnemonic(mnemonicPhrase).then(() => walletID); return walletUtils.storeMnemonic(mnemonicPhrase).then(() => walletID);
} }
else { else {
return Promise.resolve(walletID); return Promise.resolve(walletID);
} }
}) });
) })
.then(walletID => { .then(walletID => {
if (!walletID) { // not wallet found
return new Promise((_, reject) => {
console.log('[wallet] waiting for a new wallet to be created...');
const error = {
cause : 'wallet_not_found',
message: 'there is no wallet configured'
};
eventBus.emit('wallet_authentication_error', error);
reject(error);
});
}
this._initializeEvents(); this._initializeEvents();
return database.getRepository('keychain').getWalletDefaultKeyIdentifier(walletID) return database.getRepository('keychain').getWalletDefaultKeyIdentifier(walletID)
.then(defaultKeyIdentifier => { .then(defaultKeyIdentifier => {
...@@ -1754,6 +1779,9 @@ class Wallet { ...@@ -1754,6 +1779,9 @@ class Wallet {
}); });
}) })
.catch((err) => { .catch((err) => {
if (err && err.cause === 'wallet_not_found') {
return Promise.reject(err);
}
throw Error(`Could not initialize wallet ${err}`); throw Error(`Could not initialize wallet ${err}`);
}); });
} }
......
...@@ -106,7 +106,7 @@ eventBus.on('wallet_unlock', () => { ...@@ -106,7 +106,7 @@ eventBus.on('wallet_unlock', () => {
db.initialize() db.initialize()
.then(() => configLoader.cleanConfigsFromDatabase()) .then(() => configLoader.cleanConfigsFromDatabase())
.then(() => configLoader.load(false)) .then(() => configLoader.load(false))
.then(() => services.initialize()) .then(() => services.initialize({auto_create_wallet: false}))
.then(() => { .then(() => {
logManager.logSize = 1000; logManager.logSize = 1000;
if (config.MODE_TEST) { if (config.MODE_TEST) {
...@@ -126,6 +126,6 @@ db.initialize() ...@@ -126,6 +126,6 @@ db.initialize()
}); });
} }
}); });
//millix v1.13.0-tangled //millix v1.13.1-tangled
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment