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 {
res.send({
api_status: 'success',
wallet : {
id : walletID,
address : `${keyIdentifier}${addressVersion}${keyIdentifier}`,
id : walletID,
address : `${keyIdentifier}${addressVersion}${keyIdentifier}`,
address_key_identifier: keyIdentifier
}
});
......@@ -63,7 +63,10 @@ class _PMW9LXqUv7vXLpbA extends Endpoint {
};
eventBus.once('wallet_unlock', authenticationSuccessHandler);
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_unlock', authenticationSuccessHandler);
res.send({
......
......@@ -772,7 +772,7 @@ export const DATABASE_ENGINE = 'sqlite';
export const DATABASE_CONNECTION = {};
export const MILLIX_CIRCULATION = 9e15;
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_TEST_NETWORK = './millix-tangled';
let DATA_BASE_DIR = MODE_TEST_NETWORK ? DATA_BASE_DIR_TEST_NETWORK : DATA_BASE_DIR_MAIN_NETWORK;
......
......@@ -17,10 +17,11 @@ class Service {
}
initialize(options = {}) {
const {
mode,
initialize_wallet_event: initializeWalletEvent
} = options;
let {
mode,
initialize_wallet_event: initializeWalletEvent,
auto_create_wallet : createWalletIfNotExists
} = options;
if (this.initialized) {
return Promise.resolve();
}
......@@ -28,9 +29,13 @@ class Service {
if (mode) {
this.mode = mode;
}
if (createWalletIfNotExists === undefined) {
createWalletIfNotExists = true;
}
return logManager.initialize()
.then(() => server.initialize())
.then(() => wallet.setMode(this.mode).initialize(initializeWalletEvent))
.then(() => wallet.setMode(this.mode).initialize(initializeWalletEvent, createWalletIfNotExists))
.then(() => cache.initialize())
.then(() => network.initialize())
.then(() => peer.initialize())
......@@ -41,6 +46,9 @@ class Service {
.catch(e => {
console.log(`[services] ${e.message}`);
this.initialized = false;
if (e.cause === 'wallet_not_found') {
return;
}
return this.initialize(options);
});
}
......
......@@ -122,7 +122,7 @@ class Wallet {
return mnemonic.phrase;
}
getMnemonic() {
getMnemonic(createIfNotExits) {
return new Promise((resolve) => {
walletUtils.loadMnemonic()
.then(([passphrase, isNewMnemonic]) => resolve([
......@@ -130,11 +130,19 @@ class Wallet {
isNewMnemonic
]))
.catch(() => {
console.log('Creating new mnemonic');
let passphrase = this.createMnemonic();
resolve([
console.log('[wallet] ' + (createIfNotExits ? 'Creating new mnemonic' : 'No wallet found in the system'));
let passphrase = undefined;
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,
true
] : [
undefined,
false
]);
});
});
......@@ -864,7 +872,7 @@ class Wallet {
delete this._transactionReceivedFromNetwork[transaction.transaction_id];
delete this._transactionRequested[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);
}
});
......@@ -1716,26 +1724,43 @@ class Wallet {
});
}
initialize(initializeEventsOnly) {
initialize(initializeEventsOnly, createWalletIfNotExists) {
if (!initializeEventsOnly) {
return this.getMnemonic()
.then(([mnemonicPhrase, isNewMnemonic]) =>
this.getWalletPrivateKey(mnemonicPhrase, isNewMnemonic).then(xPrivkey => [
return this.getMnemonic(createWalletIfNotExists)
.then(([mnemonicPhrase, isNewMnemonic]) => {
if (mnemonicPhrase === undefined) { // not wallet found
return Promise.resolve(null);
}
return this.getWalletPrivateKey(mnemonicPhrase, isNewMnemonic).then(xPrivkey => [
xPrivkey,
isNewMnemonic
])
.then(([xPrivkey, isNewMnemonic]) => this.isCreateWallet(xPrivkey, isNewMnemonic))
.then(([xPrivkey, isCreated]) => this.activateWalletByMasterKey(xPrivkey, isCreated))
.then((walletID) => {
if (isNewMnemonic) {
return walletUtils.storeMnemonic(mnemonicPhrase).then(() => walletID);
}
else {
return Promise.resolve(walletID);
}
})
)
.then(([xPrivkey, isNewMnemonic]) => this.isCreateWallet(xPrivkey, isNewMnemonic))
.then(([xPrivkey, isCreated]) => this.activateWalletByMasterKey(xPrivkey, isCreated))
.then((walletID) => {
if (isNewMnemonic) {
return walletUtils.storeMnemonic(mnemonicPhrase).then(() => walletID);
}
else {
return Promise.resolve(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();
return database.getRepository('keychain').getWalletDefaultKeyIdentifier(walletID)
.then(defaultKeyIdentifier => {
......@@ -1754,6 +1779,9 @@ class Wallet {
});
})
.catch((err) => {
if (err && err.cause === 'wallet_not_found') {
return Promise.reject(err);
}
throw Error(`Could not initialize wallet ${err}`);
});
}
......
......@@ -106,7 +106,7 @@ eventBus.on('wallet_unlock', () => {
db.initialize()
.then(() => configLoader.cleanConfigsFromDatabase())
.then(() => configLoader.load(false))
.then(() => services.initialize())
.then(() => services.initialize({auto_create_wallet: false}))
.then(() => {
logManager.logSize = 1000;
if (config.MODE_TEST) {
......@@ -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