nmodemgr, ct: add Value to AddClaim() and UpdateClaim()

This commit is contained in:
Tzu-Jung Lee 2018-08-14 19:45:54 -07:00
parent d06dc8d547
commit c53f755595
5 changed files with 14 additions and 11 deletions

View file

@ -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 {

View file

@ -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)
}

View file

@ -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 {

View file

@ -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:

View file

@ -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: