Last active
September 15, 2022 19:02
TigerBeetle client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('node:assert/strict'); | |
const { createClient } = require('tigerbeetle-node'); | |
async function run() { | |
const client = createClient({ cluster_id: 0, replica_addresses: ['3000'] }); | |
// Create two accounts | |
let errors = await client.createAccounts([ | |
{ | |
id: 1n, | |
ledger: 1, | |
code: 1, | |
user_data: 0n, | |
reserved: Buffer.alloc(48, 0), | |
flags: 0, | |
debits_pending: 0n, | |
debits_posted: 0n, | |
credits_pending: 0n, | |
credits_posted: 0n, | |
timestamp: 0n, | |
}, | |
{ | |
id: 2n, | |
ledger: 1, | |
code: 1, | |
user_data: 0n, | |
reserved: Buffer.alloc(48, 0), | |
flags: 0, | |
debits_pending: 0n, | |
debits_posted: 0n, | |
credits_pending: 0n, | |
credits_posted: 0n, | |
timestamp: 0n, | |
}, | |
]); | |
assert.equal(errors.length, 0, 'Error creating accounts'); | |
const TRANSFERS = 100_000_000; | |
for (let i = 0; i < TRANSFERS; i++) { | |
//if (i % 100_000 == 0) { | |
console.log(`${i} transfers sent\t\t\t\t${i / TRANSFERS}%`); | |
//} | |
errors = await client.createTransfers([ | |
{ | |
id: BigInt(i+1), | |
debit_account_id: 1n, | |
credit_account_id: 2n, | |
pending_id: 0n, | |
user_data: 0n, | |
reserved: 0n, | |
timeout: 0n, | |
ledger: 1, | |
code: 1, | |
flags: 0, | |
amount: 10n, | |
timestamp: 0n, | |
} | |
]); | |
console.log(errors); | |
assert.equal(errors.length, 0, 'Error creating transfers'); | |
} | |
} | |
run().then(() => process.exit(0)).catch((e) => {console.error(e); process.exit(1); }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment