made custom decoders actually work
fix format
This commit is contained in:
parent
26e4083f38
commit
ac6a7ad121
3 changed files with 17 additions and 17 deletions
claimtrie
|
@ -9,7 +9,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClaimID represents a Claim's ClaimID.
|
// 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).
|
// NewClaimID returns a Claim ID calculated from Ripemd160(Sha256(OUTPOINT).
|
||||||
func NewClaimID(op wire.OutPoint) (id ClaimID) {
|
func NewClaimID(op wire.OutPoint) (id ClaimID) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ func changeName(c change.ChangeType) string {
|
||||||
|
|
||||||
func showChange(chg change.Change) {
|
func showChange(chg change.Change) {
|
||||||
fmt.Printf(">>> Height: %6d: %s for %04s, %d, %s\n",
|
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) {
|
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",
|
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) {
|
func showSupport(c *node.Claim) {
|
||||||
fmt.Printf(" S id: %s, op: %s, %5d/%-5d, %9s, amt: %15d\n",
|
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) {
|
func showNode(n *node.Node) {
|
||||||
|
|
|
@ -26,12 +26,11 @@ func init() {
|
||||||
}
|
}
|
||||||
claimDecoder := func(e *msgpack.Decoder, v reflect.Value) error {
|
claimDecoder := func(e *msgpack.Decoder, v reflect.Value) error {
|
||||||
data, err := e.DecodeBytes()
|
data, err := e.DecodeBytes()
|
||||||
if err != nil {
|
|
||||||
s, err := e.DecodeString()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
id, err := change.NewIDFromString(s)
|
if len(data) > change.ClaimIDSize {
|
||||||
|
id, err := change.NewIDFromString(string(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -54,14 +53,13 @@ func init() {
|
||||||
}
|
}
|
||||||
opDecoder := func(e *msgpack.Decoder, v reflect.Value) error {
|
opDecoder := func(e *msgpack.Decoder, v reflect.Value) error {
|
||||||
data, err := e.DecodeBytes()
|
data, err := e.DecodeBytes()
|
||||||
if err != nil {
|
|
||||||
// try the older data:
|
|
||||||
s, err := e.DecodeString()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
op := node.NewOutPointFromString(s)
|
if len(data) > chainhash.HashSize {
|
||||||
v.Set(reflect.ValueOf(op))
|
// try the older data:
|
||||||
|
op := node.NewOutPointFromString(string(data))
|
||||||
|
v.Set(reflect.ValueOf(*op))
|
||||||
} else {
|
} else {
|
||||||
index, err := e.DecodeUint32()
|
index, err := e.DecodeUint32()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -71,8 +69,8 @@ func init() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
op := wire.NewOutPoint(hash, index)
|
op := wire.OutPoint{Hash: *hash, Index: index}
|
||||||
v.Set(reflect.ValueOf(*op))
|
v.Set(reflect.ValueOf(op))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue