Examples
These are programs you can run, not fragments. The first is this site’s tutorial. The rest are libspiffy’s own end-to-end tests, which drive real wallets against localnet-teranode. Each one shows one feature working from start to finish.
The tutorial program
Section titled “The tutorial program”examples/first_payment is the complete tutorial: two wallets, a faucet payment imported with its proof, an invoice, a BEEF validated and broadcast, and both wallets confirming it. It uses libspiffy 5.0.0.
git clone https://github.com/twostack/libspiffy.devcd libspiffy.dev/examples/first_paymentdart pub getLOCALNET_TERANODE=/path/to/localnet-teranode dart run bin/first_payment.dartIt needs localnet-teranode running and takes about a minute and a half.
The coordinator, offline
Section titled “The coordinator, offline”example/coordinator_example.dart in the libspiffy repository shows the coordinator API with no network at all. It uses in-memory storage, creates a wallet and an invoice with ask, handles a failure as a CoordinatorFailure, and follows balance changes with on<E>(). Run it from a libspiffy checkout:
dart run example/coordinator_example.dartlibspiffy’s end-to-end tests
Section titled “libspiffy’s end-to-end tests”These are in test/integration/ in the libspiffy repository. They share a harness, localnet_harness.dart. Its LocalnetNode is a complete LibSpiffyActorSystem that syncs headers from Teranode and broadcasts through Arcade. Its receiveMined funds a wallet from the faucet with a proof, the same way the tutorial does.
| Test file | What it shows |
|---|---|
localnet_payment_e2e_test.dart |
Invoice payments: both wallets confirm; paying from a payment not yet mined; a payment handed over twice is received once; a restart between receiving and the block |
localnet_deferred_e2e_test.dart |
Deferred payments: the payer broadcasts, cancels or reclaims a payment the payee never sent; first seen wins against a reclaim |
localnet_channel_e2e_test.dart |
Payment channels: open, pay three times, close; settling at the margin; claiming a refund when the other side is gone |
localnet_delegated_payment_e2e_test.dart |
A service takes a payment on a delegated chain for an offline recipient, who later takes it in |
localnet_type42_payment_e2e_test.dart |
Paying to a type-42 (BRC-42) destination of a recipient’s anchor key |
localnet_reorg_e2e_test.dart |
Chain reorganizations: wallets follow a confirmed payment that moves to another block or height |
localnet_node_e2e_test.dart |
Header sync from Teranode, following new blocks, and restarting at the tip |
Run one from a libspiffy checkout, with localnet-teranode running beside it:
dart test -P localnet test/integration/localnet_payment_e2e_test.dartLOCALNET_LOG=1 prints the library’s log records, tagged by node. These tests mine blocks on the shared regtest chain, as the localnet scripts do. Testing against localnet has the details.