From 518fdb7a400e12512482949f6199e4ab206d0cd1 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Wed, 4 Dec 2024 11:43:44 -0500 Subject: [PATCH] add final renter and host outputs --- explorer/types.go | 9 +++++---- internal/testutil/check.go | 4 ++++ persist/sqlite/init.sql | 4 ++++ persist/sqlite/v2consensus.go | 4 ++-- persist/sqlite/v2transactions.go | 15 +++++++++++---- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/explorer/types.go b/explorer/types.go index e1a2228..eec17fa 100644 --- a/explorer/types.go +++ b/explorer/types.go @@ -213,10 +213,11 @@ type V2HostAnnouncement struct { // A V2FileContractRenewal renews a file contract. type V2FileContractRenewal struct { - FinalRevision V2FileContract `json:"finalRevision"` - NewContract V2FileContract `json:"newContract"` - RenterRollover types.Currency `json:"renterRollover"` - HostRollover types.Currency `json:"hostRollover"` + FinalRenterOutput types.SiacoinOutput `json:"finalRenterOutput"` + FinalHostOutput types.SiacoinOutput `json:"finalHostOutput"` + RenterRollover types.Currency `json:"renterRollover"` + HostRollover types.Currency `json:"hostRollover"` + NewContract V2FileContract `json:"newContract"` // signatures cover above fields RenterSignature types.Signature `json:"renterSignature"` diff --git a/internal/testutil/check.go b/internal/testutil/check.go index 4daa362..13fa049 100644 --- a/internal/testutil/check.go +++ b/internal/testutil/check.go @@ -218,6 +218,10 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl CheckV2FC(t, v.NewContract, gotV.NewContract) Equal(t, "type", "renewal", got.Type) + Equal(t, "final renter output address", v.FinalRenterOutput.Address, gotV.FinalRenterOutput.Address) + Equal(t, "final renter output value", v.FinalRenterOutput.Value, gotV.FinalRenterOutput.Value) + Equal(t, "final host output address", v.FinalHostOutput.Address, gotV.FinalHostOutput.Address) + Equal(t, "final host output value", v.FinalHostOutput.Value, gotV.FinalHostOutput.Value) Equal(t, "renter rollover", v.RenterRollover, gotV.RenterRollover) Equal(t, "host rollover", v.HostRollover, gotV.HostRollover) Equal(t, "renter signature", v.RenterSignature, gotV.RenterSignature) diff --git a/persist/sqlite/init.sql b/persist/sqlite/init.sql index 84ff3d8..f9675b6 100644 --- a/persist/sqlite/init.sql +++ b/persist/sqlite/init.sql @@ -340,6 +340,10 @@ CREATE TABLE v2_transaction_file_contract_resolutions ( -- V2FileContractRenewal renewal_new_contract_id INTEGER REFERENCES v2_file_contract_elements(id) ON DELETE CASCADE, + renewal_final_renter_output_address BLOB, + renewal_final_renter_output_value BLOB, + renewal_final_host_output_address BLOB, + renewal_final_host_output_value BLOB, renewal_renter_rollover BLOB, renewal_host_rollover BLOB, renewal_renter_signature BLOB, diff --git a/persist/sqlite/v2consensus.go b/persist/sqlite/v2consensus.go index d91693f..9121ff2 100644 --- a/persist/sqlite/v2consensus.go +++ b/persist/sqlite/v2consensus.go @@ -429,7 +429,7 @@ func addV2FileContractRevisions(tx *txn, txnID int64, txn types.V2Transaction, d } func addV2FileContractResolutions(tx *txn, txnID int64, txn types.V2Transaction, dbIDs map[explorer.DBFileContract]int64) error { - renewalStmt, err := tx.Prepare(`INSERT INTO v2_transaction_file_contract_resolutions(transaction_id, transaction_order, parent_contract_id, resolution_type, renewal_new_contract_id, renewal_renter_rollover, renewal_host_rollover, renewal_renter_signature, renewal_host_signature) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`) + renewalStmt, err := tx.Prepare(`INSERT INTO v2_transaction_file_contract_resolutions(transaction_id, transaction_order, parent_contract_id, resolution_type, renewal_new_contract_id, renewal_final_renter_output_address, renewal_final_renter_output_value, renewal_final_host_output_address, renewal_final_host_output_value, renewal_renter_rollover, renewal_host_rollover, renewal_renter_signature, renewal_host_signature) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) if err != nil { return fmt.Errorf("addV2FileContractResolutions: failed to prepare renewal statement: %w", err) } @@ -466,7 +466,7 @@ func addV2FileContractResolutions(tx *txn, txnID int64, txn types.V2Transaction, return errors.New("addV2FileContractResolutions: renewal dbID not in map") } - if _, err := renewalStmt.Exec(txnID, i, parentDBID, 0, newDBID, encode(v.RenterRollover), encode(v.HostRollover), encode(v.RenterSignature), encode(v.HostSignature)); err != nil { + if _, err := renewalStmt.Exec(txnID, i, parentDBID, 0, newDBID, encode(v.FinalRenterOutput.Address), encode(v.FinalRenterOutput.Value), encode(v.FinalHostOutput.Address), encode(v.FinalHostOutput.Value), encode(v.RenterRollover), encode(v.HostRollover), encode(v.RenterSignature), encode(v.HostSignature)); err != nil { return fmt.Errorf("addV2FileContractResolutions: failed to execute renewal statement: %w", err) } case *types.V2StorageProof: diff --git a/persist/sqlite/v2transactions.go b/persist/sqlite/v2transactions.go index 6f18fb8..d799fa5 100644 --- a/persist/sqlite/v2transactions.go +++ b/persist/sqlite/v2transactions.go @@ -434,6 +434,8 @@ func fillV2TransactionFileContractResolutions(tx *txn, dbIDs []int64, txns []exp SELECT parent_contract_id, resolution_type, renewal_new_contract_id, + renewal_final_renter_output_address, renewal_final_renter_output_value, + renewal_final_host_output_address, renewal_final_host_output_value, renewal_renter_rollover, renewal_host_rollover, renewal_renter_signature, renewal_host_signature, storage_proof_proof_index, storage_proof_leaf, storage_proof_proof @@ -469,6 +471,7 @@ WHERE fc.id = ?`) var parentContractID, resolutionType int64 // renewal var renewalNewContractID sql.NullInt64 + var finalRenterOutput, finalHostOutput types.SiacoinOutput var renewalRenterRollover, renewalHostRollover types.Currency var renewalRenterSignature, renewalHostSignature types.Signature // storage proof @@ -480,6 +483,8 @@ WHERE fc.id = ?`) if err := rows.Scan( &parentContractID, &resolutionType, &renewalNewContractID, + decodeNull(&finalRenterOutput.Address), decodeNull(&finalRenterOutput.Value), + decodeNull(&finalHostOutput.Address), decodeNull(&finalHostOutput.Value), decodeNull(&renewalRenterRollover), decodeNull(&renewalHostRollover), decodeNull(&renewalRenterSignature), decodeNull(&renewalHostSignature), decodeNull(&storageProofProofIndex), &storageProofLeaf, decodeNull(&storageProofProof)); err != nil { @@ -498,10 +503,12 @@ WHERE fc.id = ?`) switch resolutionType { case 0: // V2FileContractRenewal renewal := &explorer.V2FileContractRenewal{ - RenterRollover: renewalRenterRollover, - HostRollover: renewalHostRollover, - RenterSignature: renewalRenterSignature, - HostSignature: renewalHostSignature, + FinalRenterOutput: finalRenterOutput, + FinalHostOutput: finalHostOutput, + RenterRollover: renewalRenterRollover, + HostRollover: renewalHostRollover, + RenterSignature: renewalRenterSignature, + HostSignature: renewalHostSignature, } if renewalNewContractID.Valid { renewal.NewContract, err = scanV2FileContract(fcStmt.QueryRow(renewalNewContractID.Int64))