Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- updateOrCreateConfig(username, password){
- const directory = process.platform === "win32" ? `${homedir}/appdata/roaming/eccoin` : `${homedir}/.eccoin`;
- const filePath = process.platform === "win32" ? `${homedir}/appdata/roaming/eccoin/eccoin.conf` : `${homedir}/.eccoin/eccoin.conf`;
- return new Promise((resolve, reject) => {
- fs.exists(filePath, (exists) => {
- if(!exists){
- //create
- const toWrite = "maxconnections=100" + os.EOL + "rpcuser=" + username + os.EOL + "rpcpassword=" + password + os.EOL + "addnode=www.cryptounited.io" + os.EOL + "rpcport=19119" + os.EOL + "rpcconnect=127.0.0.1" + os.EOL + "staking=0" + os.EOL + "zapwallettxes=0";
- fsPath.writeFile(filePath, toWrite, 'utf8', (err) => {
- if (err) {
- console.log(err)
- resolve(false);
- return;
- }
- resolve(true);
- });
- }
- else{
- fs.readFile(filePath, 'utf8', (err, data) => {
- if (err) {
- console.log("readFile error: ", err);
- resolve(false);
- return;
- }
- var patt = /(rpcuser=(.*))/g
- var myArray = patt.exec(data);
- var result = data;;
- if(myArray && myArray.length > 2)
- {
- result = result.replace('rpcuser='+myArray[2], 'rpcuser='+username);
- }
- else{
- result += `${os.EOL}rpcuser=${username}`;
- }
- patt = /(rpcpassword=(.*))/g
- myArray = patt.exec(data);
- if(myArray && myArray.length > 2)
- {
- result = result.replace('rpcpassword='+myArray[2], 'rpcpassword='+password);
- }
- else{
- result += `${os.EOL}rpcpassword=${password}`;
- }
- fs.writeFile(filePath, result, 'utf8', (err) => {
- if(!err)
- resolve(true);
- else resolve(false);
- });
- });
- }
- });
- });
- },
- readRpcCredentials(){
- const directory = process.platform === "win32" ? `${homedir}/appdata/roaming/eccoin` : `${homedir}/.eccoin`;
- const filePath = process.platform === "win32" ? `${homedir}/appdata/roaming/eccoin/eccoin.conf` : `${homedir}/.eccoin/eccoin.conf`;
- var toReturn = null;
- return new Promise((resolve, reject) => {
- fs.exists(filePath, (exists) => {
- if(!exists){
- resolve(toReturn);
- return;
- }
- fs.readFile(filePath, 'utf8', (err, data) => {
- if (err) {
- console.log("readFile error: ", err);
- resolve(toReturn);
- return;
- }
- toReturn = {
- username: "",
- password: ""
- }
- var patt = /(rpcuser=(.*))/g
- var myArray = patt.exec(data);
- if(myArray && myArray.length > 2)
- {
- toReturn.username = myArray[2];
- }
- patt = /(rpcpassword=(.*))/g
- myArray = patt.exec(data);
- if(myArray && myArray.length > 2)
- {
- toReturn.password = myArray[2];
- }
- resolve(toReturn);
- });
- })
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement