Skip to content

Instantly share code, notes, and snippets.

@eatonphil
Last active September 15, 2022 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eatonphil/3bceb01e603ea0edcae16217c592c2fb to your computer and use it in GitHub Desktop.
Save eatonphil/3bceb01e603ea0edcae16217c592c2fb to your computer and use it in GitHub Desktop.
TigerBeetle client
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