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.
37 lines
1.3 KiB
37 lines
1.3 KiB
6 years ago
|
package txgen
|
||
|
|
||
|
import (
|
||
6 years ago
|
"math/big"
|
||
6 years ago
|
"math/rand"
|
||
6 years ago
|
|
||
6 years ago
|
"github.com/ethereum/go-ethereum/crypto"
|
||
|
"github.com/ethereum/go-ethereum/params"
|
||
|
"github.com/harmony-one/harmony/core/types"
|
||
|
"github.com/harmony-one/harmony/node"
|
||
|
)
|
||
|
|
||
6 years ago
|
// Settings is the settings for TX generation.
|
||
|
type Settings struct {
|
||
6 years ago
|
NumOfAddress int
|
||
|
CrossShard bool
|
||
|
MaxNumTxsPerBatch int
|
||
|
CrossShardRatio int
|
||
|
}
|
||
|
|
||
6 years ago
|
// GenerateSimulatedTransactionsAccount generates simulated transaction for account model.
|
||
6 years ago
|
func GenerateSimulatedTransactionsAccount(shardID int, dataNodes []*node.Node, setting Settings) (types.Transactions, types.Transactions) {
|
||
6 years ago
|
_ = setting // TODO: take use of settings
|
||
|
node := dataNodes[shardID]
|
||
6 years ago
|
txs := make([]*types.Transaction, 100)
|
||
6 years ago
|
for i := 0; i < 100; i++ {
|
||
|
baseNonce := node.Worker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(node.TestBankKeys[i].PublicKey))
|
||
6 years ago
|
for j := 0; j < 1; j++ {
|
||
6 years ago
|
randomUserAddress := crypto.PubkeyToAddress(node.TestBankKeys[rand.Intn(100)].PublicKey)
|
||
|
randAmount := rand.Float32()
|
||
6 years ago
|
tx, _ := types.SignTx(types.NewTransaction(baseNonce+uint64(j), randomUserAddress, uint32(shardID), big.NewInt(int64(params.Ether*randAmount)), params.TxGas, nil, nil), types.HomesteadSigner{}, node.TestBankKeys[i])
|
||
6 years ago
|
txs[i*1+j] = tx
|
||
6 years ago
|
}
|
||
|
}
|
||
|
return txs, nil
|
||
|
}
|