require ( 'dotenv' ) . config ( ) ; import TransactionService from 'core/service/transaction' ; import SharedTransactionRepo from 'shared/repository/transaction' ; import BlockService from 'core/service/block' ; import { IAsset , SerializedTransaction , Transaction , TransactionModel , TransactionType } from 'shared/model/transaction' ; import { ed } from 'shared/util/ed' ; import crypto from 'crypto' ; import fs from 'fs' ; import path from 'path' ; const DIR = path . resolve ( __dirname ) ; const SECRET = 'pre worry asd thank unfair lukas smile oven gospel less latin reason' ; const rawAccounts = [ { address : BigInt ( '12384687466662805891' ) , publicKey : '49a2b5e68f851a11058748269a276b0c0d36497215548fb40d4fe4e929d0283a' } , { address : BigInt ( '4995063339468361088' ) , publicKey : 'f4ae589b02f97e9ab5bce61cf187bcc96cfb3fdf9a11333703a682b7d47c8dc2' } , { address : BigInt ( '933553974927686133' ) , publicKey : '83cb3d8641c8e73735cc1b70c915602ffcb6e5a68f14a71056511699050a1a05' } , { address : BigInt ( '3002421063889966908' ) , publicKey : 'f959e6c8d279c97d3ec5ba993f04ab740a6e50bec4aad75a8a1e7808a6c5eec7' } , { address : BigInt ( '7897332094363171058' ) , publicKey : '137b9f0f839ab3ecd2146bfecd64d31e127d79431211e352bedfeba5fd61a57a' } ] ; const rawTransactions = [ { trs : { type : TransactionType . SEND , senderPublicKey : '49a2b5e68f851a11058748269a276b0c0d36497215548fb40d4fe4e929d0283a' , asset : { amount : 4500000000000000 , recipientAddress : BigInt ( '4995063339468361088' ) } } , privateKey : 'sad case cement sign ghost bamboo soap depart discover acoustic spot toilet' } , { trs : { type : TransactionType . SEND , senderPublicKey : 'f4ae589b02f97e9ab5bce61cf187bcc96cfb3fdf9a11333703a682b7d47c8dc2' , asset : { amount : 171000000000000 , recipientAddress : BigInt ( '933553974927686133' ) } } , privateKey : SECRET } , { trs : { type : TransactionType . SEND , senderPublicKey : 'f4ae589b02f97e9ab5bce61cf187bcc96cfb3fdf9a11333703a682b7d47c8dc2' , asset : { amount : 36000000000000 , recipientAddress : BigInt ( '3002421063889966908' ) } } , privateKey : SECRET } , { trs : { type : TransactionType . SEND , senderPublicKey : 'f4ae589b02f97e9ab5bce61cf187bcc96cfb3fdf9a11333703a682b7d47c8dc2' , asset : { amount : 90000000000000 , recipientAddress : BigInt ( '7897332094363171058' ) } } , privateKey : SECRET } , { trs : { type : TransactionType . DELEGATE , senderPublicKey : '83cb3d8641c8e73735cc1b70c915602ffcb6e5a68f14a71056511699050a1a05' , asset : { username : 'DELEGATE1' } } , privateKey : 'milk exhibit cabbage detail village hero script glory tongue post clinic wish' } , { trs : { type : TransactionType . DELEGATE , senderPublicKey : 'f959e6c8d279c97d3ec5ba993f04ab740a6e50bec4aad75a8a1e7808a6c5eec7' , asset : { username : 'DELEGATE2' } } , privateKey : 'artwork relax sheriff sting fruit return spider reflect cupboard dice goddess slice' } , { trs : { type : TransactionType . DELEGATE , senderPublicKey : '137b9f0f839ab3ecd2146bfecd64d31e127d79431211e352bedfeba5fd61a57a' , asset : { username : 'DELEGATE3' } } , privateKey : 'whale slab bridge virus merry ship bright fiber power outdoor main enforce' } , ] ; const hash = crypto . createHash ( 'sha256' ) . update ( SECRET , 'utf8' ) . digest ( ) ; const keyPair = ed . makeKeyPair ( hash ) ; const transactions = rawTransactions . map ( ( rawTransaction ) => { rawTransaction . trs . createdAt = 0 ; const response = TransactionService . create ( rawTransaction . trs , keyPair ) ; return response . data ; } ) ; let block = BlockService . create ( { transactions , timestamp : 0 , previousBlock : { id : null } , keyPair } ) ; block . height = 1 ; block = BlockService . addPayloadHash ( block , keyPair ) . data ; const resultTransactions = block . transactions . map ( ( transaction ) => { transaction . blockId = block . id ; return SharedTransactionRepo . serialize ( transaction ) ; } ) ; block . transactions = < Array < SerializedTransaction < IAsset > > > resultTransactions as any ; console . log ( block ) ; fs . writeFileSync ( path . resolve ( DIR , '..' , 'genesisBlock_' + Date . now ( ) . toString ( ) + '.json' ) , JSON . stringify ( block ) ) ;