package state import ( "ripple/bug" "ripple/errmsgs" "ripple/types" ) func (d *State) SetUserCounter(val uint32) error { d.Storage.User.Counter = val return d.Save() } func (d *State) MustSetCounterIn(id types.UserIdentifier, val uint32) error { acc, ok := d.Storage.Accounts[id] if !ok { panic(bug.BugStateViolated) } acc.CounterIn = val d.Storage.Accounts[id] = acc return d.Save() } func (d *State) IncrementAndGetCounterOut(id types.UserIdentifier) (uint32, error) { acc, ok := d.Storage.Accounts[id] if !ok { return 0, errmsgs.ErrKeyNotFound } acc.CounterOut++ d.Storage.Accounts[id] = acc return acc.CounterOut, d.Save() } func (d *State) AddCounterpart(id types.UserIdentifier, port int, secretKey [32]byte) { d.Memory.Counterpart.Identifier = id d.Memory.Counterpart.Port = port d.Memory.Counterpart.SecretKey = secretKey d.Memory.Counterpart.CounterIn = 0 d.Memory.Counterpart.CounterOut = 0 }