aboutsummaryrefslogtreecommitdiff
path: root/src/ledger.h
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-17 19:55:36 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-17 19:55:36 +0200
commit380195f7cd5e57acf2c1cf2bc41069e6b0b979ed (patch)
tree32a88fb22a7fbe8f1fd5c105156d1f928c93950d /src/ledger.h
downloadbokf-380195f7cd5e57acf2c1cf2bc41069e6b0b979ed.tar.gz
bokf-380195f7cd5e57acf2c1cf2bc41069e6b0b979ed.zip
Initial commit: daemon, clients, docs, Docker deploy pipelinev0.1.0
Diffstat (limited to 'src/ledger.h')
-rw-r--r--src/ledger.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/ledger.h b/src/ledger.h
new file mode 100644
index 0000000..30271d0
--- /dev/null
+++ b/src/ledger.h
@@ -0,0 +1,51 @@
+#ifndef BOKF_LEDGER_H
+#define BOKF_LEDGER_H
+
+#include <sqlite3.h>
+#include <stddef.h>
+#include <stdint.h>
+
+struct ledger_row {
+ const char *account;
+ int64_t debit_ore;
+ int64_t credit_ore;
+ const char *description;
+};
+
+struct ledger_error {
+ const char *code;
+ char msg[512];
+ int has_details;
+ int64_t difference_ore;
+};
+
+struct ledger_post_opts {
+ int64_t org_id;
+ int64_t user_id;
+ int64_t token_id;
+ const char *date;
+ const char *description;
+ const char *series; /* NULL -> "A" */
+ const struct ledger_row *rows;
+ size_t nrows;
+ int64_t corrects_voucher_id; /* 0 = none */
+ const int64_t *attachment_ids;
+ size_t n_attachments;
+ const char *client_ref; /* NULL = none */
+ int dry_run;
+ const char *source; /* NULL -> "manual" or "agent" */
+};
+
+int ledger_post(sqlite3 *db, const struct ledger_post_opts *o,
+ struct ledger_error *e, char **out_result_json);
+
+/* Appends the canonical bytes for a voucher hash (SCHEMA.md 7.1) and
+ returns the 32-byte hash. */
+void ledger_voucher_hash(const unsigned char prev[32], int64_t org_id,
+ const char *fy_label, const char *series,
+ int64_t number, const char *date,
+ const char *description,
+ const struct ledger_row *rows, size_t nrows,
+ unsigned char out[32]);
+
+#endif