How to use newDocument method in wpt

Best JavaScript code snippet using wpt

observeWallets.js

Source:observeWallets.js Github

copy

Full Screen

1/**2Created radom 32 byte string3@method random32Bytes4*/5var random32Bytes = function() {6 function s4() {7 return Math.floor((1 + Math.random()) * 0x10000)8 .toString(16)9 .substring(1);10 }11 return s4() + s4() + s4() + s4() +12 s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4() +13 s4() + s4() + s4() + s4();14};15/**16Update the contract data, like dailyLimit and required signatures.17@method updateContractData18*/19updateContractData = function(newDocument){20 var contractInstance = contracts['ct_'+ newDocument._id];21 if(!contractInstance)22 return;23 contractInstance.m_dailyLimit(function(e, result){24 if(!e)25 Wallets.update(newDocument._id, {$set: {26 dailyLimit: result.toString(10)27 }});28 });29 contractInstance.m_required(function(e, result){30 if(!e)31 Wallets.update(newDocument._id, {$set: {32 requiredSignatures: result.toString(10)33 }});34 });35 // UPDATE THE DAILYLIMITSPENT36 if(newDocument.version >= 1) {37 contractInstance.m_spentToday(function(e, spent) {38 contractInstance.m_lastDay(function(e, lastDay) {39 if(!e && spent && _.isFinite(spent.toString(10))) {40 var now = new Date();41 var fullDaysSinceEpoch = Math.floor(now/8.64e7);42 // update the daily limit, when its still the same day43 Wallets.update(newDocument._id, {$set: {44 dailyLimitSpent: (fullDaysSinceEpoch === lastDay.toNumber()) ? spent.toString(10) : '0'45 }});46 }47 });48 });49 }50 // check for version51 if(_.isUndefined(newDocument.version) && newDocument.address) {52 contractInstance.version(function(e, version){53 if(!e && version.toString(10)) {54 // var sha3 = web3.sha3(code, true);55 // // find version56 // index = 0;57 // _.find(contractVersions, function(contract, i){58 // if(contract.original === sha3 || contract.stub === sha3) {59 // index = i;60 // return true;61 // } else62 // return false;63 // });64 Wallets.update(newDocument._id, {$set: {65 version: version.toNumber()66 }});67 newDocument.version = version.toNumber();68 }69 });70 }71};72/**73Update the pending confirmations with either adding or removing the owner.74It will check first if the incoming log is newer than the already stored data.75@method confirmOrRevoke76@param {Object} log77*/78confirmOrRevoke = function(contract, log){79 var confirmationId = Helpers.makeId('pc', log.args.operation);80 if(!confirmationId)81 return;82 contract.hasConfirmed(log.args.operation, log.args.owner, function(e, res){83 var pendingConf = PendingConfirmations.findOne(confirmationId),84 setDocument = {$set:{85 from: log.address86 }};87 // remove the sending property88 if(pendingConf && pendingConf.sending === log.args.owner)89 setDocument['$unset'] = {sending: ''};90 Helpers.eventLogs('CHECK OPERATION: '+ log.args.operation +' owner: '+ log.args.owner, res);91 if(res){92 if(pendingConf)93 setDocument['$addToSet'] = {confirmedOwners: log.args.owner};94 else95 setDocument['$set'].confirmedOwners = [log.args.owner];96 } else {97 if(pendingConf)98 setDocument['$pull'] = {confirmedOwners: log.args.owner};99 else100 setDocument['$set'].confirmedOwners = [];101 }102 PendingConfirmations.upsert(confirmationId, setDocument);103 });104};105/**106Creates filters for a wallet contract, to watch for deposits, pending confirmations, or contract creation events.107@method setupContractFilters108@param {Object} newDocument109@param {Boolean} checkFromCreationBlock110*/111var setupContractFilters = function(newDocument, checkFromCreationBlock){112 var blockToCheckBack = (newDocument.checkpointBlock || 0) - ethereumConfig.rollBackBy;113 114 if(checkFromCreationBlock || blockToCheckBack < 0)115 blockToCheckBack = newDocument.creationBlock;116 var contractInstance = contracts['ct_'+ newDocument._id];117 if(!contractInstance)118 return;119 if(!contractInstance.walletEvents)120 contractInstance.walletEvents = [];121 var events = contractInstance.walletEvents;122 // stop all running events123 _.each(contractInstance.walletEvents, function(event){124 event.stopWatching();125 contractInstance.walletEvents.shift();126 });127 // WATCH for the created event, to get the creation block128 if(newDocument.imported) {129 Helpers.eventLogs('Imported wallet: '+ newDocument.address +' checking for any log from block #'+ newDocument.creationBlock);130 web3.eth.filter({address: newDocument.address, fromBlock: newDocument.creationBlock, toBlock: 'latest'}).get(function(error, logs) {131 if(!error) {132 var creationBlock = EthBlocks.latest.number;133 // get earliest block number of appeared log134 if(logs.length !== 0) {135 logs.forEach(function(log){136 if(log.blockNumber < creationBlock)137 creationBlock = log.blockNumber;138 });139 }140 // add the address state141 Wallets.update(newDocument._id, {$unset: {142 imported: '',143 }, $set: {144 creationBlock: creationBlock - 100145 }});146 newDocument = Wallets.findOne(newDocument._id);147 // update dailyLimit and requiredSignatures148 updateContractData(newDocument);149 // add contract filters150 setupContractFilters(newDocument, true);151 }152 });153 // CHECK if for the contract address154 } else if(!newDocument.address) {155 Helpers.eventLogs('Contract address not set, checking for contract receipt');156 web3.eth.getTransactionReceipt(newDocument.transactionHash, function(error, receipt) {157 if(!error && receipt) {158 web3.eth.getCode(receipt.contractAddress, function(error, code) {159 Helpers.eventLogs('Contract created on '+ receipt.contractAddress);160 if(!error && code.length > 2) {161 // add the address state162 Wallets.update(newDocument._id, {$set: {163 creationBlock: receipt.blockNumber,164 address: receipt.contractAddress165 }});166 newDocument = Wallets.findOne(newDocument._id);167 // set address to the contract instance168 contracts['ct_'+ newDocument._id] = WalletContract.at(receipt.contractAddress);169 // add contract filters170 setupContractFilters(newDocument);171 } else {172 Helpers.eventLogs('Contract created on '+ receipt.contractAddress + ', but didn\'t stored the code!');173 // remove account, if something failed174 Wallets.remove(newDocument._id);175 }176 });177 }178 });179 // ADD FILTERS180 } else {181 // SETUP FILTERS182 Helpers.eventLogs('Checking Deposits and ConfirmationNeeded for '+ contractInstance.address +' (_id: '+ newDocument._id +') from block #', blockToCheckBack);183 // delete the last tx and pc until block -500184 _.each(Transactions.find({_id: {$in: newDocument.transactions || []}, blockNumber: {$exists: true, $gt: blockToCheckBack}}).fetch(), function(tx){185 if(tx)186 Transactions.remove({_id: tx._id});187 });188 _.each(PendingConfirmations.find({from: newDocument.address, blockNumber: {$exists: true, $gt: blockToCheckBack}}).fetch(), function(pc){189 if(pc)190 PendingConfirmations.remove({_id: pc._id});191 });192 var filter = contractInstance.allEvents({fromBlock: blockToCheckBack, toBlock: 'latest'});193 events.push(filter);194 195 // get past logs, to set the new blockNumber196 var currentBlock = EthBlocks.latest.number;197 filter.get(function(error, logs) {198 if(!error) {199 // update last checkpoint block200 Wallets.update({_id: newDocument._id}, {$set: {201 checkpointBlock: (currentBlock || EthBlocks.latest.number) - ethereumConfig.rollBackBy202 }});203 }204 });205 filter.watch(function(error, log){206 if(!error) {207 Helpers.eventLogs(log);208 if(EthBlocks.latest.number && log.blockNumber > EthBlocks.latest.number) {209 // update last checkpoint block210 Wallets.update({_id: newDocument._id}, {$set: {211 checkpointBlock: log.blockNumber212 }});213 }214 if(log.event === 'Deposit') {215 Helpers.eventLogs('Deposit for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args.value.toNumber());216 var txExists = addTransaction(log, log.args.from, newDocument.address, log.args.value.toString(10));217 // NOTIFICATION218 if(!txExists || !txExists.tokenId) {219 var txId = Helpers.makeId('tx', log.transactionHash);220 Helpers.showNotification('wallet.transactions.notifications.incomingTransaction', {221 to: Helpers.getAccountNameByAddress(newDocument.address),222 from: Helpers.getAccountNameByAddress(log.args.from),223 amount: EthTools.formatBalance(log.args.value, '0,0.00[000000] unit', 'ether')224 }, function() {225 // on click show tx info226 EthElements.Modal.show({227 template: 'views_modals_transactionInfo',228 data: {229 _id: txId230 }231 },{232 class: 'transaction-info'233 });234 });235 }236 }237 if(log.event === 'SingleTransact' || log.event === 'MultiTransact') {238 Helpers.eventLogs(log.event +' for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args.value.toNumber());239 var txExists = addTransaction(log, newDocument.address, log.args.to, log.args.value.toString(10));240 // NOTIFICATION241 if(!txExists || !txExists.tokenId) {242 var txId = Helpers.makeId('tx', log.transactionHash);243 Helpers.showNotification('wallet.transactions.notifications.outgoingTransaction', {244 to: Helpers.getAccountNameByAddress(log.args.to),245 from: Helpers.getAccountNameByAddress(newDocument.address),246 amount: EthTools.formatBalance(log.args.value, '0,0.00[000000] unit', 'ether')247 }, function() {248 // on click show tx info249 EthElements.Modal.show({250 template: 'views_modals_transactionInfo',251 data: {252 _id: txId253 }254 },{255 class: 'transaction-info'256 });257 });258 }259 }260 if(log.event === 'ConfirmationNeeded') {261 Helpers.eventLogs('ConfirmationNeeded for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args.value.toNumber() +', Operation '+ log.args.operation);262 var block = web3.eth.getBlock(log.blockNumber, true, function(err, block){263 if(!err && block) {264 var confirmationId = Helpers.makeId('pc', log.args.operation),265 accounts = Wallets.find({$or: [{address: log.address}, {address: log.args.to}]}).fetch(),266 pendingConf = PendingConfirmations.findOne(confirmationId),267 depositTx;268 // PREVENT SHOWING pending confirmations, of WATCH ONLY WALLETS269 if(!(from = Wallets.findOne({address: log.address})) || !EthAccounts.findOne({address: {$in: from.owners}}))270 return;271 if(accounts[0] && accounts[0].transactions) {272 var txs = _.flatten(_.pluck(accounts, 'transactions'));273 depositTx = Transactions.findOne({_id: {$in: txs || []}, operation: log.args.operation});274 }275 // add pending confirmation,276 // if not already present, OR transaction already went through277 if(depositTx) {278 PendingConfirmations.remove(confirmationId);279 280 } else {281 PendingConfirmations.upsert(confirmationId, {$set: {282 confirmedOwners: pendingConf ? pendingConf.confirmedOwners : [],283 initiator: log.args.initiator,284 operation: log.args.operation,285 value: log.args.value.toString(10),286 to: log.args.to,287 from: newDocument.address,288 timestamp: block.timestamp,289 blockNumber: log.blockNumber,290 blockHash: log.blockHash,291 transactionHash: log.transactionHash,292 transactionIndex: log.transactionIndex,293 }});294 // TODO: add back? done for the confirmation log already295 // delay a little to prevent race conditions296 // Tracker.afterFlush(function() {297 // confirmOrRevoke(contractInstance, log);298 // });299 // NOTIFICATION300 if(pendingConf && !pendingConf.operation) {301 Helpers.showNotification('wallet.transactions.notifications.pendingConfirmation', {302 initiator: Helpers.getAccountNameByAddress(log.args.initiator),303 to: Helpers.getAccountNameByAddress(log.args.to),304 from: Helpers.getAccountNameByAddress(newDocument.address),305 amount: EthTools.formatBalance(log.args.value, '0,0.00[000000] unit', 'ether')306 }, function() {307 FlowRouter.go('/account/'+ newDocument.address);308 });309 }310 // remove pending transactions, as they now have to be approved311 var extistingTxId = Helpers.makeId('tx', log.transactionHash);312 Meteor.setTimeout(function() {313 Transactions.remove(extistingTxId);314 }, 500);315 }316 }317 318 });319 }320 if(log.event === 'OwnerAdded') {321 Helpers.eventLogs('OwnerAdded for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args);322 // re-add owner from log323 Wallets.update(newDocument._id, {$addToSet: {324 owners: log.args.newOwner325 }});326 }327 if(log.event === 'OwnerRemoved') {328 Helpers.eventLogs('OwnerRemoved for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args);329 // re-add owner from log330 Wallets.update(newDocument._id, {$pull: {331 owners: log.args.oldOwner332 }});333 }334 if(log.event === 'RequirementChanged') {335 Helpers.eventLogs('RequirementChanged for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args);336 }337 if(log.event === 'Confirmation') {338 Helpers.eventLogs('Operation confirmation for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args);339 // delay a little to prevent race conditions340 confirmOrRevoke(contractInstance, log);341 }342 if(log.event === 'Revoke') {343 Helpers.eventLogs('Operation revokation for '+ newDocument.address +' arrived in block: #'+ log.blockNumber, log.args);344 // delay a little to prevent race conditions345 confirmOrRevoke(contractInstance, log);346 }347 } else {348 console.error('Logs of Wallet '+ newDocument.name + ' couldn\'t be received', error);349 }350 });351 }352};353/**354Observe accounts and setup filters355@method observeWallets356*/357observeWallets = function(){358 /**359 Checking for confirmations of created wallets.360 Will only check if the old document, has no address and its inside the confirmations still.361 @method checkWalletConfirmations362 @param {Object} newDocument363 @param {Object} oldDocument364 */365 var checkWalletConfirmations = function(newDocument, oldDocument){366 var confirmations = EthBlocks.latest.number - newDocument.creationBlock;367 if(newDocument.address && (!oldDocument || (oldDocument && !oldDocument.address)) && confirmations < ethereumConfig.requiredConfirmations) {368 var filter = web3.eth.filter('latest');369 filter.watch(function(e, blockHash){370 if(!e) {371 var confirmations = EthBlocks.latest.number - newDocument.creationBlock;372 if(confirmations < ethereumConfig.requiredConfirmations && confirmations > 0) {373 Helpers.eventLogs('Checking wallet address '+ newDocument.address +' for code. Current confirmations: '+ confirmations);374 // TODO make smarter?375 // Check if the code is still at the contract address, if not remove the wallet376 web3.eth.getCode(newDocument.address, function(e, code){377 if(!e) {378 if(code.length > 2) {379 updateContractData(newDocument); 380 // check for wallet data381 } else {382 Wallets.remove(newDocument._id);383 filter.stopWatching();384 }385 }386 });387 } else if(confirmations > ethereumConfig.requiredConfirmations) {388 filter.stopWatching();389 }390 }391 });392 }393 };394 /**395 Observe Wallets, listen for new created accounts.396 @class Wallets.find({}).observe397 @constructor398 */399 collectionObservers[collectionObservers.length] = Wallets.find({}).observe({400 /**401 This will observe the account creation, to send the contract creation transaction.402 @method added403 */404 added: function(newDocument) {405 // DEPLOYED NEW CONTRACT406 if(!newDocument.address) {407 // tx hash already exisits, so just get the receipt and don't re-deploy408 if(newDocument.transactionHash) {409 contracts['ct_'+ newDocument._id] = WalletContract.at();410 // remove account, if something is searching since more than 30 blocks411 if(newDocument.creationBlock + 50 <= EthBlocks.latest.number)412 Wallets.remove(newDocument._id);413 else414 setupContractFilters(newDocument);415 return;416 }417 if(_.isEmpty(newDocument.owners))418 return;419 // SAFETY420 // 1. check if stub code has a proper address421 if(newDocument.code.indexOf('cafecafecafecafecafecafecafecafecafecafe') !== -1) {422 GlobalNotification.error({423 content: TAPi18n.__('wallet.newWallet.error.stubHasNoOrigWalletAddress'),424 closeable: false425 });426 Wallets.remove(newDocument._id);427 return;428 }429 // 2. check if we ares still on the right chain, before creating a wallet430 Helpers.checkChain(function(e) {431 if(e) {432 Wallets.remove(newDocument._id);433 GlobalNotification.error({434 content: TAPi18n.__('wallet.app.error.wrongChain'),435 closeable: false436 });437 } else {438 console.log('Deploying Wallet with following options', newDocument);439 WalletContract.new(newDocument.owners, newDocument.requiredSignatures, (newDocument.dailyLimit || ethereumConfig.dailyLimitDefault), {440 from: newDocument.owners[0],441 data: newDocument.code,442 gas: 3000000,443 }, function(error, contract){444 if(!error) {445 // TX HASH arrived446 if(!contract.address) {447 // add transactionHash to account448 newDocument.transactionHash = contract.transactionHash;449 console.log('Contract transaction hash: ', contract.transactionHash);450 Wallets.update(newDocument._id, {$set: {451 transactionHash: contract.transactionHash452 }});453 // CONTRACT DEPLOYED454 } else {455 console.log('Contract Address: ', contract.address);456 contracts['ct_'+ newDocument._id] = contract;457 // add address to account458 Wallets.update(newDocument._id, {$set: {459 creationBlock: EthBlocks.latest.number - 1,460 checkpointBlock: EthBlocks.latest.number - 1,461 address: contract.address462 }, $unset: {463 code: ''464 }});465 newDocument.address = contract.address;466 delete newDocument.code;467 updateContractData(newDocument);468 setupContractFilters(newDocument);469 // Show backup note470 EthElements.Modal.question({471 template: 'views_modals_backupContractAddress',472 data: {473 address: contract.address474 },475 ok: true476 },{477 closeable: false478 });479 }480 481 } else {482 console.log('Error while deploying wallet', error);483 484 GlobalNotification.error({485 content: error.message,486 duration: 8487 });488 // remove account, if something failed489 Wallets.remove(newDocument._id);490 }491 });492 }493 });494 // USE DEPLOYED CONTRACT495 } else {496 contracts['ct_'+ newDocument._id] = WalletContract.at(newDocument.address);497 // update balance on start498 web3.eth.getBalance(newDocument.address, function(err, res){499 if(!err) {500 Wallets.update(newDocument._id, {$set: {501 balance: res.toString(10)502 }});503 }504 });505 // check if wallet has code506 web3.eth.getCode(newDocument.address, function(e, code) {507 if(!e) {508 if(code && code.length > 2){509 Wallets.update(newDocument._id, {$unset: {510 disabled: ''511 }});512 // init wallet events, only if existing wallet513 updateContractData(newDocument);514 setupContractFilters(newDocument);515 checkWalletConfirmations(newDocument, {});516 } else {517 Wallets.update(newDocument._id, {$set: {518 disabled: true519 }});520 }521 } else {522 console.log('Couldn\'t check Wallet code of ', newDocument, e);523 }524 });525 }526 },527 /**528 Will check if the contract is still there and update the today spend if a new tx is added529 @method changed530 */531 changed: function(newDocument, oldDocument){532 // checkWalletConfirmations(newDocument, oldDocument);533 updateContractData(newDocument);534 },535 /**536 Stop filters, when accounts are removed537 @method removed538 */539 removed: function(newDocument){540 var contractInstance = contracts['ct_'+ newDocument._id];541 if(!contractInstance)542 return;543 if(!contractInstance.walletEvents)544 contractInstance.walletEvents = [];545 // stop all running events546 _.each(contractInstance.walletEvents, function(event){547 event.stopWatching();548 contractInstance.walletEvents.shift();549 });550 delete contracts['ct_'+ newDocument._id];551 // delete the all tx and pending conf552 _.each(Transactions.find({from: newDocument.address}).fetch(), function(tx){553 if(!Wallets.findOne({transactions: tx._id}) && !EthAccounts.findOne({transactions: tx._id}))554 Transactions.remove(tx._id);555 });556 _.each(PendingConfirmations.find({from: newDocument.address}).fetch(), function(pc){557 PendingConfirmations.remove(pc._id);558 });559 }560 });...

Full Screen

Full Screen

observeSubChains.js

Source:observeSubChains.js Github

copy

Full Screen

1import '../collections.js';2import './walletConnector.js';3/**4Update the owner list5@method checkOwner6*/7checkOwner = function(newDocument){8 // check if the owners have changed9 //if(chain3.isAddress(newDocument.address)) {10 chain3.scs.getMicroChainInfo(newDocument.subChainAddress).then(function(subChainInfo){11 SubChains.update(newDocument._id, {$set: {owners: subChainInfo.owner}});12 },function(err){13 console.log('subChainOwner err:'+err);14 });15 //}16};17/**18Observe SubChains and setup filters19@method observeSubChains20*/21observeSubChains = function(){22 /**23 Checking for confirmations of created subChains.24 Will only check if the old document, has no address and its inside the confirmations still.25 @method checkSubChainConfirmations26 @param {Object} newDocument27 @param {Object} oldDocument28 */29 var checkSubChainConfirmations = function(newDocument, oldDocument){30 var confirmations = McBlocks.latest.number - newDocument.creationBlock;31 if(newDocument.address && (!oldDocument || (oldDocument && !oldDocument.address)) && confirmations < moacConfig.requiredConfirmations) {32 var filter = chain3.mc.filter('latest');33 filter.watch(function(e, blockHash){34 if(!e) {35 var confirmations = McBlocks.latest.number - newDocument.creationBlock;36 if(confirmations < moacConfig.requiredConfirmations && confirmations > 0) {37 Helpers.eventLogs('Checking subChain address '+ newDocument.address +' for code. Current confirmations: '+ confirmations);38 // TODO make smarter?39 // Check if the code is still at the contract address, if not remove the subChain40 chain3.mc.getCode(newDocument.address, function(e, code){41 if(!e) {42 if(code.length > 2) {43 updateContractData(newDocument); 44 // check for subChain data45 } else {46 SubChains.remove(newDocument._id);47 filter.stopWatching();48 }49 }50 });51 } else if(confirmations > moacConfig.requiredConfirmations) {52 filter.stopWatching();53 }54 }55 });56 }57 };58 /**59 Observe SubChains, listen for new created accounts.60 @class SubChains.find({}).observe61 @constructor62 */63 collectionObservers[collectionObservers.length] = SubChains.find({}).observe({64 /**65 This will observe the account creation, to send the contract creation transaction.66 @method added67 */68 added: function(newDocument) {69 70 scsApi2.init(newDocument.monitorAddr, newDocument.monitorPort);71 //chain3.scs.getBlockNumber( newDocument.address, function(e,blockNumber){72 //if( !e ){73 //var block = ScsBlocks.findOne({address:newDocument.address}).fetch()74 var scsBlock = {75 address: newDocument.address,76 currentBlockNumber: 077 }78 ScsBlocks.insert( scsBlock );79 SubChains.update( newDocument._id, {$set:{ currentBlockNumber: 0,80 ownerBalance: 0}});81 //}82 //});83 /*chain3.scs.getBlockNumber(newDocument.address,function(e, res){84 if( !e && !(res===newDocument.currentBlockNumber )) {85 //console.log('observe scs blocks3');86 SubChains.update( newDocument._id, {$set:{ currentBlockNumber: res}});87 chain3.scs.getBalance(newDocument.address, subChain.owner.address,function(err,balance){88 //console.log('observe scs blocks5');89 //console.log('observe scs balance:'+balance);90 if(! err)91 SubChains.update( newDocument._id, {$set:{ ownerBalance: balance}});92 else93 console.log(err);94 });95 }96 });*/97 },98/*99 // DEPLOYED NEW CONTRACT100 if(!newDocument.address) {101 // tx hash already exisits, so just get the receipt and don't re-deploy102 if(newDocument.transactionHash) {103 contracts['ct_'+ newDocument._id] = SubChainContract.at();104 // remove account, if something is searching since more than 30 blocks105 if(newDocument.creationBlock + 50 <= McBlocks.latest.number)106 SubChains.remove(newDocument._id);107 else108 setupContractFilters(newDocument);109 return;110 }111 if(_.isEmpty(newDocument.owners))112 return;113 // SAFETY114 // 1. check if stub code has a proper address115 if(newDocument.code.indexOf('cafecafecafecafecafecafecafecafecafecafe') !== -1) {116 GlobalNotification.error({117 content: TAPi18n.__('subChain.newSubChain.error.stubHasNoOrigSubChainAddress'),118 closeable: false119 });120 SubChains.remove(newDocument._id);121 return;122 }123 // 2. check if we ares still on the right chain, before creating a subChain124 Helpers.checkChain(function(e) {125 if(e) {126 SubChains.remove(newDocument._id);127 GlobalNotification.error({128 content: TAPi18n.__('subChain.app.error.wrongChain'),129 closeable: false130 });131 } else {132 console.log('Deploying SubChain with following options', newDocument);133 SubChainContract.new(newDocument.owners, newDocument.requiredSignatures, (newDocument.dailyLimit || moacConfig.dailyLimitDefault), {134 from: newDocument.deployFrom,135 data: newDocument.code,136 gas: 3000000,137 }, function(error, contract){138 if(!error) {139 // TX HASH arrived140 if(!contract.address) {141 // add transactionHash to account142 newDocument.transactionHash = contract.transactionHash;143 console.log('Contract transaction hash: ', contract.transactionHash);144 SubChains.update(newDocument._id, {$set: {145 transactionHash: contract.transactionHash146 }});147 // CONTRACT DEPLOYED148 } else {149 console.log('Contract Address: ', contract.address);150 contracts['ct_'+ newDocument._id] = contract;151 // add address to account152 SubChains.update(newDocument._id, {$set: {153 creationBlock: McBlocks.latest.number - 1,154 checkpointBlock: McBlocks.latest.number - 1,155 address: contract.address156 }, $unset: {157 code: ''158 }});159 newDocument.address = contract.address;160 delete newDocument.code;161 updateContractData(newDocument);162 setupContractFilters(newDocument);163 // Show backup note164 McElements.Modal.question({165 template: 'views_modals_backupContractAddress',166 data: {167 address: contract.address168 },169 ok: true170 },{171 closeable: false172 });173 }174 175 } else {176 console.log('Error while deploying subChain', error);177 178 GlobalNotification.error({179 content: error.message,180 duration: 8181 });182 // remove account, if something failed183 SubChains.remove(newDocument._id);184 }185 });186 }187 });188 // USE DEPLOYED CONTRACT189 } else {190 contracts['ct_'+ newDocument._id] = SubChainContract.at(newDocument.address);191 // update balance on start192 chain3.mc.getBalance(newDocument.address, function(err, res){193 if(!err) {194 SubChains.update(newDocument._id, {$set: {195 balance: res.toString(10)196 }});197 }198 });199 // check if subChain has code200 chain3.mc.getCode(newDocument.address, function(e, code) {201 if(!e) {202 if(code && code.length > 2){203 SubChains.update(newDocument._id, {$unset: {204 disabled: ''205 }});206 // init subChain events, only if existing subChain207 updateContractData(newDocument);208 setupContractFilters(newDocument);209 checkSubChainConfirmations(newDocument, {});210 } else {211 SubChains.update(newDocument._id, {$set: {212 disabled: true213 }});214 }215 } else {216 console.log('Couldn\'t check SubChain code of ', newDocument, e);217 }218 });219 // check for vulnerability220 checkForVulnerableSubChain(newDocument);221 }*/222 //},223 /**224 Will check if the contract is still there and update the today spend if a new tx is added225 @method changed226 */227 changed: function(newDocument, oldDocument){228 // checkSubChainConfirmations(newDocument, oldDocument);229 //if(newDocument.transactions != oldDocument.transactions)230 // updateContractData(newDocument);231 },232 /**233 Stop filters, when accounts are removed234 @method removed235 */236 removed: function(newDocument){237 /* var contractInstance = contracts['ct_'+ newDocument._id];238 if(!contractInstance)239 return;240 if(!contractInstance.subChainEvents)241 contractInstance.subChainEvents = [];242 // stop all running events243 _.each(contractInstance.subChainEvents, function(event){244 event.stopWatching();245 contractInstance.subChainEvents.shift();246 });247 delete contracts['ct_'+ newDocument._id];248 // delete the all tx and pending conf249 _.each(Transactions.find({from: newDocument.address}).fetch(), function(tx){250 if(!SubChains.findOne({transactions: tx._id}) && !McAccounts.findOne({transactions: tx._id}))251 Transactions.remove(tx._id);252 });253 _.each(PendingConfirmations.find({from: newDocument.address}).fetch(), function(pc){254 PendingConfirmations.remove(pc._id);255 });*/256 }257 });...

Full Screen

Full Screen

initializeDocument.js

Source:initializeDocument.js Github

copy

Full Screen

1const initializeDocument = (document) => {2 const newDocument = {...document}3 switch (document.type) {4 case "dayOffDocument" : 5 newDocument.accepter_1_email = "sergeybuniatyan@dflow.com"6 newDocument.accepter_2_email = "merisaryan@dflow.com"7 newDocument.accepter_3_email = "manaelinyan@dflow.com"8 newDocument.accepter_1_position = "Թիմի ղեկավար"9 newDocument.accepter_2_position = "Ծրագրի ղեկավար"10 newDocument.accepter_3_position = "Մարդկային ռեսուրսների ղեկավար"11 newDocument.accepter_1_seen = false12 newDocument.accepter_2_seen = false13 newDocument.accepter_3_seen = false14 newDocument.accepter_1_answer = false15 newDocument.accepter_2_answer = false16 newDocument.accepter_3_answer = false17 newDocument.denied = false18 newDocument.accepted = false19 newDocument.seenStep = 120 newDocument.accepters = 321 return newDocument22 case "VacantionDocument" :23 newDocument.accepter_1_email = "sergeybuniatyan@dflow.com"24 newDocument.accepter_2_email = "merisaryan@dflow.com"25 newDocument.accepter_3_email = "manaelinyan@dflow.com"26 newDocument.accepter_4_email = "annanahapetyan@dflow.com"27 newDocument.accepter_1_position = "Թիմի ղեկավար"28 newDocument.accepter_2_position = "Ծրագրի ղեկավար"29 newDocument.accepter_3_position = "Մարդկային ռեսուրսների ղեկավար"30 newDocument.accepter_4_position = "Հաշվապահ"31 newDocument.accepter_1_seen = false32 newDocument.accepter_2_seen = false33 newDocument.accepter_3_seen = false34 newDocument.accepter_4_seen = false35 newDocument.accepter_1_answer = false36 newDocument.accepter_2_answer = false37 newDocument.accepter_3_answer = false38 newDocument.accepter_4_answer = false39 newDocument.denied = false40 newDocument.accepted = false41 newDocument.seenStep = 142 newDocument.accepters = 443 return newDocument44 }45}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var request = require('request');5request(url, function (error, response, body) {6 if (!error && response.statusCode == 200) {7 var data = JSON.parse(body);8 var pageId = Object.keys(data.query.pages)[0];9 var page = data.query.pages[pageId];10 var url = page.thumbnail.source;11 var file = fs.createWriteStream(path.join(__dirname, 'test.png'));12 var request = http.get(url, function(response) {13 response.pipe(file);14 });15 }16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var _ = require('lodash');4var csv = require('csv');5var async = require('async');6var request = require('request');7var cheerio = require('cheerio');8var mongoose = require('mongoose');9var config = require('./config');10var utils = require('./utils');11var Article = require('./models/article');12var ArticleData = require('./models/articleData');13var db = mongoose.connect(config.db);14var data = fs.readFileSync('data.csv', 'utf8');15var articleData = [];16var articles = [];17var articlesData = [];18var articlesDataProcessed = [];19var articlesDataProcessedByArticle = [];20var articlesDataProcessedByArticleData = [];21var articlesDataProcessedByArticleDataWithImages = [];22var articlesDataProcessedByArticleDataWithImagesAndText = [];23var articlesDataProcessedByArticleDataWithImagesAndTextAndCategories = [];24var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfobox = [];25var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferences = [];26var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferencesAndLinks = [];27var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferencesAndLinksAndCoordinates = [];28var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferencesAndLinksAndCoordinatesAndWikipediaData = [];29var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferencesAndLinksAndCoordinatesAndWikipediaDataAndWikipediaArticle = [];30var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferencesAndLinksAndCoordinatesAndWikipediaDataAndWikipediaArticleAndWikipediaArticleData = [];31var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferencesAndLinksAndCoordinatesAndWikipediaDataAndWikipediaArticleAndWikipediaArticleDataAndWikipediaArticleDataProcessed = [];32var articlesDataProcessedByArticleDataWithImagesAndTextAndCategoriesAndInfoboxAndReferencesAndLinksAndCoordinatesAndWikipediaDataAndWikipediaArticleAndWikipediaArticleDataAndWikipediaArticleDataProcessedAndWikipediaArticleDataProcessedByArticle = [];

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.newDocument(url, function(err, data) {3 if (err) {4 console.log('error: ' + err);5 } else {6 console.log('data: ' + data);7 }8});9### newDocument(url, callback)10### runTest(testID, options, callback)11### getLocations(callback)12### getTesters(callback)13### getTestStatus(testID, callback)14### getTestResults(testID, callback)15### getTestResultsURL(testID, callback)16### getTestResultsCSV(testID, callback)17### getTestResultsHar(testID, callback)18### getTestResultsHarFile(testID, callback)19### getTestResultsPagespeed(testID, callback)20### getTestResultsPagespeedFile(testID, callback)21### getTestResultsWaterfall(testID, callback)22### getTestResultsWaterfallFile(testID, callback)23### getTestResultsVideo(testID, callback)24### getTestResultsVideoFile(testID, callback)25### getTestResultsScreenshot(testID, callback)26### getTestResultsScreenshotFile(testID, callback)27### getTestResultsStdout(testID, callback)28### getTestResultsStdoutFile(testID, callback)29Returns the results of the test in Stdout format (file

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var doc = wptools.newDocument('test');3doc.add('name', 'Test Document');4doc.add('description', 'This is a test document');5doc.add('date', new Date());6doc.add('location', 'San Francisco, CA');7doc.add('location', 'New York, NY');8doc.add('location', 'Paris, France');9doc.save(function(err) {10 if (err) {11 console.log(err);12 } else {13 console.log('Document created with id: ' + doc.id);14 }15});16var wptools = require('wptools');17var doc = wptools.updateDocument('test', 'test');18doc.add('name', 'Test Document');19doc.add('description', 'This is a test document');20doc.add('date', new Date());21doc.add('location', 'San Francisco, CA');22doc.add('location', 'New York, NY');23doc.add('location', 'Paris, France');24doc.save(function(err) {25 if (err) {26 console.log(err);27 } else {28 console.log('Document updated with id: ' + doc.id);29 }30});31var wptools = require('wptools');32wptools.deleteDocument('test', 'test', function(err) {33 if (err) {34 console.log(err);35 } else {36 console.log('Document deleted');37 }38});39var wptools = require('wptools');40wptools.getDocument('test', 'test', function(err, doc) {41 if (err) {42 console.log(err);43 } else {44 console.log('Document retrieved with id: ' + doc.id);45 console.log(doc);46 }47});48var wptools = require('wptools');49wptools.searchDocuments('test', 'Test', function(err,

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require("./wptools.js");2var newDoc = wptools.newDocument("test", "test");3newDoc.newField("test", "test");4newDoc.newField("test2", "test2");5newDoc.newField("test3", "test3");6newDoc.newField("test4", "test4");7newDoc.newField("test5", "test5");8newDoc.newField("test6", "test6");9newDoc.newField("test7", "test7");10newDoc.newField("test8", "test8");11newDoc.newField("test9", "test9");12newDoc.newField("test10", "test10");13newDoc.newField("test11", "test11");14newDoc.newField("test12", "test12");15newDoc.newField("test13", "test13");16newDoc.newField("test14", "test14");17newDoc.newField("test15", "test15");18newDoc.newField("test16", "test16");19newDoc.newField("test17", "test17");20newDoc.newField("test18", "test18");21newDoc.newField("test19", "test19");22newDoc.newField("test20", "test20");23newDoc.newField("test21", "test21");24newDoc.newField("test22", "test22");25newDoc.newField("test23", "test23");26newDoc.newField("test24", "test24");27newDoc.newField("test25", "test25");28newDoc.newField("test26", "test26");29newDoc.newField("test27", "test27");30newDoc.newField("test28", "test28");31newDoc.newField("test29", "test29");32newDoc.newField("test30", "test30");33newDoc.newField("test31", "test31");34newDoc.newField("test32", "test32");35newDoc.newField("test33", "test33");36newDoc.newField("test34", "test34");37newDoc.newField("test35", "test35");38newDoc.newField("test36",

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful