Skip to content

Commit

Permalink
add final renter and host outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Dec 4, 2024
1 parent 28687d1 commit 77bb5e6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
9 changes: 5 additions & 4 deletions explorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions internal/testutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions persist/sqlite/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions persist/sqlite/v2consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions persist/sqlite/v2transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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))
Expand Down

0 comments on commit 77bb5e6

Please sign in to comment.