From 3ccd8213c1476b0ec6222d46d1023ecd018c5d9c Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 18 Jun 2024 09:30:55 -0700 Subject: [PATCH 1/2] wallet: change resolution event to use V2FileContractResolution for custom resolution type encoding --- wallet/events.go | 9 ++++----- wallet/wallet.go | 16 ++++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/wallet/events.go b/wallet/events.go index b305fe5..3151a0e 100644 --- a/wallet/events.go +++ b/wallet/events.go @@ -63,7 +63,7 @@ type ( // An EventV1ContractResolution represents a file contract payout from a v1 // contract. EventV1ContractResolution struct { - FileContract types.FileContractElement `json:"fileContract"` + Parent types.FileContractElement `json:"parent"` SiacoinElement types.SiacoinElement `json:"siacoinElement"` Missed bool `json:"missed"` } @@ -71,10 +71,9 @@ type ( // An EventV2ContractResolution represents a file contract payout from a v2 // contract. EventV2ContractResolution struct { - FileContract types.V2FileContractElement `json:"fileContract"` - Resolution types.V2FileContractResolutionType `json:"resolution"` - SiacoinElement types.SiacoinElement `json:"siacoinElement"` - Missed bool `json:"missed"` + types.V2FileContractResolution + SiacoinElement types.SiacoinElement `json:"siacoinElement"` + Missed bool `json:"missed"` } ) diff --git a/wallet/wallet.go b/wallet/wallet.go index f4fc8e9..c954f8f 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -280,7 +280,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f outputID := types.FileContractID(fce.ID).ValidOutputID(i) addEvent(types.Hash256(outputID), cs.MaturityHeight(), EventTypeV1ContractResolution, EventV1ContractResolution{ - FileContract: fce, + Parent: fce, SiacoinElement: sces[outputID], Missed: false, }, []types.Address{address}) @@ -294,7 +294,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f outputID := types.FileContractID(fce.ID).MissedOutputID(i) addEvent(types.Hash256(outputID), cs.MaturityHeight(), EventTypeV1ContractResolution, EventV1ContractResolution{ - FileContract: fce, + Parent: fce, SiacoinElement: sces[outputID], Missed: true, }, []types.Address{address}) @@ -315,8 +315,10 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f if relevant(fce.V2FileContract.HostOutput.Address) { outputID := types.FileContractID(fce.ID).V2HostOutputID() addEvent(types.Hash256(outputID), cs.MaturityHeight(), EventTypeV2ContractResolution, EventV2ContractResolution{ - FileContract: fce, - Resolution: res, + V2FileContractResolution: types.V2FileContractResolution{ + Parent: fce, + Resolution: res, + }, SiacoinElement: sces[outputID], Missed: missed, }, []types.Address{fce.V2FileContract.HostOutput.Address}) @@ -325,8 +327,10 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f if relevant(fce.V2FileContract.RenterOutput.Address) { outputID := types.FileContractID(fce.ID).V2RenterOutputID() addEvent(types.Hash256(outputID), cs.MaturityHeight(), EventTypeV2ContractResolution, EventV2ContractResolution{ - FileContract: fce, - Resolution: res, + V2FileContractResolution: types.V2FileContractResolution{ + Parent: fce, + Resolution: res, + }, SiacoinElement: sces[outputID], Missed: missed, }, []types.Address{fce.V2FileContract.RenterOutput.Address}) From 213b2810835ac75d893c674eb879b2ab5de3ceb7 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 18 Jun 2024 14:38:13 -0700 Subject: [PATCH 2/2] sqlite: add siacoin_elements index --- persist/sqlite/init.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/persist/sqlite/init.sql b/persist/sqlite/init.sql index 133cad1..a6220b1 100644 --- a/persist/sqlite/init.sql +++ b/persist/sqlite/init.sql @@ -28,6 +28,7 @@ CREATE INDEX siacoin_elements_address_id ON siacoin_elements (address_id); CREATE INDEX siacoin_elements_maturity_height_matured ON siacoin_elements (maturity_height, matured); CREATE INDEX siacoin_elements_chain_index_id ON siacoin_elements (chain_index_id); CREATE INDEX siacoin_elements_spent_index_id ON siacoin_elements (spent_index_id); +CREATE INDEX siacoin_elements_address_id_spent_index_id ON siacoin_elements(address_id, spent_index_id); CREATE TABLE siafund_elements ( id BLOB PRIMARY KEY, @@ -42,6 +43,7 @@ CREATE TABLE siafund_elements ( CREATE INDEX siafund_elements_address_id ON siafund_elements (address_id); CREATE INDEX siafund_elements_chain_index_id ON siafund_elements (chain_index_id); CREATE INDEX siafund_elements_spent_index_id ON siafund_elements (spent_index_id); +CREATE INDEX siafund_elements_address_id_spent_index_id ON siafund_elements(address_id, spent_index_id); CREATE TABLE state_tree ( row INTEGER,