Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

start.ts 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import * as dotevnv from "dotenv"
  2. import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
  3. ,Transaction,formatEther,
  4. ZeroHash,ethers,keccak256
  5. } from 'ethers'
  6. import {Calulator} from "../inc/calc";
  7. import { TokenIssuer } from "../inc/TokenIssuer";
  8. import {
  9. SecurityToken,
  10. SecurityToken__factory,
  11. } from '../typechain'
  12. // import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
  13. import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses,
  14. getElapsed, sleep,getBlockInfo} from '../inc/util'
  15. dotevnv.config();
  16. if (!process.env.RPCURL) {
  17. console.log(`No rpcur value specified...`)
  18. }
  19. console.log(`목적 서버 : ${process.env.RPCURL}`);
  20. async function getNonce(addr: string): Promise<number> {
  21. const nonce = await provider.getTransactionCount(addr);
  22. return nonce;
  23. }
  24. async function info(symbol: string) {
  25. const proxy = getDeploymentAddresses(symbol).address;
  26. console.log(`토큰 주소 : ${proxy}`);
  27. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  28. await token.connect(admin);
  29. const ops = await token.operators();
  30. console.log(ops);
  31. // token.grantRole(keccak256('OPERATOR_ROLE'),'0xaaa')
  32. }
  33. async function transfer(symbol:string,from: Wallet, to: Wallet, amount: number = 1, count: number = 10) {
  34. const proxy = getDeploymentAddresses(symbol).address;
  35. console.log(`토큰 주소 : ${proxy}`);
  36. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  37. await token.connect(admin);
  38. // const ops = await token.operators();
  39. // console.log(ops);
  40. let balance1= await token.balanceOf(from);
  41. let balance2 = await token.balanceOf(to);
  42. const b = await token.isTokenHolderKYC(from);
  43. if(!b) {
  44. console.log('holder kyc error');
  45. return;
  46. }
  47. const partitions = await token.getDefaultPartitions();
  48. console.log('###################### 전송전 ###################################')
  49. console.log(`balance of sender = ${balance1}, balance of receiver = ${balance2}`);
  50. // token.on(token.filters.Transfer, async (...args) => {
  51. // const lastArg = args[args.length - 1];
  52. // console.log(lastArg);
  53. // console.log('on transfer by partition');
  54. // })
  55. let nonce = await getNonce(signer.address);
  56. let txids = [];
  57. let proms = [];
  58. let firstTx:string = null;
  59. let lastTx:string = null;
  60. const start = Date.now();
  61. //console.log(`전송시작 시간 : `,new Date(start));
  62. console.log(`sending ${count} transactions`);
  63. for(let i = 0; i < count; i++) {
  64. const tx = await token.operatorTransferByPartition.populateTransaction(
  65. partitions[0],
  66. from.address,
  67. to.address,
  68. amount,
  69. ZeroHash,
  70. ZeroHash,
  71. {
  72. // gasPrice: 0,
  73. gasLimit: 2100000,
  74. nonce: nonce,
  75. type: 2,
  76. chainId: 1337
  77. }
  78. );
  79. ++nonce;
  80. // console.log(tx);
  81. const signed = await signer.signTransaction(tx);
  82. const pm = provider.send('eth_sendRawTransaction',[signed]);
  83. if(i == 0) {
  84. firstTx = keccak256(signed);
  85. }
  86. if (i == count -1) {
  87. lastTx = keccak256(signed);
  88. }
  89. proms.push(pm);
  90. }
  91. let txs = await Promise.all(proms);
  92. const elapsed = getElapsed(start,1000);
  93. console.log(`all tx sent in ${elapsed} seconds`);
  94. console.log(`first Tx = ${firstTx}`);
  95. console.log(`last Tx = ${lastTx}`);
  96. let txMap = new Map<string,boolean>();
  97. txs.forEach(txid => {
  98. // txids.push({txid: txid});
  99. txMap.set(txid,false);
  100. });
  101. const blockHashes = await checkReceipt2(txMap,[firstTx as string, lastTx as string], 'wait for receipt...');
  102. const firstBlockHash = blockHashes.get(firstTx);
  103. const lastBlockHash = blockHashes.get(lastTx);
  104. console.log(`firstBlockHash = ${firstBlockHash} \nlastBlockHash = ${lastBlockHash}`);
  105. const lastB = await getBlockInfo(lastBlockHash);
  106. // console.log(lastB.timestamp);
  107. const lastTimeStamp = parseInt(lastB.timestamp,16);
  108. balance1= await token.balanceOf(from);
  109. balance2 = await token.balanceOf(to);
  110. console.log(`balance of sender = ${balance1}, balance of receiver = ${balance2}`);
  111. const d = new Date(lastTimeStamp * 1000);
  112. console.log(d);
  113. console.log(start);
  114. console.log(lastTimeStamp * 1000);
  115. const tps = calc.CTPS(count,start,lastTimeStamp * 1000);
  116. console.log(`CTPS = ${tps}`);
  117. }
  118. const calc = new Calulator();
  119. const rpcUrl = process.env.RPCURL;
  120. const provider = new JsonRpcProvider(rpcUrl);
  121. setProvider(provider);
  122. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  123. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  124. // const signer = new Wallet('0x55d1000aa2057a878b5f7902158615f889cb1e9b811f7e1e9c0b4518399ba84a',provider);
  125. const signer = issuer;
  126. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  127. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  128. async function main() {
  129. // console.log(admin);
  130. // console.log(issuer);
  131. console.log(holder1);
  132. console.log(holder2);
  133. transfer('test001',holder2, holder1,1, 1000);
  134. }
  135. main();