You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 transfer(symbol:string, count: number = 10) {
  25. const proxy = getDeploymentAddresses(symbol).address;
  26. console.log(`토큰 주소 : ${proxy}`);
  27. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  28. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  29. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  30. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  31. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  32. await token.connect(admin);
  33. // const ops = await token.operators();
  34. // console.log(ops);
  35. let balance1= await token.balanceOf(holder1);
  36. let balance2 = await token.balanceOf(holder2);
  37. const b = await token.isTokenHolderKYC(holder1);
  38. if(!b) {
  39. console.log('holder kyc error');
  40. return;
  41. }
  42. const partitions = await token.getDefaultPartitions();
  43. console.log(`holder1(sender) = ${balance1}, holder2(receiver) = ${balance2}`);
  44. // token.on(token.filters.Transfer, async (...args) => {
  45. // const lastArg = args[args.length - 1];
  46. // console.log(lastArg);
  47. // console.log('on transfer by partition');
  48. // })
  49. let nonce = await getNonce(issuer.address);
  50. let txids = [];
  51. let proms = [];
  52. let firstTx:string = null;
  53. let lastTx:string = null;
  54. const start = Date.now();
  55. console.log(`sending ${count} transactions`);
  56. for(let i = 0; i < count; i++) {
  57. const tx = await token.operatorTransferByPartition.populateTransaction(
  58. partitions[0],
  59. holder1.address,
  60. holder2.address,
  61. 1,
  62. ZeroHash,
  63. ZeroHash,
  64. {
  65. // gasPrice: 0,
  66. gasLimit: 2100000,
  67. nonce: nonce,
  68. type: 2,
  69. chainId: 1337
  70. }
  71. );
  72. ++nonce;
  73. // console.log(tx);
  74. const signed = await issuer.signTransaction(tx);
  75. const pm = provider.send('eth_sendRawTransaction',[signed]);
  76. if(i == 0) {
  77. firstTx = keccak256(signed);
  78. }
  79. if (i == count -1) {
  80. lastTx = keccak256(signed);
  81. }
  82. proms.push(pm);
  83. }
  84. let txs = await Promise.all(proms);
  85. const elapsed = getElapsed(start,1000);
  86. console.log(`all tx sent in ${elapsed} seconds`);
  87. console.log(`first Tx = ${firstTx}`);
  88. console.log(`last Tx = ${lastTx}`);
  89. let txMap = new Map<string,boolean>();
  90. txs.forEach(txid => {
  91. // txids.push({txid: txid});
  92. txMap.set(txid,false);
  93. });
  94. const blockHashes = await checkReceipt2(txMap,[firstTx as string, lastTx as string], 'wait for receipt...');
  95. const firstBlockHash = blockHashes.get(firstTx);
  96. const lastBlockHash = blockHashes.get(lastTx);
  97. console.log(`firstBlockHash = ${firstBlockHash} , lastBlockHash = ${lastBlockHash}`);
  98. const lastB = await getBlockInfo(lastBlockHash);
  99. console.log(lastB.timestamp);
  100. const lastTimeStamp = parseInt(lastB.timestamp,16);
  101. balance1= await token.balanceOf(holder1);
  102. balance2 = await token.balanceOf(holder2);
  103. console.log(`holder1 = ${balance1}, holder2 = ${balance2}`);
  104. const d = new Date(lastTimeStamp * 1000);
  105. console.log(d);
  106. console.log(start);
  107. console.log(lastTimeStamp * 1000);
  108. const tps = calc.CTPS_NUM(count,start,lastTimeStamp * 1000);
  109. console.log(tps);
  110. }
  111. const calc = new Calulator();
  112. const rpcUrl = process.env.RPCURL;
  113. const provider = new JsonRpcProvider(rpcUrl);
  114. setProvider(provider);
  115. async function main() {
  116. transfer('test001',1000);
  117. // for(let i = 13489; i < 13492; i++ ) {
  118. // try {
  119. // await send(i);
  120. // } catch(ex) {
  121. // console.log(ex);
  122. // }
  123. // await sleep(10);
  124. // }
  125. }
  126. main();