diff --git a/claimtrie/change/claimid.go b/claimtrie/change/claimid.go index 8b8e4c7e..f6d0ebd7 100644 --- a/claimtrie/change/claimid.go +++ b/claimtrie/change/claimid.go @@ -9,7 +9,9 @@ import ( ) // ClaimID represents a Claim's ClaimID. -type ClaimID [20]byte +const ClaimIDSize = 20 + +type ClaimID [ClaimIDSize]byte // NewClaimID returns a Claim ID calculated from Ripemd160(Sha256(OUTPOINT). func NewClaimID(op wire.OutPoint) (id ClaimID) { diff --git a/claimtrie/cmd/cmd/ui.go b/claimtrie/cmd/cmd/ui.go index 2f9f7162..bbfc52ca 100644 --- a/claimtrie/cmd/cmd/ui.go +++ b/claimtrie/cmd/cmd/ui.go @@ -32,7 +32,7 @@ func changeName(c change.ChangeType) string { func showChange(chg change.Change) { fmt.Printf(">>> Height: %6d: %s for %04s, %d, %s\n", - chg.Height, changeName(chg.Type), chg.ClaimID.String(), chg.Amount, chg.OutPoint) + chg.Height, changeName(chg.Type), chg.ClaimID.String(), chg.Amount, chg.OutPoint.String()) } func showClaim(c *node.Claim, n *node.Node) { @@ -42,12 +42,12 @@ func showClaim(c *node.Claim, n *node.Node) { } fmt.Printf("%s C ID: %s, TXO: %s\n %5d/%-5d, Status: %9s, Amount: %15d, Support Amount: %15d\n", - mark, c.ClaimID.String(), c.OutPoint, c.AcceptedAt, c.ActiveAt, status[c.Status], c.Amount, n.SupportSums[c.ClaimID.Key()]) + mark, c.ClaimID.String(), c.OutPoint.String(), c.AcceptedAt, c.ActiveAt, status[c.Status], c.Amount, n.SupportSums[c.ClaimID.Key()]) } func showSupport(c *node.Claim) { fmt.Printf(" S id: %s, op: %s, %5d/%-5d, %9s, amt: %15d\n", - c.ClaimID.String(), c.OutPoint, c.AcceptedAt, c.ActiveAt, status[c.Status], c.Amount) + c.ClaimID.String(), c.OutPoint.String(), c.AcceptedAt, c.ActiveAt, status[c.Status], c.Amount) } func showNode(n *node.Node) { diff --git a/claimtrie/node/noderepo/pebble.go b/claimtrie/node/noderepo/pebble.go index d4611c4d..5d7b5440 100644 --- a/claimtrie/node/noderepo/pebble.go +++ b/claimtrie/node/noderepo/pebble.go @@ -27,11 +27,10 @@ func init() { claimDecoder := func(e *msgpack.Decoder, v reflect.Value) error { data, err := e.DecodeBytes() if err != nil { - s, err := e.DecodeString() - if err != nil { - return err - } - id, err := change.NewIDFromString(s) + return err + } + if len(data) > change.ClaimIDSize { + id, err := change.NewIDFromString(string(data)) if err != nil { return err } @@ -55,13 +54,12 @@ func init() { opDecoder := func(e *msgpack.Decoder, v reflect.Value) error { data, err := e.DecodeBytes() if err != nil { + return err + } + if len(data) > chainhash.HashSize { // try the older data: - s, err := e.DecodeString() - if err != nil { - return err - } - op := node.NewOutPointFromString(s) - v.Set(reflect.ValueOf(op)) + op := node.NewOutPointFromString(string(data)) + v.Set(reflect.ValueOf(*op)) } else { index, err := e.DecodeUint32() if err != nil { @@ -71,8 +69,8 @@ func init() { if err != nil { return err } - op := wire.NewOutPoint(hash, index) - v.Set(reflect.ValueOf(*op)) + op := wire.OutPoint{Hash: *hash, Index: index} + v.Set(reflect.ValueOf(op)) } return nil }