From bc86ccf21224afd1a788fb3e0114489699c3ef94 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 23 Oct 2018 18:28:31 -0700 Subject: [PATCH] watchtower/wtdb/breach_hint: adds BreachHint, txid prefix --- watchtower/wtdb/breach_hint.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 watchtower/wtdb/breach_hint.go diff --git a/watchtower/wtdb/breach_hint.go b/watchtower/wtdb/breach_hint.go new file mode 100644 index 00000000..8332745b --- /dev/null +++ b/watchtower/wtdb/breach_hint.go @@ -0,0 +1,27 @@ +package wtdb + +import ( + "encoding/hex" + + "github.com/btcsuite/btcd/chaincfg/chainhash" +) + +// BreachHintSize is the length of the txid prefix used to identify remote +// commitment broadcasts. +const BreachHintSize = 16 + +// BreachHint is the first 16-bytes of the txid belonging to a revoked +// commitment transaction. +type BreachHint [BreachHintSize]byte + +// NewBreachHintFromHash creates a breach hint from a transaction ID. +func NewBreachHintFromHash(hash *chainhash.Hash) BreachHint { + var hint BreachHint + copy(hint[:], hash[:BreachHintSize]) + return hint +} + +// String returns a hex encoding of the breach hint. +func (h BreachHint) String() string { + return hex.EncodeToString(h[:]) +}