claimtrie/claimid.go
Tzu-Jung Lee 84c64c1018 wip: misc updates
AddClaim / AddSupport is working with minimal testing done so far.
RemoveClaim / RemoveSupport is implemented, but not tested yet.

Some known issues:

Currently, we update the BestClaim for each node in a lazy fashion.
Each node could add/remove claims/supports without recalculating hash
until its being obeserved externally.

However, due to the "Takeover Delay" bidding rule, as the block number
increases, the bestClaim might changes implicitly. The Trie can't detect
this passively, and would need some mechanism for this.
2018-07-03 22:03:55 -07:00

46 lines
854 B
Go

package claimtrie
import (
"bytes"
"encoding/binary"
"encoding/hex"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
)
// NewClaimID ...
func NewClaimID(op wire.OutPoint) ClaimID {
w := bytes.NewBuffer(op.Hash[:])
if err := binary.Write(w, binary.BigEndian, op.Index); err != nil {
panic(err)
}
var id ClaimID
copy(id[:], btcutil.Hash160(w.Bytes()))
return id
}
// NewClaimIDFromString ...
func NewClaimIDFromString(s string) (ClaimID, error) {
b, err := hex.DecodeString(s)
var id ClaimID
copy(id[:], b)
return id, err
}
// ClaimID ...
type ClaimID [20]byte
func (id ClaimID) String() string {
return hex.EncodeToString(id[:])
}
func calActiveHeight(accepted, curr, tookover Height) Height {
factor := Height(32)
delay := (curr - tookover) / factor
if delay > 4032 {
delay = 4032
}
return accepted + delay
}