Code for this sample is in ./main.js.
Linux >= 5.6 is the only production environment we support. But for ease of development we also support macOS and Windows.
- NodeJS >=
18
First, clone this repo and cd
into tigerbeetle/src/clients/node/samples/two-phase-many
.
Then, install the TigerBeetle client:
npm install tigerbeetle-node
Follow steps in the repo README to run TigerBeetle.
If you are not running on port localhost:3000
, set
the environment variable TB_ADDRESS
to the full
address of the TigerBeetle server you started.
Now you can run this sample:
node main.js
Here's what this project does.
This project starts by creating two accounts (1
and 2
).
Then it begins 5 pending transfers of amounts 100
to
500
, incrementing by 100
for each transfer.
Then it fetches both accounts and validates that account 1
has:
debits_posted = 0
credits_posted = 0
debits_pending = 1500
- and
credits_pending = 0
And that account 2
has:
debits_posted = 0
credits_posted = 0
debits_pending = 0
- and
credits_pending = 1500
(This is because a pending transfer only affects pending credits and debits on accounts, not posted credits and debits.)
Then it alternatively posts and voids each transfer, checking account balances after each transfer.
Finally, it fetches both accounts, validates they both exist, and checks that credits and debits for both account are now solely posted, not pending.
Specifically, that account 1
has:
debits_posted = 1500
credits_posted = 0
debits_pending = 0
- and
credits_pending = 0
And that account 2
has:
debits_posted = 0
credits_posted = 1500
debits_pending = 0
- and
credits_pending = 0