|
| 1 | +const { Block, Blockchain, Transaction} = require("./src/blockchain") |
| 2 | +const EC = require('elliptic').ec; |
| 3 | +const ec = new EC('secp256k1'); |
| 4 | + |
| 5 | +// const Generate = require("./src/keygenerator"); |
| 6 | +// console.log("generate",Generate()); |
| 7 | + |
| 8 | +// Your private key goes here |
| 9 | +const myKey = ec.keyFromPrivate('765e1d5fed37306154d66a4da0f97e09e8bc21e8d615fe084aab3a0439ee37bc'); |
| 10 | + |
| 11 | +// From that we can calculate your public key (which doubles as your wallet address) |
| 12 | +const myWalletAddress = myKey.getPublic('hex'); |
| 13 | + |
| 14 | +// Create new instance of Blockchain class |
| 15 | +const AnilCoin = new Blockchain() |
| 16 | + |
| 17 | +// Mine first block |
| 18 | +console.log("\nStarting the miner...."); |
| 19 | +AnilCoin.minePendingTransactions(myWalletAddress); |
| 20 | +console.log("\nBalance of Anil is : ", AnilCoin.getBalanceOfAddress(myWalletAddress)); |
| 21 | + |
| 22 | + |
| 23 | +// Create a transaction & sign it with your key |
| 24 | +const tx1 = new Transaction(myWalletAddress, 'public key goes here', 5); |
| 25 | +tx1.signTransaction(myKey); |
| 26 | +AnilCoin.addTransaction(tx1); |
| 27 | + |
| 28 | +AnilCoin.minePendingTransactions(myWalletAddress); |
| 29 | +console.log("\nBalance of Anil is : ", AnilCoin.getBalanceOfAddress(myWalletAddress)); |
| 30 | + |
| 31 | + |
| 32 | +const tx2 = new Transaction(myWalletAddress, 'address1', 50); |
| 33 | +tx2.signTransaction(myKey); |
| 34 | +AnilCoin.addTransaction(tx2); |
| 35 | + |
| 36 | +// Mine block |
| 37 | +AnilCoin.minePendingTransactions(myWalletAddress); |
| 38 | +console.log("\nBalance of Anil is : ", AnilCoin.getBalanceOfAddress(myWalletAddress)); |
| 39 | + |
| 40 | + |
| 41 | +const tx3 = new Transaction(myWalletAddress, 'address1', 45); |
| 42 | +tx3.signTransaction(myKey); |
| 43 | +AnilCoin.addTransaction(tx3); |
| 44 | + |
| 45 | +//// Mine block |
| 46 | +AnilCoin.minePendingTransactions(myWalletAddress); |
| 47 | +console.log("\nBalance of Anil is : ", AnilCoin.getBalanceOfAddress(myWalletAddress)); |
| 48 | + |
| 49 | +// Change the data |
| 50 | +//AnilCoin.blockchain[2].transactions[0].amount =50 |
| 51 | +console.log("\nTotal Transaction of Anil is : ", AnilCoin.getAllTransactionsForWallet(myWalletAddress).length,"\n"); |
| 52 | +console.log("Is BlockChain Valid ?", AnilCoin.validateChainIntegrity()); |
| 53 | +//console.log(AnilCoin); |
| 54 | +//console.log(JSON.stringify(AnilCoin, null, 5)) |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +// Create Transaction Section |
| 62 | +//AnilCoin.createTransaction(new Transaction("address1", "address2",100)); |
| 63 | +//AnilCoin.createTransaction(new Transaction("address2", "address1",50)); |
| 64 | +// |
| 65 | +//console.log("\n Starting the miner...."); |
| 66 | +//AnilCoin.minePendingTransactions("Anil-address") |
| 67 | +// |
| 68 | +//console.log("\n Balance of Anil is : ", AnilCoin.getBalanceOfAddress("Anil-address")); |
| 69 | +// |
| 70 | +//console.log("\n Starting the miner Again...."); |
| 71 | +//AnilCoin.minePendingTransactions("Anil-address") |
| 72 | +// |
| 73 | +//console.log("\n Balance of Anil is : ", AnilCoin.getBalanceOfAddress("Anil-address")); |
| 74 | +//console.log(AnilCoin); |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +//console.log("Mining AnilCoin in progress..."); |
| 84 | +// Add new Block |
| 85 | +//console.log("Mining New Block......."); |
| 86 | +//AnilCoin.addNewBlock( |
| 87 | +// new Block("30/08/2022", |
| 88 | +// { sender:"Anil Patidar", |
| 89 | +// recipient:"Ajay Dangi", |
| 90 | +// quantity:25 |
| 91 | +// }) |
| 92 | +//); |
| 93 | +// |
| 94 | +//AnilCoin.addNewBlock( |
| 95 | +// new Block("30/08/2022", |
| 96 | +// { sender:"Jitu", |
| 97 | +// recipient:"Anurag", |
| 98 | +// quantity:50 |
| 99 | +// }) |
| 100 | +//); |
| 101 | +// |
| 102 | +//console.log("Is BlockChain Valid ?", AnilCoin.validateChainIntegrity()); |
| 103 | +// |
| 104 | +//AnilCoin.addNewBlock( |
| 105 | +// new Block("30/08/2022", |
| 106 | +// { sender:"Ram", |
| 107 | +// recipient:"Gaurav", |
| 108 | +// quantity:10 |
| 109 | +// }) |
| 110 | +//); |
| 111 | + |
| 112 | +// update blockchain data n check its valid or not |
| 113 | +// AnilCoin.blockchain[1].data = { |
| 114 | +// AnilCoin.blockchain[1].transactions = { |
| 115 | +// sender:"Ram", |
| 116 | +// recipient:"Gaurav", |
| 117 | +// quantity:40 |
| 118 | +// }; |
| 119 | +// |
| 120 | +// AnilCoin.blockchain[1].hash = AnilCoin.blockchain[1].generateHash() |
| 121 | + |
| 122 | +//console.log("Is BlockChain Valid ?", AnilCoin.validateChainIntegrity()); |
| 123 | + |
| 124 | +//console.log(AnilCoin); |
| 125 | +//console.log(JSON.stringify(AnilCoin, null, 5)) |
0 commit comments