@@ -57,7 +57,7 @@ type migratedAddress struct {
5757type migratedEntry struct {
5858 Address migratedAddress `json:"address"`
5959 Verified bool `json:"verified"`
60- LastSeen int64 `json:"last_seen"`
60+ LastSeen int64 `json:"last_seen,omitempty "`
6161}
6262
6363// rewriteAddressbookEnvelope wraps each "addressbook_entry_*" legacy
@@ -125,9 +125,9 @@ func rewriteAddressbookEnvelope(s storage.Store) migration.StepFn {
125125// stampAddressbookLastSeen sets "last_seen" to the current time on every
126126// "addressbook_entry_*" record that lacks it, so that addresses carried over
127127// from before pruning was introduced are not immediately pruned. Entries that
128- // already carry a non-zero last_seen are left untouched. The whole record is
129- // preserved by merging into the decoded JSON object rather than re-encoding a
130- // typed struct .
128+ // already carry a non-zero last_seen are left untouched. The record is decoded
129+ // into migratedEntry, the current serialization shape, whose last_seen field is
130+ // omitempty so older records that predate it round-trip unchanged .
131131func stampAddressbookLastSeen (s storage.Store ) migration.StepFn {
132132 return func () error {
133133 store := & StateStorerAdapter {s }
@@ -151,31 +151,18 @@ func stampAddressbookLastSeen(s storage.Store) migration.StepFn {
151151 now := time .Now ().Unix ()
152152
153153 for _ , e := range batch {
154- var fields map [ string ]json. RawMessage
155- if err := json .Unmarshal (e .val , & fields ); err != nil {
154+ var entry migratedEntry
155+ if err := json .Unmarshal (e .val , & entry ); err != nil {
156156 _ = store .Delete (e .key )
157157 continue
158158 }
159159
160- if raw , ok := fields ["last_seen" ]; ok {
161- var ls int64
162- if json .Unmarshal (raw , & ls ) == nil && ls != 0 {
163- continue
164- }
165- }
166-
167- stamp , err := json .Marshal (now )
168- if err != nil {
169- return fmt .Errorf ("marshal last_seen: %w" , err )
170- }
171- fields ["last_seen" ] = stamp
172-
173- out , err := json .Marshal (fields )
174- if err != nil {
175- return fmt .Errorf ("marshal addressbook entry %q: %w" , e .key , err )
160+ if entry .LastSeen != 0 {
161+ continue
176162 }
163+ entry .LastSeen = now
177164
178- if err := store .Put (e .key , json . RawMessage ( out ) ); err != nil {
165+ if err := store .Put (e .key , & entry ); err != nil {
179166 return fmt .Errorf ("stamp addressbook entry %q: %w" , e .key , err )
180167 }
181168 }
0 commit comments