-
Notifications
You must be signed in to change notification settings - Fork 11
/
transactionsPerSecond.js
68 lines (47 loc) · 1.6 KB
/
transactionsPerSecond.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const BigchainDB = require('bigchaindb-driver')
const schedule = require('node-schedule')
const bip39 = require('bip39')
const sizeof = require('object-sizeof');
const API_PATH = 'http://localhost:9984/api/v1/'
const conn = new BigchainDB.Connection(API_PATH, {
app_id: '',
app_key: ''
})
const user = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('seedPhrase').slice(0, 32))
// Execute ever x seconds: '*/15 * * * * *'
let count = 0
const numTransactions = 60
var j = schedule.scheduleJob('*/1 * * * * *', function () {
const ua = postTransactions(numTransactions)
count++
console.log(count)
})
const longAsset = 'testexapme'.repeat(400)
async function postTransactions(nTx) {
for (i = 0; i < nTx; i++) {
const windAsset = {
'timeStamp': JSON.stringify(new Date()),
'example': 'simpleAsseet'
}
await sendToBigchainDB(windAsset, user, i, nTx)
}
return true
}
function sendToBigchainDB(asset, keypair, count, nTx) {
const txSimpleAsset = BigchainDB.Transaction.makeCreateTransaction(
asset,
{
'metadata': 'sdfs'
},
// counterparty is the owner
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(keypair.publicKey))],
keypair.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(txSimpleAsset, keypair.privateKey)
// console.log(txSigned.id)
// console.log(sizeof(txSigned))
//console.log(JSON.stringify(txSigned))
conn.postTransaction(txSigned)
}