diff --git a/db_scripts/local_testing/anvil_test.sh b/db_scripts/local_testing/anvil_test.sh index e6f1f6dd..04ddf876 100755 --- a/db_scripts/local_testing/anvil_test.sh +++ b/db_scripts/local_testing/anvil_test.sh @@ -42,7 +42,7 @@ set -e PWD=`pwd` LOCAL_DB="host=localhost user=debian dbname=sample" cd /home/debian/anvil-third-eye -# go run "scripts/merged_pf_version_reset/main.go" "$LOCAL_DB" $FORK_BLOCK +go run "scripts/merged_pf_version_reset/main.go" "$LOCAL_DB" $FORK_BLOCK cd $PWD createdb -O $SUPERUSER -T sample tmp_sample diff --git a/ds/mergedPFVersion.go b/ds/mergedPFVersion.go index 999ca6a6..9dac7a46 100644 --- a/ds/mergedPFVersion.go +++ b/ds/mergedPFVersion.go @@ -67,6 +67,7 @@ func (mdl *MergedPFManager) Load(details core.Json, discoveredAt int64) { } case map[string]interface{}: for token, det := range v { + log.Info(token, det) snaps := det.([]interface{}) for _, snap := range snaps { snapDetails := snap.(map[string]interface{}) @@ -137,3 +138,19 @@ func (mdl MergedPFManager) DisableToken(blockNum int64, token string, pfVersion BlockNumber: blockNum, }) } + +func (mdl MergedPFManager) DeleteAfter(blockNum int64) { + for token, entries := range mdl { + var newEntries []entry + for _, entry := range entries { + if entry.BlockNumber <= blockNum { + newEntries = append(newEntries, entry) + } + } + if len(newEntries) == 0 { + delete(mdl, token) + } else { + mdl[token] = newEntries + } + } +} diff --git a/scripts/merged_pf_version_reset/main.go b/scripts/merged_pf_version_reset/main.go index e8afca14..bf704875 100644 --- a/scripts/merged_pf_version_reset/main.go +++ b/scripts/merged_pf_version_reset/main.go @@ -38,7 +38,7 @@ func main() { } else { mgr := ds.MergedPFManager{} mgr.Load(adapter.GetDetails(), adapter.FirstLogAt) - // mgr.DeleteAfter(deletedB) + mgr.DeleteAfter(deletedB) mgr.Save(&adapter.Details) } }