From eda230e53cb2388b2c0ef563b29cf091e2d46d51 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Thu, 19 Dec 2024 09:14:42 -0500 Subject: [PATCH] reduce code duplication for v2 events --- explorer/events.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/explorer/events.go b/explorer/events.go index bf145bc..d1350d7 100644 --- a/explorer/events.go +++ b/explorer/events.go @@ -275,9 +275,8 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) (events [] panic("unknown resolution type") } - efc := V2FileContract{V2FileContractElement: fce} - { - element := sces[types.FileContractID(fce.ID).V2HostOutputID()] + addV2Resolution := func(element types.SiacoinElement) { + efc := V2FileContract{V2FileContractElement: fce} addEvent(types.Hash256(element.ID), element.MaturityHeight, wallet.EventTypeV2ContractResolution, EventV2ContractResolution{ Resolution: V2FileContractResolution{ Parent: efc, @@ -286,21 +285,10 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) (events [] }, SiacoinElement: SiacoinOutput{SiacoinElement: element}, Missed: missed, - }, []types.Address{fce.V2FileContract.HostOutput.Address}) - } - - { - element := sces[types.FileContractID(fce.ID).V2RenterOutputID()] - addEvent(types.Hash256(element.ID), element.MaturityHeight, wallet.EventTypeV2ContractResolution, EventV2ContractResolution{ - Resolution: V2FileContractResolution{ - Parent: efc, - Type: typ, - Resolution: res, - }, - SiacoinElement: SiacoinOutput{SiacoinElement: element}, - Missed: missed, - }, []types.Address{fce.V2FileContract.RenterOutput.Address}) + }, []types.Address{element.SiacoinOutput.Address}) } + addV2Resolution(sces[types.FileContractID(fce.ID).V2RenterOutputID()]) + addV2Resolution(sces[types.FileContractID(fce.ID).V2HostOutputID()]) }) // handle block rewards