Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

start.ts 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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(`balance of sender = ${balance1}, balance of receiver = ${balance2}`);
  49. // token.on(token.filters.Transfer, async (...args) => {
  50. // const lastArg = args[args.length - 1];
  51. // console.log(lastArg);
  52. // console.log('on transfer by partition');
  53. // })
  54. let nonce = await getNonce(issuer.address);
  55. let txids = [];
  56. let proms = [];
  57. let firstTx:string = null;
  58. let lastTx:string = null;
  59. const start = Date.now();
  60. console.log(`sending ${count} transactions`);
  61. for(let i = 0; i < count; i++) {
  62. const tx = await token.operatorTransferByPartition.populateTransaction(
  63. partitions[0],
  64. from.address,
  65. to.address,
  66. amount,
  67. ZeroHash,
  68. ZeroHash,
  69. {
  70. // gasPrice: 0,
  71. gasLimit: 2100000,
  72. nonce: nonce,
  73. type: 2,
  74. chainId: 1337
  75. }
  76. );
  77. ++nonce;
  78. // console.log(tx);
  79. const signed = await issuer.signTransaction(tx);
  80. const pm = provider.send('eth_sendRawTransaction',[signed]);
  81. if(i == 0) {
  82. firstTx = keccak256(signed);
  83. }
  84. if (i == count -1) {
  85. lastTx = keccak256(signed);
  86. }
  87. proms.push(pm);
  88. }
  89. let txs = await Promise.all(proms);
  90. const elapsed = getElapsed(start,1000);
  91. console.log(`all tx sent in ${elapsed} seconds`);
  92. console.log(`first Tx = ${firstTx}`);
  93. console.log(`last Tx = ${lastTx}`);
  94. let txMap = new Map<string,boolean>();
  95. txs.forEach(txid => {
  96. // txids.push({txid: txid});
  97. txMap.set(txid,false);
  98. });
  99. const blockHashes = await checkReceipt2(txMap,[firstTx as string, lastTx as string], 'wait for receipt...');
  100. const firstBlockHash = blockHashes.get(firstTx);
  101. const lastBlockHash = blockHashes.get(lastTx);
  102. console.log(`firstBlockHash = ${firstBlockHash} \nlastBlockHash = ${lastBlockHash}`);
  103. const lastB = await getBlockInfo(lastBlockHash);
  104. // console.log(lastB.timestamp);
  105. const lastTimeStamp = parseInt(lastB.timestamp,16);
  106. balance1= await token.balanceOf(from);
  107. balance2 = await token.balanceOf(to);
  108. console.log(`balance of sender = ${balance1}, balance of receiver = ${balance2}`);
  109. const d = new Date(lastTimeStamp * 1000);
  110. console.log(d);
  111. console.log(start);
  112. console.log(lastTimeStamp * 1000);
  113. const tps = calc.CTPS(count,start,lastTimeStamp * 1000);
  114. console.log(`CTPS = ${tps}`);
  115. }
  116. const calc = new Calulator();
  117. const rpcUrl = process.env.RPCURL;
  118. const provider = new JsonRpcProvider(rpcUrl);
  119. setProvider(provider);
  120. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  121. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  122. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  123. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  124. async function main() {
  125. // console.log(admin);
  126. // console.log(issuer);
  127. console.log(holder1);
  128. console.log(holder2);
  129. transfer('test001',holder1, holder2,1, 10000);
  130. }
  131. main();