How to use tx method in wpt

Best JavaScript code snippet using wpt

CToken.ts

Source:CToken.ts Github

copy

Full Screen

1import { PromiEvent, TransactionReceipt } from "web3-core";2import BN from "bn.js";3import MarketContract from "./MarketContract";4import CTokenArtifact from "../abi/CToken.json";5import CTokenV2Artifact from "../abi/CTokenV2.json";6import { CToken as CTokenWeb3Interface } from "../types/CToken";7import { CTokenV2 as CTokenV2Web3Interface } from "../types/CTokenV2";8import { NonPayableTx } from "../types/types";9import { Comptroller, ComptrollerV2 } from "./Comptroller";10import MarketSDK from "./MarketSDK";11class CToken extends MarketContract<CTokenWeb3Interface> {12 constructor(sdk: MarketSDK, address: string){13 super(sdk, address, CTokenArtifact.abi);14 }15 _acceptAdmin(16 tx?: NonPayableTx17 ): PromiEvent<TransactionReceipt> {18 return this.contract.methods._acceptAdmin().send(tx);19 }20 _reduceReserves(21 redduceAmount: number | string | BN,22 tx?: NonPayableTx,23 ): PromiEvent<TransactionReceipt> {24 return this.contract.methods._reduceReserves(redduceAmount).send(tx);25 }26 _renounceAdminRights(27 tx?: NonPayableTx28 ): PromiEvent<TransactionReceipt> {29 return this.contract.methods._renounceAdminRights().send(tx);30 }31 _renounceFuseAdminRights(32 tx?: NonPayableTx33 ): PromiEvent<TransactionReceipt> {34 return this.contract.methods._renounceFuseAdminRights().send(tx);35 }36 _setAdminFee(37 newAdminFeeMantissa: number | string | BN,38 tx?: NonPayableTx39 ): PromiEvent<TransactionReceipt> {40 return this.contract.methods._setAdminFee(newAdminFeeMantissa).send(tx);41 }42 _setComptroller(43 newComptroller: Comptroller,44 tx?: NonPayableTx45 ): PromiEvent<TransactionReceipt> {46 return this.contract.methods._setComptroller(newComptroller.address).send(tx);47 }48 _setFuseFee(49 tx?: NonPayableTx50 ): PromiEvent<TransactionReceipt> {51 return this.contract.methods._setFuseFee().send(tx);52 }53 _setInterestRateModel(54 newInterestRateModel: string, // change to InterestRateModel class later55 tx?: NonPayableTx56 ): PromiEvent<TransactionReceipt> {57 return this.contract.methods._setInterestRateModel(newInterestRateModel).send(tx);58 }59 _setPendingAdmin(60 newPendingAdmin: string,61 tx?: NonPayableTx62 ): PromiEvent<TransactionReceipt> {63 return this.contract.methods._setPendingAdmin(newPendingAdmin).send(tx);64 }65 _setReserveFactor(66 newReserveFactorMantissa: number | string | BN,67 tx?: NonPayableTx68 ): PromiEvent<TransactionReceipt> {69 return this.contract.methods._setReserveFactor(newReserveFactorMantissa).send(tx);70 }71 _withdrawAdminFees(72 withdrawAmount: number | string | BN,73 tx?: NonPayableTx74 ): PromiEvent<TransactionReceipt> {75 return this.contract.methods._withdrawAdminFees(withdrawAmount).send(tx);76 }77 _withdrawFuseFees(78 withdrawAmount: number | string | BN,79 tx?: NonPayableTx80 ): PromiEvent<TransactionReceipt> {81 return this.contract.methods._withdrawFuseFees(withdrawAmount).send(tx);82 }83 accrualBlockNumber(84 tx?: NonPayableTx85 ): Promise<string> {86 return this.contract.methods.accrualBlockNumber().call(tx);87 }88 accrueInterest(89 tx?: NonPayableTx90 ): Promise<string> {91 return this.contract.methods.accrueInterest().call(tx);92 }93 admin(94 tx?: NonPayableTx95 ): Promise<string> {96 return this.contract.methods.admin().call(tx);97 }98 adminFeeMantissa(99 tx?: NonPayableTx100 ): Promise<string> {101 return this.contract.methods.adminFeeMantissa().call(tx);102 }103 adminHasRights(104 tx?: NonPayableTx105 ): Promise<boolean> {106 return this.contract.methods.adminHasRights().call(tx);107 }108 allowance(109 owner: string,110 spender: string,111 tx?: NonPayableTx112 ): PromiEvent<TransactionReceipt> {113 return this.contract.methods.allowance(owner, spender).send(tx);114 }115 approve(116 spender: string,117 amount: number | string | BN,118 tx?: NonPayableTx119 ): PromiEvent<TransactionReceipt> {120 return this.contract.methods.approve(spender, amount).send(tx);121 }122 balanceOf(123 owner: string,124 tx?: NonPayableTx125 ): Promise<string> {126 return this.contract.methods.balanceOf(owner).call(tx);127 }128 balanceOfUnderlying(129 owner: string,130 tx?: NonPayableTx131 ): Promise<string> {132 return this.contract.methods.balanceOfUnderlying(owner).call(tx);133 }134 borrow(135 borrowAmount: number | string | BN,136 tx?: NonPayableTx137 ): PromiEvent<TransactionReceipt> {138 return this.contract.methods.borrow(borrowAmount).send(tx);139 }140 borrowBalanceCurrent(141 account: string,142 tx?: NonPayableTx143 ): Promise<string> {144 return this.contract.methods.borrowBalanceCurrent(account).call(tx);145 }146 borrowBalanceStored(147 account: string,148 tx?: NonPayableTx149 ): Promise<string> {150 return this.contract.methods.borrowBalanceStored(account).call(tx);151 }152 borrowIndex(153 tx?: NonPayableTx154 ): Promise<string> {155 return this.contract.methods.borrowIndex().call(tx);156 }157 borrowRatePerBlock(158 tx?: NonPayableTx159 ): Promise<string> {160 return this.contract.methods.borrowRatePerBlock().call(tx);161 }162 async comptroller(163 tx?: NonPayableTx164 ): Promise<Comptroller> {165 const addr = await this.contract.methods.comptroller().call(tx);166 return new Comptroller(this.sdk, addr);167 }168 169 decimals(170 tx?: NonPayableTx171 ): Promise<string> {172 return this.contract.methods.decimals().call(tx);173 }174 exchangeRateCurrent(175 tx?: NonPayableTx176 ): Promise<string> {177 return this.contract.methods.exchangeRateCurrent().call(tx);178 }179 exchangeRateStored(180 tx?: NonPayableTx181 ): Promise<string> {182 return this.contract.methods.exchangeRateStored().call(tx);183 }184 fuseAdminHasRights(185 tx?: NonPayableTx186 ): Promise<boolean> {187 return this.contract.methods.fuseAdminHasRights().call(tx);188 }189 fuseFeeMantissa(190 tx?: NonPayableTx191 ): Promise<string> {192 return this.contract.methods.fuseFeeMantissa().call(tx);193 }194 getAccountSnapshot(195 account: string,196 tx?: NonPayableTx197 ): Promise<{198 0: string;199 1: string;200 2: string;201 3: string;202 }> {203 return this.contract.methods.getAccountSnapshot(account).call(tx);204 }205 getCash(206 tx?: NonPayableTx207 ): Promise<string> {208 return this.contract.methods.getCash().call(tx);209 }210 interestRateModel(211 tx?: NonPayableTx212 ): Promise<string> {213 return this.contract.methods.interestRateModel().call(tx);214 }215 isCEther(216 tx?: NonPayableTx217 ): Promise<boolean> {218 return this.contract.methods.isCEther().call(tx);219 }220 isCToken(221 tx?: NonPayableTx222 ): Promise<boolean> {223 return this.contract.methods.isCToken().call(tx);224 }225 liquidateBorrow(226 borrower: string,227 repayAmount: number | string | BN,228 cTokenCollateral: CToken | string,229 tx?: NonPayableTx230 ): PromiEvent<TransactionReceipt> {231 if(cTokenCollateral instanceof CToken){232 cTokenCollateral = cTokenCollateral.address;233 }234 return this.contract.methods.liquidateBorrow(borrower, repayAmount, cTokenCollateral).send(tx);235 }236 mint(237 mintAmount: number | string | BN,238 tx?: NonPayableTx239 ): PromiEvent<TransactionReceipt> {240 return this.contract.methods.mint(mintAmount).send(tx);241 }242 name(243 tx?: NonPayableTx244 ): Promise<string> {245 return this.contract.methods.name().call(tx);246 }247 pendingAdmin(248 tx?: NonPayableTx249 ): Promise<string> {250 return this.contract.methods.pendingAdmin().call(tx);251 }252 redeem(253 redeemTokens: number | string | BN,254 tx?: NonPayableTx255 ): PromiEvent<TransactionReceipt> {256 return this.contract.methods.redeem(redeemTokens).send(tx);257 }258 redeemUnderlying(259 redeemAdmount: number | string | BN,260 tx?: NonPayableTx261 ): PromiEvent<TransactionReceipt> {262 return this.contract.methods.redeemUnderlying(redeemAdmount).send(tx);263 }264 repayBorrow(265 repayAmount: number | string | BN,266 tx?: NonPayableTx267 ): PromiEvent<TransactionReceipt> {268 return this.contract.methods.repayBorrow(repayAmount).send(tx);269 }270 repayBorrowBehalf(271 borrower: string,272 repayAmount: number | string | BN,273 tx?: NonPayableTx274 ): PromiEvent<TransactionReceipt> {275 return this.contract.methods.repayBorrowBehalf(borrower, repayAmount).send(tx);276 }277 reserveFactorMantissa(278 tx?: NonPayableTx279 ): Promise<string> {280 return this.contract.methods.reserveFactorMantissa().call(tx);281 }282 seize(283 liquidator: string, 284 borrower: string,285 seizeTokens: number | string | BN,286 tx?: NonPayableTx287 ): PromiEvent<TransactionReceipt> {288 return this.contract.methods.seize(liquidator, borrower, seizeTokens).send(tx);289 }290 supplyRatePerBlock(291 tx?: NonPayableTx292 ): Promise<string> {293 return this.contract.methods.supplyRatePerBlock().call(tx);294 }295 symbol(296 tx?: NonPayableTx297 ): Promise<string> {298 return this.contract.methods.symbol().call(tx);299 }300 totalAdminFees(301 tx?: NonPayableTx302 ): Promise<string> {303 return this.contract.methods.totalAdminFees().call(tx);304 }305 totalBorrows(306 tx?: NonPayableTx307 ): Promise<string> {308 return this.contract.methods.totalBorrows().call(tx);309 }310 totalBorrowsCurrent(311 tx?: NonPayableTx312 ): Promise<string> {313 return this.contract.methods.totalBorrowsCurrent().call(tx);314 }315 totalFuseFees(316 tx?: NonPayableTx317 ): Promise<string> {318 return this.contract.methods.totalFuseFees().call(tx);319 }320 totalReserves(321 tx?: NonPayableTx322 ): Promise<string> {323 return this.contract.methods.totalReserves().call(tx);324 }325 totalSupply(326 tx?: NonPayableTx327 ): Promise<string> {328 return this.contract.methods.totalSupply().call(tx);329 }330 transfer(331 dst: string,332 amount: number | string | BN,333 tx?: NonPayableTx334 ): PromiEvent<TransactionReceipt> {335 return this.contract.methods.transfer(dst, amount).send(tx);336 }337 transferFrom(338 src: string,339 dst: string,340 amount: number | string | BN,341 tx?: NonPayableTx342 ): PromiEvent<TransactionReceipt> {343 return this.contract.methods.transferFrom(src, dst, amount).send(tx);344 }345 underlying(346 tx?: NonPayableTx347 ): Promise<string> {348 return this.contract.methods.underlying().call(tx);349 }350}351class CTokenV2 extends MarketContract<CTokenV2Web3Interface> {352 constructor(sdk: MarketSDK, address: string){353 super(sdk, address, CTokenV2Artifact.abi);354 }355 356 _reduceReserves(357 redduceAmount: number | string | BN,358 tx?: NonPayableTx,359 ): PromiEvent<TransactionReceipt> {360 return this.contract.methods._reduceReserves(redduceAmount).send(tx);361 }362 363 _setAdminFee(364 newAdminFeeMantissa: number | string | BN,365 tx?: NonPayableTx366 ): PromiEvent<TransactionReceipt> {367 return this.contract.methods._setAdminFee(newAdminFeeMantissa).send(tx);368 }369 370 _setInterestRateModel(371 newInterestRateModel: string, // change to InterestRateModel class later372 tx?: NonPayableTx373 ): PromiEvent<TransactionReceipt> {374 return this.contract.methods._setInterestRateModel(newInterestRateModel).send(tx);375 }376 _setNameAndSymbol(377 name: string,378 symbol: string,379 tx?: NonPayableTx380 ): PromiEvent<TransactionReceipt> {381 return this.contract.methods._setNameAndSymbol(name, symbol).send(tx);382 }383 _setReserveFactor(384 newReserveFactorMantissa: number | string | BN,385 tx?: NonPayableTx386 ): PromiEvent<TransactionReceipt> {387 return this.contract.methods._setReserveFactor(newReserveFactorMantissa).send(tx);388 }389 _withdrawAdminFees(390 withdrawAmount: number | string | BN,391 tx?: NonPayableTx392 ): PromiEvent<TransactionReceipt> {393 return this.contract.methods._withdrawAdminFees(withdrawAmount).send(tx);394 }395 _withdrawFuseFees(396 withdrawAmount: number | string | BN,397 tx?: NonPayableTx398 ): PromiEvent<TransactionReceipt> {399 return this.contract.methods._withdrawFuseFees(withdrawAmount).send(tx);400 }401 accrualBlockNumber(402 tx?: NonPayableTx403 ): Promise<string> {404 return this.contract.methods.accrualBlockNumber().call(tx);405 }406 accrueInterest(407 tx?: NonPayableTx408 ): Promise<string> {409 return this.contract.methods.accrueInterest().call(tx);410 }411 adminFeeMantissa(412 tx?: NonPayableTx413 ): Promise<string> {414 return this.contract.methods.adminFeeMantissa().call(tx);415 }416 allowance(417 owner: string,418 spender: string,419 tx?: NonPayableTx420 ): PromiEvent<TransactionReceipt> {421 return this.contract.methods.allowance(owner, spender).send(tx);422 }423 approve(424 spender: string,425 amount: number | string | BN,426 tx?: NonPayableTx427 ): PromiEvent<TransactionReceipt> {428 return this.contract.methods.approve(spender, amount).send(tx);429 }430 balanceOf(431 owner: string,432 tx?: NonPayableTx433 ): Promise<string> {434 return this.contract.methods.balanceOf(owner).call(tx);435 }436 balanceOfUnderlying(437 owner: string,438 tx?: NonPayableTx439 ): Promise<string> {440 return this.contract.methods.balanceOfUnderlying(owner).call(tx);441 }442 borrow(443 borrowAmount: number | string | BN,444 tx?: NonPayableTx445 ): PromiEvent<TransactionReceipt> {446 return this.contract.methods.borrow(borrowAmount).send(tx);447 }448 borrowBalanceCurrent(449 account: string,450 tx?: NonPayableTx451 ): Promise<string> {452 return this.contract.methods.borrowBalanceCurrent(account).call(tx);453 }454 borrowBalanceStored(455 account: string,456 tx?: NonPayableTx457 ): Promise<string> {458 return this.contract.methods.borrowBalanceStored(account).call(tx);459 }460 borrowIndex(461 tx?: NonPayableTx462 ): Promise<string> {463 return this.contract.methods.borrowIndex().call(tx);464 }465 borrowRatePerBlock(466 tx?: NonPayableTx467 ): Promise<string> {468 return this.contract.methods.borrowRatePerBlock().call(tx);469 }470 471 async comptroller(472 tx?: NonPayableTx473 ): Promise<ComptrollerV2> {474 const addr = await this.contract.methods.comptroller().call(tx);475 return new ComptrollerV2(this.sdk, addr);476 }477 decimals(478 tx?: NonPayableTx479 ): Promise<string> {480 return this.contract.methods.decimals().call(tx);481 }482 exchangeRateCurrent(483 tx?: NonPayableTx484 ): Promise<string> {485 return this.contract.methods.exchangeRateCurrent().call(tx);486 }487 exchangeRateStored(488 tx?: NonPayableTx489 ): Promise<string> {490 return this.contract.methods.exchangeRateStored().call(tx);491 }492 fuseFeeMantissa(493 tx?: NonPayableTx494 ): Promise<string> {495 return this.contract.methods.fuseFeeMantissa().call(tx);496 }497 getAccountSnapshot(498 account: string,499 tx?: NonPayableTx500 ): Promise<{501 0: string;502 1: string;503 2: string;504 3: string;505 }> {506 return this.contract.methods.getAccountSnapshot(account).call(tx);507 }508 getCash(509 tx?: NonPayableTx510 ): Promise<string> {511 return this.contract.methods.getCash().call(tx);512 }513 "initialize(address,address,uint256,string,string,uint8,uint256,uint256)"(514 comptroller: ComptrollerV2 | string,515 interestRateModel: string,516 initialExchangeRateMantissa: number | string | BN,517 name: string,518 symbol: string,519 decimals: number | string | BN,520 reserveFactorMantissa: number | string | BN,521 adminFeeMantissa: number | string | BN,522 tx?: NonPayableTx523 ): PromiEvent<TransactionReceipt> {524 comptroller = comptroller instanceof ComptrollerV2 ? comptroller.address : comptroller;525 return this.contract.methods["initialize(address,address,uint256,string,string,uint8,uint256,uint256)"](comptroller, interestRateModel, initialExchangeRateMantissa, name, symbol, decimals, reserveFactorMantissa, adminFeeMantissa).send(tx);526 }527 "initialize(address,address,string,string,uint256,uint256)"(528 comptroller: ComptrollerV2 | string,529 interestRateModel: string,530 name: string,531 symbol: string,532 reserveFactorMantissa: number | string | BN,533 adminFeeMantissa: number | string | BN,534 tx?: NonPayableTx535 ): PromiEvent<TransactionReceipt> {536 comptroller = comptroller instanceof ComptrollerV2 ? comptroller.address : comptroller;537 return this.contract.methods["initialize(address,address,string,string,uint256,uint256)"](comptroller, interestRateModel, name, symbol, reserveFactorMantissa, adminFeeMantissa).send(tx);538 }539 540 interestRateModel(541 tx?: NonPayableTx542 ): Promise<string> {543 return this.contract.methods.interestRateModel().call(tx);544 }545 isCEther(546 tx?: NonPayableTx547 ): Promise<boolean> {548 return this.contract.methods.isCEther().call(tx);549 }550 isCToken(551 tx?: NonPayableTx552 ): Promise<boolean> {553 return this.contract.methods.isCToken().call(tx);554 }555 liquidateBorrow(556 borrower: string,557 cTokenCollateral: CTokenV2 | string,558 tx?: NonPayableTx559 ): PromiEvent<TransactionReceipt> {560 if(cTokenCollateral instanceof CTokenV2){561 cTokenCollateral = cTokenCollateral.address;562 }563 return this.contract.methods.liquidateBorrow(borrower, cTokenCollateral).send(tx);564 }565 mint(566 tx?: NonPayableTx567 ): PromiEvent<TransactionReceipt> {568 return this.contract.methods.mint().send(tx);569 }570 name(571 tx?: NonPayableTx572 ): Promise<string> {573 return this.contract.methods.name().call(tx);574 }575 protocolSeizeShareMantissa(576 tx?: NonPayableTx577 ): Promise<string> {578 return this.contract.methods.protocolSeizeShareMantissa().call(tx);579 }580 581 redeem(582 redeemTokens: number | string | BN,583 tx?: NonPayableTx584 ): PromiEvent<TransactionReceipt> {585 return this.contract.methods.redeem(redeemTokens).send(tx);586 }587 redeemUnderlying(588 redeemAdmount: number | string | BN,589 tx?: NonPayableTx590 ): PromiEvent<TransactionReceipt> {591 return this.contract.methods.redeemUnderlying(redeemAdmount).send(tx);592 }593 repayBorrow(594 tx?: NonPayableTx595 ): PromiEvent<TransactionReceipt> {596 return this.contract.methods.repayBorrow().send(tx);597 }598 repayBorrowBehalf(599 borrower: string,600 tx?: NonPayableTx601 ): PromiEvent<TransactionReceipt> {602 return this.contract.methods.repayBorrowBehalf(borrower).send(tx);603 }604 reserveFactorMantissa(605 tx?: NonPayableTx606 ): Promise<string> {607 return this.contract.methods.reserveFactorMantissa().call(tx);608 }609 seize(610 liquidator: string, 611 borrower: string,612 seizeTokens: number | string | BN,613 tx?: NonPayableTx614 ): PromiEvent<TransactionReceipt> {615 return this.contract.methods.seize(liquidator, borrower, seizeTokens).send(tx);616 }617 supplyRatePerBlock(618 tx?: NonPayableTx619 ): Promise<string> {620 return this.contract.methods.supplyRatePerBlock().call(tx);621 }622 symbol(623 tx?: NonPayableTx624 ): Promise<string> {625 return this.contract.methods.symbol().call(tx);626 }627 totalAdminFees(628 tx?: NonPayableTx629 ): Promise<string> {630 return this.contract.methods.totalAdminFees().call(tx);631 }632 totalBorrows(633 tx?: NonPayableTx634 ): Promise<string> {635 return this.contract.methods.totalBorrows().call(tx);636 }637 totalBorrowsCurrent(638 tx?: NonPayableTx639 ): Promise<string> {640 return this.contract.methods.totalBorrowsCurrent().call(tx);641 }642 totalFuseFees(643 tx?: NonPayableTx644 ): Promise<string> {645 return this.contract.methods.totalFuseFees().call(tx);646 }647 totalReserves(648 tx?: NonPayableTx649 ): Promise<string> {650 return this.contract.methods.totalReserves().call(tx);651 }652 totalSupply(653 tx?: NonPayableTx654 ): Promise<string> {655 return this.contract.methods.totalSupply().call(tx);656 }657 transfer(658 dst: string,659 amount: number | string | BN,660 tx?: NonPayableTx661 ): PromiEvent<TransactionReceipt> {662 return this.contract.methods.transfer(dst, amount).send(tx);663 }664 transferFrom(665 src: string,666 dst: string,667 amount: number | string | BN,668 tx?: NonPayableTx669 ): PromiEvent<TransactionReceipt> {670 return this.contract.methods.transferFrom(src, dst, amount).send(tx);671 }672 underlying(673 tx?: NonPayableTx674 ): Promise<string> {675 return this.contract.methods.underlying().call(tx);676 }677}...

Full Screen

Full Screen

wallet.js

Source:wallet.js Github

copy

Full Screen

1const ecdsa = require("elliptic"); // 타원곡선 디지털서명 알고리즘2const fs = require("fs");3const _ = require("lodash");4const TX = require("./transaction");5const EC = new ecdsa.ec("secp256k1");6const privateKeyLocation =7 process.env.PRIVATE_KEY || "miner1/wallet/private_key";8// 지갑에서 비밀키 가져오기9const getPrivateFromWallet = () => {10 // privateKeyLocation경로의 파일의 내용을 buffer에 담고 문자열로 반환11 const buffer = fs.readFileSync(privateKeyLocation, "utf8");12 return buffer.toString();13};14// 지갑에서 공개키 가져오기15const getPublicFromWallet = () => {16 // 내 비밀키를 가져와서17 const privateKey = getPrivateFromWallet();18 // 그 비밀키로부터 키쌍을 만들고19 const key = EC.keyFromPrivate(privateKey, "hex");20 // 그 키쌍으로부터 공개키를 만들어 16진수 형태(130자리)로 변환하여 반환21 return key.getPublic().encode("hex");22};23// 비밀키 생성24const generatePrivateKey = () => {25 // 키쌍을 생성해서26 const keyPair = EC.genKeyPair();27 // 그 키쌍으로부터 비밀키를 만들어28 const privateKey = keyPair.getPrivate();29 // 16진수 문자열로 반환30 return privateKey.toString(16);31};32// 지갑 초기화33const initWallet = () => {34 // 해당 경로에 비밀키가 존재하면 아무것도 안함35 if (fs.existsSync(privateKeyLocation)) {36 return;37 }38 // 지갑(비밀키)이 없으면 비밀키를 만들어서39 const newPrivateKey = generatePrivateKey();40 // 지갑 경로에 새로 파일을 만들고 파일 내용에 비밀키(16진수 64자리)를 기입해주기41 fs.writeFileSync(privateKeyLocation, newPrivateKey);42 console.log("새로 지갑 만들었어염 ->", privateKeyLocation);43};44// 지갑 삭제45const deleteWallet = () => {46 // 해당 경로에 지갑이 있으면47 if (fs.existsSync(privateKeyLocation)) {48 // 그 경로에 있는 지갑(private_key)49 fs.unlinkSync(privateKeyLocation);50 }51};52// 지갑 잔고 조회53const getBalance = (address, unspentTxOuts) => {54 // 미사용 트랜잭션에서 해당 지갑주소만 찾아서 합치기55 return _(findUnspentTxOuts(address, unspentTxOuts))56 .map((uTxO) => uTxO.amount)57 .sum();58};59// 미사용 트랜잭션 뒤지기60const findUnspentTxOuts = (ownerAddress, unspentTxOuts) => {61 // 미사용 트랜잭션에서 요구하는 지갑주소(ownerAddress)와 일치하는62 // 지갑주소들(uTxO.address) 찾아서 반환63 return _.filter(unspentTxOuts, (uTxO) => uTxO.address === ownerAddress);64};65// 지불할 금액에 대한 내 아웃풋들 찾기66const findTxOutsForAmount = (amount, myUnspentTxOuts) => {67 let currentAmount = 0; // 현재금액 068 const includedUnspentTxOuts = []; // 포함된 uTxOs69 // 내 uTxO 갯수만큼 반복70 for (const myUnspentTxOut of myUnspentTxOuts) {71 // 포함된uTxOs 목록에 해당 uTxO 넣기72 includedUnspentTxOuts.push(myUnspentTxOut);73 // 현재 금액에 해당 uTxO의 금액만큼 더해주기74 currentAmount = currentAmount + myUnspentTxOut.amount;75 // 현재 금액이 지불할 금액 이상이면 짤짤이가 생김76 if (currentAmount >= amount) {77 // 짤짤이 = 내 현재금액 - 지불할 금액78 const leftOverAmount = currentAmount - amount;79 // 포함된uTxOs, 짤짤이 반환80 return { includedUnspentTxOuts, leftOverAmount };81 }82 } /* 내uTxO들에 금액들이 각각 들어있는데83 그 금액들을 지불할 금액에 도달할 때까지 합치고84 합쳐진 uTxO들은 추후에 정산할때 한개의 uTxO가 될것이다85 예) 내 지갑에 12원짜리, 8원짜리 5원짜리, 30원짜리가 있다.86 내가 A에게 21원을 줘야 한다.87 12원짜리, 8원짜리, 5원짜리를 합치니 25원이다(25원>=21원)88 포함된uTxOs에는 12원짜리, 8원짜리, 5원짜리 uTxO가 들어가고89 짤짤이는 4원이 생긴다(25원-21원)90 포함된uTxOs는 추후에 공용장부에서 날려버릴것이고91 짤짤이는 추후에 나에게 4원을 보내는 아웃풋이 되어 공용장부에 들어갈것이다 */92 // 지불할 금액이 모자라면 메시지 출력93 const eMsg = "트랜잭션을 만들 수 없어요. uTxO가 모자라던가 금액이 모자라요";94 throw Error(eMsg);95};96// 트랜잭션에 들어갈 아웃풋들 만들기97const createTxOuts = (receiverAddress, myAddress, amount, leftOverAmount) => {98 // 받는이(receiverAddress)에게 얼마(amount) 주겠다고 아웃풋 생성99 const txOut1 = new TX.TxOut(receiverAddress, amount);100 // 주고 거슬러 받을 코인이 없으면 해당 아웃풋 그대로 반환101 if (leftOverAmount === 0) {102 return [txOut1];103 } else {104 // 거슬러 받아야 할 코인이 있으면105 // 내 지갑주소로 거슬러 받을 금액이 적힌 아웃풋도 같이 반환106 const leftOverTx = new TX.TxOut(myAddress, leftOverAmount);107 return [txOut1, leftOverTx];108 }109};110// 내 명의의 uTxO를 풀에 있는 tx와 비교하여 사용된 것 필터링 해주기111// (트랜잭션으로 이미 만들어져 풀에 들어가 있는 내 명의의 uTxO는)112// (블록이 채굴될 때까지 정산되지 않았으므로 또 풀에 들어갈 수 없다)113const filterTxPoolTxs = (unspentTxOuts, transactionPool) => {114 // 풀의 인풋들의 객체(txOutId, txOutIndex, signature)를 끄집어내서 배열로 저장115 const txIns = _(transactionPool)116 .map((tx) => tx.txIns)117 .flatten() // 배열 안의 배열을 1깊이? 1수준? 만큼 풀어주는 녀석118 .value(); // .flatten()의 결과는 객체임 .value()는 그 객체의 값을 추출하는녀석119 // .flatten().value() -> [ [[a],[b]],[c] ] -> [[a,b],c]120 // 제거할uTxO(removable)121 const removable = [];122 // 내 명의의 uTxO 갯수만큼 반복할거임123 for (const unspentTxOut of unspentTxOuts) {124 // 풀에서 끄집어낸 인풋들[]에서 해당uTxO와 일치하는것을 찾아서 txIn에 담기125 const txIn = _.find(txIns, (aTxIn) => {126 return (127 aTxIn.txOutIndex === unspentTxOut.txOutIndex &&128 aTxIn.txOutId === unspentTxOut.txOutId129 );130 });131 // 그 txIn이 undefined면(일치하는게 없으면)132 if (txIn === undefined) {133 } else {134 // 해당 uTxO를 제거할uTxO(removable)에 추가135 removable.push(unspentTxOut);136 }137 }138 // 장부에서 제거할uTxO들 제거하고 반환139 return _.without(unspentTxOuts, ...removable);140};141// 트랜잭션 만들어주기 / 매개변수는(받는이주소, 코인양, 비밀키, 공용장부, 트랜잭션풀)142const createTransaction = (143 receiverAddress,144 amount,145 privateKey,146 unspentTxOuts,147 txPool148) => {149 // 내 주소 = 내 비밀키를 가지고 만든 공개키150 const myAddress = TX.getPublicKey(privateKey);151 // 공용장부에서 내 명의로 된 uTxO들 가져오기152 const myUnspentTxOutsA = unspentTxOuts.filter(153 (uTxO) => uTxO.address === myAddress154 );155 // 내명의의uTxO들 중 아직 풀에 들어가지 않은 uTxO들을 변수myUnspentTxOuts에 저장156 const myUnspentTxOuts = filterTxPoolTxs(myUnspentTxOutsA, txPool);157 // 내uTxOs 에서 지불할 금액만큼 includedUnspentTxOuts(포함된uTxOs)랑158 // leftOverAmount(거스름돈) 만들어두기159 const { includedUnspentTxOuts, leftOverAmount } = findTxOutsForAmount(160 amount,161 myUnspentTxOuts162 );163 // 서명 없는 트랜잭션 인풋 만들기164 const toUnsignedTxIn = (unspentTxOut) => {165 const txIn = new TX.TxIn();166 txIn.txOutId = unspentTxOut.txOutId;167 txIn.txOutIndex = unspentTxOut.txOutIndex;168 return txIn;169 };170 // 포함된uTxOs로부터 인풋들 만들어서171 // unsignedTxIns(서명없는 트랜잭션인풋들 목록에 저장)172 const unsignedTxIns = includedUnspentTxOuts.map(toUnsignedTxIn);173 const tx = new TX.Transaction(); // 빈 트랜잭션 생성174 tx.txIns = unsignedTxIns; // 인풋들은 서명없는 트랜잭션인풋들을 넣고175 // 받는이에게 얼마보내는지의 아웃풋,176 // (거스름돈이 생기면)거스름돈을 나에게 보내는 아웃풋을 만들어177 // 트랜잭션의 아웃풋들(txOuts[])에 담기178 tx.txOuts = createTxOuts(receiverAddress, myAddress, amount, leftOverAmount);179 // 그러고 나서 인풋들(txIns)과 아웃풋들(txOuts)을 가지고 id만들어 담기180 tx.id = TX.getTransactionId(tx);181 // 내 비밀키를 가지고 서명 없이 담겨있는 인풋들에 서명 넣기182 tx.txIns = tx.txIns.map((txIn, index) => {183 txIn.signature = TX.signTxIn(tx, index, privateKey, unspentTxOuts);184 return txIn;185 });186 return tx; // 이렇게 완성된 트랜잭션 반환187};188module.exports = {189 createTransaction,190 getPublicFromWallet,191 getPrivateFromWallet,192 getBalance,193 generatePrivateKey,194 initWallet,195 deleteWallet,196 findUnspentTxOuts,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.tx(function(tx) {2 tx.executeSql("CREATE TABLE IF NOT EXISTS test (id unique, data)");3 tx.executeSql("INSERT INTO test (id, data) VALUES (1, 'First row')");4 tx.executeSql("INSERT INTO test (id, data) VALUES (2, 'Second row')");5 tx.executeSql("INSERT INTO test (id, data) VALUES (3, 'Third row')");6 tx.executeSql("INSERT INTO test (id, data) VALUES (4, 'Fourth row')");7 tx.executeSql("INSERT INTO test (id, data) VALUES (5, 'Fifth row')");8 tx.executeSql("INSERT INTO test (id, data) VALUES (6, 'Sixth row')");9 tx.executeSql("INSERT INTO test (id, data) VALUES (7, 'Seventh row')");10 tx.executeSql("INSERT INTO test (id, data) VALUES (8, 'Eighth row')");11 tx.executeSql("INSERT INTO test (id, data) VALUES (9, 'Ninth row')");12 tx.executeSql("INSERT INTO test (id, data) VALUES (10, 'Tenth row')");13 tx.executeSql("INSERT INTO test (id, data) VALUES (11, 'Eleventh row')");14 tx.executeSql("INSERT INTO test (id, data) VALUES (12, 'Twelfth row')");15 tx.executeSql("INSERT INTO test (id, data) VALUES (13, 'Thirteenth row')");16 tx.executeSql("INSERT INTO test (id, data) VALUES (14, 'Fourteenth row')");17 tx.executeSql("INSERT INTO test (id, data) VALUES (15, 'Fifteenth row')");18 tx.executeSql("INSERT INTO test (id, data) VALUES (16, 'Sixteenth row')");19 tx.executeSql("INSERT INTO test (id, data) VALUES (17, 'Seventeenth row')");20 tx.executeSql("INSERT INTO test (id, data) VALUES (18, 'Eighteenth row')");21 tx.executeSql("INSERT INTO test (id, data) VALUES (19, 'Nineteenth row')");22 tx.executeSql("INSERT INTO test (id, data) VALUES (20, 'Twentieth row')");23 tx.executeSql("INSERT INTO test (id, data) VALUES (21, 'Twenty-first row')");24 tx.executeSql("INSERT INTO test (id

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org', 'A.12345678901234567890123456789012');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('Test submitted. Polling for results...');7 test.waitForTestRun(data.data.testId, function(err, data) {8 if (err) {9 console.log('Error: ' + err);10 } else {11 console.log('Test results: ' + data.data.summary);12 }13 });14 }15});16var wpt = require('webpagetest');17var test = new wpt('www.webpagetest.org', 'A.12345678901234567890123456789012');18 if (err) {19 console.log('Error: ' + err);20 } else {21 console.log('Test submitted. Polling for results...');22 test.waitForTestRun(data.data.testId, function(err, data) {23 if (err) {24 console.log('Error: ' + err);25 } else {26 console.log('Test results: ' + data.data.summary);27 }28 });29 }30});31var wpt = require('webpagetest');32var test = new wpt('www.webpagetest.org', 'A.12345678901234567890123456789012');33 if (err) {34 console.log('Error: ' + err);35 } else {36 console.log('Test submitted. Polling for results...');37 test.waitForTestRun(data.data.testId, function(err, data) {38 if (err) {39 console.log('Error: ' + err);40 } else {41 console.log('Test results: ' + data.data.summary);42 }43 });44 }45});46var wpt = require('webpagetest');47var test = new wpt('www.webpagetest.org', '

Full Screen

Using AI Code Generation

copy

Full Screen

1function tx() {2 var tx = document.getElementById("tx");3 if (tx.value == "0") {4 tx.value = "1";5 } else {6 tx.value = "0";7 }8 wpt.tx(tx.value);9}10function rx() {11 var rx = document.getElementById("rx");12 if (rx.value == "0") {13 rx.value = "1";14 } else {15 rx.value = "0";16 }17 wpt.rx(rx.value);18}19function txrx() {20 var txrx = document.getElementById("txrx");21 if (txrx.value == "0") {22 txrx.value = "1";23 } else {24 txrx.value = "0";25 }26 wpt.txrx(txrx.value);27}28function txrx() {29 var txrx = document.getElementById("txrx");30 if (txrx.value == "0") {31 txrx.value = "1";32 } else {33 txrx.value = "0";34 }35 wpt.txrx(txrx.value);36}37function txrx() {38 var txrx = document.getElementById("txrx");39 if (txrx.value == "0") {40 txrx.value = "1";41 } else {42 txrx.value = "0";43 }44 wpt.txrx(txrx.value);45}46function txrx() {47 var txrx = document.getElementById("txrx");48 if (txrx.value == "0") {49 txrx.value = "1";50 } else {51 txrx.value = "0";52 }53 wpt.txrx(txrx.value);54}55function txrx() {56 var txrx = document.getElementById("txrx");57 if (txrx.value == "0") {58 txrx.value = "1";59 } else {60 txrx.value = "0";61 }62 wpt.txrx(txrx.value);63}64function txrx() {65 var txrx = document.getElementById("txrx");66 if (txrx.value == "0

Full Screen

Using AI Code Generation

copy

Full Screen

1var webpagetest = require('webpagetest');2var wpt = new webpagetest('www.webpagetest.org', 'A.3f3b8a7b0f0b9d7a9a9c8f9b6e1e1a1e');3 if (err) return console.error(err);4 console.log('Test ID: %s', data.data.testId);5 wpt.getTestResults(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log('Test completed in %d seconds', data.data.average.firstView.loadTime);8 console.log('View the test at %s', data.data.userUrl);9 });10});11var wpt = new webpagetest('www.webpagetest.org', 'A.3f3b8a7b0f0b9d7a9a9c8f9b6e1e1a1e');12 if (err) return console.error(err);13 console.log('Test ID: %s', data.data.testId);14 wpt.getTestResults(data.data.testId, function(err, data) {15 if (err) return console.error(err);16 console.log('Test completed in %d seconds', data.data.average.firstView.loadTime);17 console.log('View the test at %s', data.data.userUrl);18 });19});20var webpagetest = require('webpagetest');21var wpt = new webpagetest('www.webpagetest.org', 'A.3f3b8a7b0f0b9d7a9a9c8f9b6e1e1a1e');22 if (err) return console.error(err);

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