Skip to content

Commit

Permalink
consensus: Inline V1TransactionSupplement methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine authored and ChrisSchinnerl committed Dec 18, 2024
1 parent caa8ba6 commit b94782a
Showing 1 changed file with 29 additions and 44 deletions.
73 changes: 29 additions & 44 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,34 +610,55 @@ func (ms *MidState) siacoinElement(ts V1TransactionSupplement, id types.SiacoinO
if i, ok := ms.created[id]; ok {
return ms.sces[i], true
}
return ts.siacoinElement(id)
for _, sce := range ts.SiacoinInputs {
if sce.ID == id {
return sce, true
}
}
return types.SiacoinElement{}, false
}

func (ms *MidState) siafundElement(ts V1TransactionSupplement, id types.SiafundOutputID) (types.SiafundElement, bool) {
if i, ok := ms.created[id]; ok {
return ms.sfes[i], true
}
return ts.siafundElement(id)
for _, sfe := range ts.SiafundInputs {
if sfe.ID == id {
return sfe, true
}
}
return types.SiafundElement{}, false
}

func (ms *MidState) fileContractElement(ts V1TransactionSupplement, id types.FileContractID) (types.FileContractElement, bool) {
if rev, ok := ms.revs[id]; ok {
return *rev, true
} else if i, ok := ms.created[id]; ok {
return ms.fces[i], true
} else if rev, ok := ts.revision(id); ok {
return rev, true
}
sps, ok := ts.storageProof(id)
return sps.FileContract, ok
for _, fce := range ts.RevisedFileContracts {
if fce.ID == id {
return fce, true
}
}
for _, sps := range ts.StorageProofs {
if sps.FileContract.ID == id {
return sps.FileContract, true
}
}
return types.FileContractElement{}, false
}

func (ms *MidState) storageProofWindowID(ts V1TransactionSupplement, id types.FileContractID) (types.BlockID, bool) {
if i, ok := ms.created[id]; ok && ms.fces[i].FileContract.WindowStart == ms.base.childHeight() {
return ms.base.Index.ID, true
}
sps, ok := ts.storageProof(id)
return sps.WindowID, ok
for _, sps := range ts.StorageProofs {
if sps.FileContract.ID == id {
return sps.WindowID, true
}
}
return types.BlockID{}, false
}

func (ms *MidState) spent(id types.ElementID) (types.TransactionID, bool) {
Expand Down Expand Up @@ -720,42 +741,6 @@ func (ts *V1TransactionSupplement) DecodeFrom(d *types.Decoder) {
types.DecodeSlice(d, &ts.StorageProofs)
}

func (ts V1TransactionSupplement) siacoinElement(id types.SiacoinOutputID) (sce types.SiacoinElement, ok bool) {
for _, sce := range ts.SiacoinInputs {
if sce.ID == id {
return sce, true
}
}
return
}

func (ts V1TransactionSupplement) siafundElement(id types.SiafundOutputID) (sfe types.SiafundElement, ok bool) {
for _, sfe := range ts.SiafundInputs {
if sfe.ID == id {
return sfe, true
}
}
return
}

func (ts V1TransactionSupplement) revision(id types.FileContractID) (fce types.FileContractElement, ok bool) {
for _, fce := range ts.RevisedFileContracts {
if fce.ID == id {
return fce, true
}
}
return
}

func (ts V1TransactionSupplement) storageProof(id types.FileContractID) (sps V1StorageProofSupplement, ok bool) {
for _, sps := range ts.StorageProofs {
if sps.FileContract.ID == id {
return sps, true
}
}
return
}

// A V1BlockSupplement contains elements that are associated with a v1 block,
// but not included in the block. This includes supplements for each v1
// transaction, as well as any file contracts that expired at the block's
Expand Down

0 comments on commit b94782a

Please sign in to comment.