From c53f755595edb3c156e032e568f0d71541c006e3 Mon Sep 17 00:00:00 2001 From: Tzu-Jung Lee Date: Tue, 14 Aug 2018 19:45:54 -0700 Subject: [PATCH] nmodemgr, ct: add Value to AddClaim() and UpdateClaim() --- claim/claim.go | 3 ++- claimtrie.go | 8 ++++---- cmd/claimtrie/main.go | 6 ++++-- import.go | 4 ++-- nodemgr/nm.go | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/claim/claim.go b/claim/claim.go index bc3cbe2..ca617bf 100644 --- a/claim/claim.go +++ b/claim/claim.go @@ -26,8 +26,8 @@ type Claim struct { ID ID Amt Amount Accepted Height + Value []byte - // Dynamic values. EffAmt Amount ActiveAt Height } @@ -37,6 +37,7 @@ func (c *Claim) setID(id ID) *Claim { c.ID = id; return c } func (c *Claim) setAmt(amt Amount) *Claim { c.Amt = amt; return c } func (c *Claim) setAccepted(ht Height) *Claim { c.Accepted = ht; return c } func (c *Claim) setActiveAt(ht Height) *Claim { c.ActiveAt = ht; return c } +func (c *Claim) setValue(val []byte) *Claim { c.Value = val; return c } func (c *Claim) String() string { return claimToString(c) } func (c *Claim) expireAt() Height { diff --git a/claimtrie.go b/claimtrie.go index cc6d919..3156864 100644 --- a/claimtrie.go +++ b/claimtrie.go @@ -81,8 +81,8 @@ func (ct *ClaimTrie) CommitMgr() *CommitMgr { } // AddClaim adds a Claim to the ClaimTrie. -func (ct *ClaimTrie) AddClaim(name string, op claim.OutPoint, amt claim.Amount) error { - c := change.New(change.AddClaim).SetOP(op).SetAmt(amt) +func (ct *ClaimTrie) AddClaim(name string, op claim.OutPoint, amt claim.Amount, val []byte) error { + c := change.New(change.AddClaim).SetOP(op).SetAmt(amt).SetValue(val) return ct.modify(name, c) } @@ -93,8 +93,8 @@ func (ct *ClaimTrie) SpendClaim(name string, op claim.OutPoint) error { } // UpdateClaim updates a Claim in the ClaimTrie. -func (ct *ClaimTrie) UpdateClaim(name string, op claim.OutPoint, amt claim.Amount, id claim.ID) error { - c := change.New(change.UpdateClaim).SetOP(op).SetAmt(amt).SetID(id) +func (ct *ClaimTrie) UpdateClaim(name string, op claim.OutPoint, amt claim.Amount, id claim.ID, val []byte) error { + c := change.New(change.UpdateClaim).SetOP(op).SetAmt(amt).SetID(id).SetValue(val) return ct.modify(name, c) } diff --git a/cmd/claimtrie/main.go b/cmd/claimtrie/main.go index ec3e8c0..2063ad1 100644 --- a/cmd/claimtrie/main.go +++ b/cmd/claimtrie/main.go @@ -31,6 +31,7 @@ var ( dump bool verbose bool name string + value string height claim.Height amt claim.Amount op claim.OutPoint @@ -45,6 +46,7 @@ var ( flagAmount = cli.Int64Flag{Name: "amount, a", Usage: "Amount", Destination: (*int64)(&amt)} flagHeight = cli.Int64Flag{Name: "height, ht", Usage: "Height"} flagName = cli.StringFlag{Name: "name, n", Value: "Hello", Usage: "Name", Destination: &name} + flagValue = cli.StringFlag{Name: "value, val", Value: "{\"I'm Node Value\"}", Usage: "Value", Destination: &value} flagID = cli.StringFlag{Name: "id", Usage: "Claim ID"} flagOutPoint = cli.StringFlag{Name: "outpoint, op", Usage: "Outpoint. (HASH:INDEX)"} ) @@ -207,7 +209,7 @@ func main() { } func cmdAddClaim(c *cli.Context) error { - return ct.AddClaim(name, op, amt) + return ct.AddClaim(name, op, amt, []byte(value)) } func cmdSpendClaim(c *cli.Context) error { @@ -218,7 +220,7 @@ func cmdUpdateClaim(c *cli.Context) error { if !c.IsSet("id") { return fmt.Errorf("flag id is required") } - return ct.UpdateClaim(name, op, amt, id) + return ct.UpdateClaim(name, op, amt, id, []byte(value)) } func cmdAddSupport(c *cli.Context) error { diff --git a/import.go b/import.go index 0815803..99374e7 100644 --- a/import.go +++ b/import.go @@ -66,11 +66,11 @@ func apply(ct *ClaimTrie, c *change.Change, verbose bool) error { var err error switch c.Cmd { case change.AddClaim: - err = ct.AddClaim(c.Name, c.OP, c.Amt) + err = ct.AddClaim(c.Name, c.OP, c.Amt, c.Value) case change.SpendClaim: err = ct.SpendClaim(c.Name, c.OP) case change.UpdateClaim: - err = ct.UpdateClaim(c.Name, c.OP, c.Amt, c.ID) + err = ct.UpdateClaim(c.Name, c.OP, c.Amt, c.ID, c.Value) case change.AddSupport: err = ct.AddSupport(c.Name, c.OP, c.Amt, c.ID) case change.SpendSupport: diff --git a/nodemgr/nm.go b/nodemgr/nm.go index f4d670d..52b9c7f 100644 --- a/nodemgr/nm.go +++ b/nodemgr/nm.go @@ -155,11 +155,11 @@ func execute(n *claim.Node, c *change.Change) error { var err error switch c.Cmd { case change.AddClaim: - err = n.AddClaim(c.OP, c.Amt) + err = n.AddClaim(c.OP, c.Amt, c.Value) case change.SpendClaim: err = n.SpendClaim(c.OP) case change.UpdateClaim: - err = n.UpdateClaim(c.OP, c.Amt, c.ID) + err = n.UpdateClaim(c.OP, c.Amt, c.ID, c.Value) case change.AddSupport: err = n.AddSupport(c.OP, c.Amt, c.ID) case change.SpendSupport: