Best JavaScript code snippet using mountebank
mapping.ts
Source:mapping.ts
1import { near, log, json, JSONValueKind, BigInt } from "@graphprotocol/graph-ts";2import { Ping, Withdraw, StakeAll, Stake, DepositAndStake, WithdrawAll, Unstake, UnstakeAll, Deposit, DepositToStakingPool } from "../generated/schema";3export function handleReceipt(receipt: near.ReceiptWithOutcome): void {4 const actions = receipt.receipt.actions;5 6 for (let i = 0; i < actions.length; i++) {7 handleAction(8 actions[i], 9 receipt.receipt, 10 receipt.block.header,11 receipt.outcome,12 receipt.receipt.signerPublicKey13 );14 }15}16function handleAction(17 action: near.ActionValue,18 receipt: near.ActionReceipt,19 blockHeader: near.BlockHeader,20 outcome: near.ExecutionOutcome,21 publicKey: near.PublicKey22): void {23 24 if (action.kind != near.ActionKind.FUNCTION_CALL) {25 log.info("Early return: {}", ["Not a function call"]);26 return;27 } 28 29 const functionCall = action.toFunctionCall();30 if (functionCall.methodName == "deposit_and_stake") {31 const receiptId = receipt.id.toBase58()32 let logs = new DepositAndStake(`${receiptId}`)33 // Standard receipt properties34 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)35 logs.blockHeight = BigInt.fromU64(blockHeader.height)36 logs.blockHash = blockHeader.hash.toBase58()37 logs.predecessorId = receipt.predecessorId38 logs.receiverId = receipt.receiverId39 logs.signerId = receipt.signerId40 logs.signerPublicKey = publicKey.bytes.toBase58()41 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)42 logs.tokensBurned = outcome.tokensBurnt43 logs.outcomeId = outcome.id.toBase58()44 logs.executorId = outcome.executorId45 logs.outcomeBlockHash = outcome.blockHash.toBase58()46 // Log Parsing47 if(outcome.logs !=null && outcome.logs.length > 0){48 if(outcome.logs.length == 5){49 log.info("outcome log is: {}", [outcome.logs[0]])50 logs.log = outcome.logs[0]51 let firstLog = outcome.logs[0]52 let secondLog = outcome.logs[1]53 let thirdLog = outcome.logs[2]54 let fourthLog = outcome.logs[3]55 let fifthLog = outcome.logs[4]56 let firstParts = firstLog.split(' ')57 logs.epoch = firstParts[1].split(':')[0]58 logs.rewardsReceived = firstParts[7]59 logs.newContractStakedBalance = firstParts[14].split('.')[0]60 logs.newContractTotalShares = firstParts[19]61 let secondParts = secondLog.split(' ')62 logs.totalRewardsFee = secondParts[4]63 64 let thirdParts = thirdLog.split(' ')65 logs.accountIdDepositing = thirdParts[0].split('@')[1]66 logs.deposit = thirdParts[2]67 logs.newUnstakedBalance = thirdParts[7]68 let fourthParts = fourthLog.split(' ')69 logs.accountIdStaking = fourthParts[0].split('@')[1]70 logs.staking = fourthParts[2].split('.')[0]71 logs.receivedStakingShares = fourthParts[4]72 logs.unstakedBalance = fourthParts[9]73 logs.stakingShares = fourthParts[13]74 let fifthParts = fifthLog.split(' ')75 logs.contractTotalStakedBalance = fifthParts[5].split('.')[0]76 logs.contractTotalShares = fifthParts[10]77 logs.save()78 }79 if(outcome.logs.length == 3){80 log.info("outcome log is: {}", [outcome.logs[0]])81 let firstLog = outcome.logs[0]82 let secondLog = outcome.logs[1]83 let thirdLog = outcome.logs[2]84 85 let firstParts = firstLog.split(' ')86 logs.accountIdDepositing = firstParts[0].split('@')[1]87 logs.deposit = firstParts[2]88 logs.newUnstakedBalance = firstParts[7]89 let secondParts = secondLog.split(' ')90 logs.accountIdStaking = secondParts[0].split('@')[1]91 logs.staking = secondParts[2]92 logs.receivedStakingShares = secondParts[4]93 logs.unstakedBalance = secondParts[9]94 logs.stakingShares = secondParts[13]95 let thirdParts = thirdLog.split(' ')96 logs.contractTotalStakedBalance = thirdParts[5].split('.')[0]97 logs.contractTotalShares = thirdParts[10]98 99 logs.save()100 } 101 102 } 103 } else {104 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);105 }106 if (functionCall.methodName == "deposit") {107 const receiptId = receipt.id.toBase58()108 let logs = new Deposit(`${receiptId}`)109 // Standard receipt properties110 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)111 logs.blockHeight = BigInt.fromU64(blockHeader.height)112 logs.blockHash = blockHeader.hash.toBase58()113 logs.predecessorId = receipt.predecessorId114 logs.receiverId = receipt.receiverId115 logs.signerId = receipt.signerId116 logs.signerPublicKey = publicKey.bytes.toBase58()117 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)118 logs.tokensBurned = outcome.tokensBurnt119 logs.outcomeId = outcome.id.toBase58()120 logs.executorId = outcome.executorId121 logs.outcomeBlockHash = outcome.blockHash.toBase58()122 // Log Parsing123 if(outcome.logs !=null && outcome.logs.length > 0){124 if(outcome.logs.length == 5){125 log.info("outcome log is: {}", [outcome.logs[0]])126 logs.log = outcome.logs[0]127 let firstLog = outcome.logs[0]128 let secondLog = outcome.logs[1]129 let thirdLog = outcome.logs[2]130 let fourthLog = outcome.logs[3]131 let fifthLog = outcome.logs[4]132 let firstParts = firstLog.split(' ')133 logs.epoch = firstParts[1].split(':')[0]134 logs.rewardsReceived = firstParts[7]135 logs.newContractStakedBalance = firstParts[14].split('.')[0]136 logs.newContractTotalShares = firstParts[19]137 let secondParts = secondLog.split(' ')138 logs.totalRewardsFee = secondParts[4]139 140 let thirdParts = thirdLog.split(' ')141 logs.accountIdDepositing = thirdParts[0].split('@')[1]142 logs.deposit = thirdParts[2]143 logs.newUnstakedBalance = thirdParts[7]144 let fourthParts = fourthLog.split(' ')145 logs.accountIdStaking = fourthParts[0].split('@')[1]146 logs.staking = fourthParts[2].split('.')[0]147 logs.receivedStakingShares = fourthParts[4]148 logs.unstakedBalance = fourthParts[9]149 logs.stakingShares = fourthParts[13]150 let fifthParts = fifthLog.split(' ')151 logs.contractTotalStakedBalance = fifthParts[5].split('.')[0]152 logs.contractTotalShares = fifthParts[10]153 logs.save()154 }155 if(outcome.logs.length == 3 && outcome.logs[0].split(' ')[0] == 'Epoch'){156 log.info("outcome log is: {}", [outcome.logs[0]])157 logs.log = outcome.logs[0]158 let firstLog = outcome.logs[0]159 let secondLog = outcome.logs[1]160 let thirdLog = outcome.logs[2]161 162 let firstParts = firstLog.split(' ')163 logs.epoch = firstParts[1].split(':')[0]164 logs.rewardsReceived = firstParts[7]165 logs.newContractStakedBalance = firstParts[14].split('.')[0]166 logs.newContractTotalShares = firstParts[19]167 let secondParts = secondLog.split(' ')168 logs.totalRewardsFee = secondParts[4]169 170 let thirdParts = thirdLog.split(' ')171 logs.accountIdDepositing = thirdParts[0].split('@')[1]172 logs.deposit = thirdParts[2]173 logs.newUnstakedBalance = thirdParts[7]174 logs.save()175 }176 if(outcome.logs.length == 3 && outcome.logs[0].split(' ')[0] != 'Epoch'){177 log.info("outcome log is: {}", [outcome.logs[0]])178 let firstLog = outcome.logs[0]179 let secondLog = outcome.logs[1]180 let thirdLog = outcome.logs[2]181 182 let firstParts = firstLog.split(' ')183 logs.accountIdDepositing = firstParts[0].split('@')[1]184 logs.deposit = firstParts[2]185 logs.newUnstakedBalance = firstParts[7]186 let secondParts = secondLog.split(' ')187 logs.accountIdStaking = secondParts[0].split('@')[1]188 logs.staking = secondParts[2]189 logs.receivedStakingShares = secondParts[4]190 logs.unstakedBalance = secondParts[9]191 logs.stakingShares = secondParts[13]192 let thirdParts = thirdLog.split(' ')193 logs.contractTotalStakedBalance = thirdParts[5].split('.')[0]194 logs.contractTotalShares = thirdParts[10]195 196 logs.save()197 } 198 if(outcome.logs.length == 1){199 log.info("outcome log is: {}", [outcome.logs[0]])200 let firstLog = outcome.logs[0]201 202 let firstParts = firstLog.split(' ')203 logs.accountIdDepositing = firstParts[0].split('@')[1]204 logs.deposit = firstParts[2]205 logs.newUnstakedBalance = firstParts[7]206 207 logs.save()208 }209 } 210 } else {211 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);212 }213 if (functionCall.methodName == "ping"214 || functionCall.methodName == "update_staking_key"215 || functionCall.methodName == "update_reward_fee_fraction"216 || functionCall.methodName == "pause_staking"217 || functionCall.methodName == "resume_staking"218 ) {219 const receiptId = receipt.id.toBase58()220 let logs = new Ping(`${receiptId}`)221 // Standard receipt properties222 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)223 logs.blockHeight = BigInt.fromU64(blockHeader.height)224 logs.blockHash = blockHeader.hash.toBase58()225 logs.predecessorId = receipt.predecessorId226 logs.receiverId = receipt.receiverId227 logs.signerId = receipt.signerId228 logs.signerPublicKey = publicKey.bytes.toBase58()229 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)230 logs.tokensBurned = outcome.tokensBurnt231 logs.outcomeId = outcome.id.toBase58()232 logs.executorId = outcome.executorId233 logs.outcomeBlockHash = outcome.blockHash.toBase58()234 // Log Parsing235 if(outcome.logs !=null && outcome.logs.length > 0){236 log.info("outcome log is: {}", [outcome.logs[0]])237 let firstLog = outcome.logs[0]238 239 let firstParts = firstLog.split(' ')240 logs.epoch = firstParts[1].split(':')[0]241 logs.rewardsReceived = firstParts[7]242 logs.newContractStakedBalance = firstParts[14].split('.')[0]243 logs.newContractTotalShares = firstParts[19]244 245 logs.save()246 } 247 } else {248 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);249 }250 if (functionCall.methodName == "withdraw_all") {251 const receiptId = receipt.id.toBase58()252 let logs = new WithdrawAll(`${receiptId}`)253 // Standard receipt properties254 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)255 logs.blockHeight = BigInt.fromU64(blockHeader.height)256 logs.blockHash = blockHeader.hash.toBase58()257 logs.predecessorId = receipt.predecessorId258 logs.receiverId = receipt.receiverId259 logs.signerId = receipt.signerId260 logs.signerPublicKey = publicKey.bytes.toBase58()261 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)262 logs.tokensBurned = outcome.tokensBurnt263 logs.outcomeId = outcome.id.toBase58()264 logs.executorId = outcome.executorId265 logs.outcomeBlockHash = outcome.blockHash.toBase58()266 // Log Parsing267 if(outcome.logs !=null && outcome.logs.length > 0){268 if(outcome.logs.length == 2){269 let firstLog = outcome.logs[0]270 let secondLog = outcome.logs[1]271 let firstParts = firstLog.split(' ')272 logs.epoch = firstParts[1].split(':')[0]273 logs.rewardsReceived = firstParts[7]274 logs.newContractStakedBalance = firstParts[14].split('.')[0]275 logs.newContractTotalShares = firstParts[19]276 let secondParts = secondLog.split(' ')277 logs.accountId = secondParts[0].split('@')[1]278 logs.amount = secondParts[2]279 logs.newUnstakedBalance = secondParts[7]280 }281 if(outcome.logs.length == 1){282 log.info("outcome log is: {}", [outcome.logs[0]])283 let firstLog = outcome.logs[0]284 285 let firstParts = firstLog.split(' ')286 logs.accountId = firstParts[0].split('@')[1]287 logs.amount = firstParts[2]288 logs.newUnstakedBalance = firstParts[7]289 290 logs.save()291 } 292 } 293 } else {294 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);295 }296 if (functionCall.methodName == "withdraw") {297 const receiptId = receipt.id.toBase58()298 let logs = new Withdraw(`${receiptId}`)299 // Standard receipt properties300 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)301 logs.blockHeight = BigInt.fromU64(blockHeader.height)302 logs.blockHash = blockHeader.hash.toBase58()303 logs.predecessorId = receipt.predecessorId304 logs.receiverId = receipt.receiverId305 logs.signerId = receipt.signerId306 logs.signerPublicKey = publicKey.bytes.toBase58()307 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)308 logs.tokensBurned = outcome.tokensBurnt309 logs.outcomeId = outcome.id.toBase58()310 logs.executorId = outcome.executorId311 logs.outcomeBlockHash = outcome.blockHash.toBase58()312 // Log Parsing313 if(outcome.logs !=null && outcome.logs.length > 0){314 if(outcome.logs.length == 2){315 let firstLog = outcome.logs[0]316 let secondLog = outcome.logs[1]317 let firstParts = firstLog.split(' ')318 logs.epoch = firstParts[1].split(':')[0]319 logs.rewardsReceived = firstParts[7]320 logs.newContractStakedBalance = firstParts[14].split('.')[0]321 logs.newContractTotalShares = firstParts[19]322 let secondParts = secondLog.split(' ')323 logs.accountId = secondParts[0].split('@')[1]324 logs.amount = secondParts[2]325 logs.newUnstakedBalance = secondParts[7]326 }327 if(outcome.logs.length == 1){328 log.info("outcome log is: {}", [outcome.logs[0]])329 let firstLog = outcome.logs[0]330 331 let firstParts = firstLog.split(' ')332 logs.accountId = firstParts[0].split('@')[1]333 logs.amount = firstParts[2]334 logs.newUnstakedBalance = firstParts[7]335 336 logs.save()337 } 338 } 339 } else {340 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);341 }342 if (functionCall.methodName == "stake_all") {343 const receiptId = receipt.id.toBase58()344 let logs = new StakeAll(`${receiptId}`)345 // Standard receipt properties346 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)347 logs.blockHeight = BigInt.fromU64(blockHeader.height)348 logs.blockHash = blockHeader.hash.toBase58()349 logs.predecessorId = receipt.predecessorId350 logs.receiverId = receipt.receiverId351 logs.signerId = receipt.signerId352 logs.signerPublicKey = publicKey.bytes.toBase58()353 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)354 logs.tokensBurned = outcome.tokensBurnt355 logs.outcomeId = outcome.id.toBase58()356 logs.executorId = outcome.executorId357 logs.outcomeBlockHash = outcome.blockHash.toBase58()358 // Log Parsing359 if(outcome.logs !=null && outcome.logs.length > 0){360 if(outcome.logs.length == 3 && outcome.logs[0].split(' ')[0] == 'Epoch'){361 let firstLog = outcome.logs[0]362 let secondLog = outcome.logs[1]363 let thirdLog = outcome.logs[2]364 let firstParts = firstLog.split(' ')365 logs.epoch = firstParts[1].split(':')[0]366 logs.rewardsReceived = firstParts[7]367 logs.newContractStakedBalance = firstParts[14].split('.')[0]368 logs.newContractTotalShares = firstParts[19]369 let secondParts = secondLog.split(' ')370 logs.accountIdStaking = secondParts[0].split('@')[1]371 logs.staking = secondParts[2]372 logs.receivedStakingShares = secondParts[4]373 logs.unstakedBalance = secondParts[9]374 logs.stakingShares = secondParts[13]375 let thirdParts = thirdLog.split(' ')376 logs.contractTotalStakedBalance = thirdParts[5].split('.')[0]377 logs.contractTotalShares = thirdParts[10]378 }379 if(outcome.logs.length == 3){380 log.info("outcome log is: {}", [outcome.logs[0]])381 let firstLog = outcome.logs[0]382 let secondLog = outcome.logs[1]383 let thirdLog = outcome.logs[2]384 385 let firstParts = firstLog.split(' ')386 logs.accountIdDepositing = firstParts[0].split('@')[1]387 logs.deposit = firstParts[2]388 logs.newUnstakedBalance = firstParts[7]389 let secondParts = secondLog.split(' ')390 logs.accountIdStaking = secondParts[0].split('@')[1]391 logs.staking = secondParts[2]392 logs.receivedStakingShares = secondParts[4]393 logs.unstakedBalance = secondParts[9]394 logs.stakingShares = secondParts[13]395 let thirdParts = thirdLog.split(' ')396 logs.contractTotalStakedBalance = thirdParts[5].split('.')[0]397 logs.contractTotalShares = thirdParts[10]398 399 logs.save()400 }401 if(outcome.logs.length == 2){402 log.info("outcome log is: {}", [outcome.logs[0]])403 let firstLog = outcome.logs[0]404 let secondLog = outcome.logs[1]405 let firstParts = firstLog.split(' ')406 logs.accountIdStaking = firstParts[0].split('@')[1]407 logs.staking = firstParts[2]408 logs.receivedStakingShares = firstParts[4]409 logs.unstakedBalance = firstParts[9]410 logs.stakingShares = firstParts[13]411 let secondParts = secondLog.split(' ')412 logs.contractTotalStakedBalance = secondParts[5].split('.')[0]413 logs.contractTotalShares = secondParts[10]414 415 logs.save()416 } 417 } 418 } else {419 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);420 } 421 if (functionCall.methodName == "stake") {422 const receiptId = receipt.id.toBase58()423 let logs = new Stake(`${receiptId}`)424 // Standard receipt properties425 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)426 logs.blockHeight = BigInt.fromU64(blockHeader.height)427 logs.blockHash = blockHeader.hash.toBase58()428 logs.predecessorId = receipt.predecessorId429 logs.receiverId = receipt.receiverId430 logs.signerId = receipt.signerId431 logs.signerPublicKey = publicKey.bytes.toBase58()432 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)433 logs.tokensBurned = outcome.tokensBurnt434 logs.outcomeId = outcome.id.toBase58()435 logs.executorId = outcome.executorId436 logs.outcomeBlockHash = outcome.blockHash.toBase58()437 // Log Parsing438 if(outcome.logs !=null && outcome.logs.length > 0){439 if(outcome.logs.length == 4){440 let firstLog = outcome.logs[0]441 let secondLog = outcome.logs[1]442 let thirdLog = outcome.logs[2]443 let firstParts = firstLog.split(' ')444 logs.epoch = firstParts[1].split(':')[0]445 logs.rewardsReceived = firstParts[7]446 logs.newContractStakedBalance = firstParts[14].split('.')[0]447 logs.newContractTotalShares = firstParts[19]448 let secondParts = secondLog.split(' ')449 logs.accountIdStaking = secondParts[0].split('@')[1]450 logs.staking = secondParts[2]451 logs.receivedStakingShares = secondParts[4]452 logs.unstakedBalance = secondParts[9]453 logs.stakingShares = secondParts[13]454 let thirdParts = thirdLog.split(' ')455 logs.contractTotalStakedBalance = thirdParts[5].split('.')[0]456 logs.contractTotalShares = thirdParts[10]457 }458 if(outcome.logs.length == 3){459 log.info("outcome log is: {}", [outcome.logs[0]])460 let firstLog = outcome.logs[0]461 let secondLog = outcome.logs[1]462 let thirdLog = outcome.logs[2]463 464 let firstParts = firstLog.split(' ')465 logs.accountIdDepositing = firstParts[0].split('@')[1]466 logs.deposit = firstParts[2]467 logs.newUnstakedBalance = firstParts[7]468 let secondParts = secondLog.split(' ')469 logs.accountIdStaking = secondParts[0].split('@')[1]470 logs.staking = secondParts[2]471 logs.receivedStakingShares = secondParts[4]472 logs.unstakedBalance = secondParts[9]473 logs.stakingShares = secondParts[13]474 let thirdParts = thirdLog.split(' ')475 logs.contractTotalStakedBalance = thirdParts[5].split('.')[0]476 logs.contractTotalShares = thirdParts[10]477 478 logs.save()479 }480 if(outcome.logs.length == 2){481 log.info("outcome log is: {}", [outcome.logs[0]])482 let firstLog = outcome.logs[0]483 let secondLog = outcome.logs[1]484 let firstParts = firstLog.split(' ')485 logs.accountIdStaking = firstParts[0].split('@')[1]486 logs.staking = firstParts[2]487 logs.receivedStakingShares = firstParts[4]488 logs.unstakedBalance = firstParts[9]489 logs.stakingShares = firstParts[13]490 let secondParts = secondLog.split(' ')491 logs.contractTotalStakedBalance = secondParts[5].split('.')[0]492 logs.contractTotalShares = secondParts[10]493 494 logs.save()495 } 496 } 497 } else {498 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);499 } 500 if (functionCall.methodName == "unstake") {501 const receiptId = receipt.id.toBase58()502 let logs = new Unstake(`${receiptId}`)503 // Standard receipt properties504 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)505 logs.blockHeight = BigInt.fromU64(blockHeader.height)506 logs.blockHash = blockHeader.hash.toBase58()507 logs.predecessorId = receipt.predecessorId508 logs.receiverId = receipt.receiverId509 logs.signerId = receipt.signerId510 logs.signerPublicKey = publicKey.bytes.toBase58()511 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)512 logs.tokensBurned = outcome.tokensBurnt513 logs.outcomeId = outcome.id.toBase58()514 logs.executorId = outcome.executorId515 logs.outcomeBlockHash = outcome.blockHash.toBase58()516 // Log Parsing517 if(outcome.logs !=null && outcome.logs.length > 0){518 if(outcome.logs.length == 4){519 log.info("outcome log is: {}", [outcome.logs[0]])520 let firstLog = outcome.logs[0]521 let secondLog = outcome.logs[1]522 let thirdLog = outcome.logs[2]523 let fourthLog = outcome.logs[3]524 let firstParts = firstLog.split(' ')525 logs.epoch = firstParts[1].split(':')[0]526 logs.rewardsReceived = firstParts[7]527 logs.newContractStakedBalance = firstParts[14].split('.')[0]528 logs.newContractTotalShares = firstParts[19]529 let secondParts = secondLog.split(' ')530 logs.totalRewardsFee = secondParts[4]531 532 let thirdParts = thirdLog.split(' ')533 logs.accountId = thirdParts[0].split('@')[1]534 logs.amount = thirdParts[2].split('.')[0]535 logs.spentStakingShareAmount = thirdParts[4]536 logs.totalUnstakedBalance = thirdParts[8]537 logs.totalStakingShares = thirdParts[12]538 539 let fourthParts = fourthLog.split(' ')540 logs.contractTotalStakedBalance = fourthParts[5].split('.')[0]541 logs.contractTotalShares = fourthParts[10]542 543 logs.save()544 }545 if(outcome.logs.length == 2){546 log.info("outcome log is: {}", [outcome.logs[0]])547 let firstLog = outcome.logs[0]548 let secondLog = outcome.logs[1]549 550 let firstParts = firstLog.split(' ')551 logs.accountId = firstParts[0].split('@')[1]552 logs.amount = firstParts[2].split('.')[0]553 logs.spentStakingShareAmount = firstParts[4]554 logs.totalUnstakedBalance = firstParts[8]555 logs.totalStakingShares = firstParts[12]556 557 let secondParts = secondLog.split(' ')558 logs.contractTotalStakedBalance = secondParts[5].split('.')[0]559 logs.contractTotalShares = secondParts[10]560 561 logs.save()562 } 563 } 564 } else {565 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);566 }567 if (functionCall.methodName == "unstake_all") {568 const receiptId = receipt.id.toBase58()569 let logs = new UnstakeAll(`${receiptId}`)570 // Standard receipt properties571 logs.blockTime = BigInt.fromU64(blockHeader.timestampNanosec/1000000)572 logs.blockHeight = BigInt.fromU64(blockHeader.height)573 logs.blockHash = blockHeader.hash.toBase58()574 logs.predecessorId = receipt.predecessorId575 logs.receiverId = receipt.receiverId576 logs.signerId = receipt.signerId577 logs.signerPublicKey = publicKey.bytes.toBase58()578 logs.gasBurned = BigInt.fromU64(outcome.gasBurnt)579 logs.tokensBurned = outcome.tokensBurnt580 logs.outcomeId = outcome.id.toBase58()581 logs.executorId = outcome.executorId582 logs.outcomeBlockHash = outcome.blockHash.toBase58()583 // Log Parsing584 if(outcome.logs !=null && outcome.logs.length > 0){585 if(outcome.logs.length == 4){586 log.info("outcome log is: {}", [outcome.logs[0]])587 let firstLog = outcome.logs[0]588 let secondLog = outcome.logs[1]589 let thirdLog = outcome.logs[2]590 let fourthLog = outcome.logs[3]591 let firstParts = firstLog.split(' ')592 logs.epoch = firstParts[1].split(':')[0]593 logs.rewardsReceived = firstParts[7]594 logs.newContractStakedBalance = firstParts[14].split('.')[0]595 logs.newContractTotalShares = firstParts[19]596 let secondParts = secondLog.split(' ')597 logs.totalRewardsFee = secondParts[4]598 599 let thirdParts = thirdLog.split(' ')600 logs.accountId = thirdParts[0].split('@')[1]601 logs.amount = thirdParts[2].split('.')[0]602 logs.spentStakingShareAmount = thirdParts[4]603 logs.totalUnstakedBalance = thirdParts[8]604 logs.totalStakingShares = thirdParts[12]605 606 let fourthParts = fourthLog.split(' ')607 logs.contractTotalStakedBalance = fourthParts[5].split('.')[0]608 logs.contractTotalShares = fourthParts[10]609 610 logs.save()611 }612 if(outcome.logs.length == 2){613 log.info("outcome log is: {}", [outcome.logs[0]])614 let firstLog = outcome.logs[0]615 let secondLog = outcome.logs[1]616 617 let firstParts = firstLog.split(' ')618 logs.accountId = firstParts[0].split('@')[1]619 logs.amount = firstParts[2].split('.')[0]620 logs.spentStakingShareAmount = firstParts[4]621 logs.totalUnstakedBalance = firstParts[8]622 logs.totalStakingShares = firstParts[12]623 624 let secondParts = secondLog.split(' ')625 logs.contractTotalStakedBalance = secondParts[5].split('.')[0]626 logs.contractTotalShares = secondParts[10]627 628 logs.save()629 }630 } 631 } else {632 log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]);633 } ...
Using AI Code Generation
1var mb = require('mountebank');2var imposter = {3 {4 {5 "is": {6 }7 }8 }9};10mb.create(imposter).then(function (server) {11 console.log('Server: ', server);12 console.log('Server.port: ', server.port);13 console.log('Server.protocol: ', server.protocol);14 console.log('Server.stubs: ', server.stubs);15 console.log('Server.stubs[0].predicates: ', server.stubs[0].predicates);16 console.log('Server.stubs[0].responses: ', server.stubs[0].responses);17 console.log('Server.stubs[0].responses[0].is: ', server.stubs[0].responses[0].is);18 console.log('Server.stubs[0].responses[0].is.body: ', server.stubs[0].responses[0].is.body);19});20Server: { port: 3000,21 stubs: [ { responses: [Object] } ] }22Server.stubs: [ { responses: [ [Object] ] } ]23Server.stubs[0].responses: [ { is: { body: 'Hello World!' } } ]24Server.stubs[0].responses[0].is: { body: 'Hello World!' }
Using AI Code Generation
1var mb = require('mountebank'),2 firstParts = mb.firstParts;3var mb = require('mountebank'),4 secondParts = mb.secondParts;5var mb = require('mountebank'),6 thirdParts = mb.thirdParts;7var mb = require('mountebank'),8 fourthParts = mb.fourthParts;9var mb = require('mountebank'),10 fifthParts = mb.fifthParts;11var mb = require('mountebank'),12 sixthParts = mb.sixthParts;13var mb = require('mountebank'),14 seventhParts = mb.seventhParts;15var mb = require('mountebank'),16 eighthParts = mb.eighthParts;17var mb = require('mountebank'),18 ninthParts = mb.ninthParts;19var mb = require('mountebank'),20 tenthParts = mb.tenthParts;21var mb = require('mountebank'),22 eleventhParts = mb.eleventhParts;23var mb = require('mountebank'),24 twelvethParts = mb.twelvethParts;25var mb = require('mountebank'),26 thirteenthParts = mb.thirteenthParts;27var mb = require('mountebank'),28 fourteenthParts = mb.fourteenthParts;29var mb = require('mountebank'),30 fifteenthParts = mb.fifteenthParts;31var mb = require('mountebank'),32 sixteenthParts = mb.sixteenthParts;
Using AI Code Generation
1var mb = require('mountebank'),2 stub = {3 {4 is: {5 }6 }7 };8mb.start({9}, function () {10 console.log('mountebank started');11});12var mb = require('mountebank'),13 stub = {14 {15 is: {16 }17 }18 };19mb.start({20}, function () {21 console.log('mountebank started');22});
Using AI Code Generation
1var mb = require('mountebank');2var firstParts = mb.firstParts;3var assert = require('chai').assert;4describe('firstParts', function () {5 it('should return first part of url', function () {6 });7});8var mb = require('mountebank');9var secondParts = mb.secondParts;10var assert = require('chai').assert;11describe('secondParts', function () {12 it('should return second part of url', function () {13 });14});15var mb = require('mountebank');16var thirdParts = mb.thirdParts;17var assert = require('chai').assert;18describe('thirdParts', function () {19 it('should return third part of url', function () {
Using AI Code Generation
1var mb = require('mountebank');2var mbHelper = mb.create();3 {4 {5 equals: {6 }7 }8 {9 is: {10 headers: {11 },12 body: JSON.stringify({13 })14 }15 }16 }17];18mbHelper.start(2525).then(function () {19 mbHelper.addStub(stubs[0]).then(function (stub) {20 console.log('stub', stub);21 });22});23var mb = require('mountebank');24var mbHelper = mb.create();25 {26 {27 equals: {28 }29 }30 {31 is: {32 headers: {33 },34 body: JSON.stringify({35 })36 }37 }38 }39];40mbHelper.start(2525).then(function () {41 mbHelper.addStub(stubs[0]).then(function (stub) {42 console.log('stub', stub);43 });44});45var mb = require('mountebank');46var mbHelper = mb.create();47 {48 {49 equals: {50 }51 }52 {53 is: {54 headers: {55 },56 body: JSON.stringify({57 })58 }59 }60 }61];62mbHelper.start(2525).then(function () {63 mbHelper.addStub(stubs[0]).then(function (stub) {64 console.log('stub', stub);65 });66});67var mb = require('mountebank');68var mbHelper = mb.create();69 {
Using AI Code Generation
1var firstParts = require('mbjs').firstParts;2var request = require('request');3var mbjs = require('mbjs');4var mb = mbjs.create({port: 2525});5mb.createImposter(2525, {protocol: 'http', stubs: [{responses: [{is: {body: 'Hello World'}}]}]}, function (error, imposter) {6 });7});8mb.deleteImposter(2525, function () {9 console.log('done');10});
Using AI Code Generation
1const firstParts = require("mountebank").firstParts;2var request = {3 "headers": {4 },5 "body": {6 }7};8var firstParts = firstParts(request, 2);9const firstPart = require("mountebank").firstPart;10var request = {11 "headers": {12 },13 "body": {14 }15};16var firstPart = firstPart(request);17const first = require("mountebank").first;18var request = {19 "headers": {20 },21 "body": {22 }23};24var first = first(request);25const secondParts = require("mountebank").secondParts;26var request = {27 "headers": {28 },29 "body": {30 }31};32var secondParts = secondParts(request, 2);33const secondPart = require("mountebank").secondPart;34var request = {
Using AI Code Generation
1var mb = require('mountebank');2var firstParts = mb.firstParts;3var response = firstParts(200, { 'Content-Type': 'text/html' }, 'Hello World');4console.log(response);5{6 {7 {8 "is": {9 "headers": {10 },11 }12 }13 }14}15{16 {17 {18 "is": {19 "headers": {20 },21 }22 }23 }24}25{26 {27 {28 "is": {29 "headers": {30 },31 }32 }33 }34}35{36 {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!