summaryrefslogtreecommitdiff
path: root/src/xact.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2023-11-22 16:47:21 -0800
committerJohn Wiegley <johnw@newartisans.com>2024-08-05 08:35:56 -0700
commitdb0661dbb51e9082e47926c31e93bdc97b491bf9 (patch)
treee60f7dc32ebe9c24cb26eeb8c8438de7e891fe6b /src/xact.cc
parente6dae78c033ea970a459b1a0ccc2f1310d1bff96 (diff)
downloadfork-ledger-db0661dbb51e9082e47926c31e93bdc97b491bf9.tar.gz
fork-ledger-db0661dbb51e9082e47926c31e93bdc97b491bf9.tar.bz2
fork-ledger-db0661dbb51e9082e47926c31e93bdc97b491bf9.zip
Add support for hash chaining to detect modifications in postings
The following details of a posting contribute to its hash: fullname of account string representation of amount Each posting hashes contributes to the transaction hash, which is compromised of: previous transaction’s hash (as encountered in parsing order) actual date optional auxiliary date optional code payee hashes of all postings Note that this means that changes in the “code” or any of the comments
Diffstat (limited to 'src/xact.cc')
-rw-r--r--src/xact.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/xact.cc b/src/xact.cc
index 55e816cb..0b9bd9cd 100644
--- a/src/xact.cc
+++ b/src/xact.cc
@@ -581,6 +581,21 @@ bool xact_t::valid() const
return true;
}
+string xact_t::hash(string nonce) const {
+ std::ostringstream repr;
+ repr << nonce;
+ repr << date();
+ repr << aux_date();
+ repr << code;
+ repr << payee;
+ string hash(repr.str());
+ posts_list all_posts(posts.begin(), posts.end());
+ foreach (post_t * post, all_posts) {
+ hash = post->hash(hash);
+ }
+ return hash;
+}
+
namespace {
bool post_pred(expr_t::ptr_op_t op, post_t& post)
{