Commit c1ce0f09 authored by David Vorick's avatar David Vorick

tune up signatures.go

parent 91c83c1d
......@@ -315,6 +315,15 @@ func (s *State) ValidContract(fc FileContract) error {
return s.validFileContracts(t)
}
// ValidSignatures takes a transaction and determines whether the transaction
// contains a legal set of signatures, including checking the timelocks against
// the current state height.
func (s *State) ValidSignatures(t Transaction) error {
s.mu.RLock()
defer s.mu.RUnlock()
return s.validSignatures(t)
}
func (s *State) ValidTransaction(t Transaction) (err error) {
s.mu.RLock()
defer s.mu.RUnlock()
......
......@@ -56,11 +56,12 @@ func (t Transaction) validCoveredFields() (err error) {
len(cf.MinerFees) != 0 ||
len(cf.SiacoinOutputs) != 0 ||
len(cf.FileContracts) != 0 ||
len(cf.FileContractTerminations) != 0 ||
len(cf.StorageProofs) != 0 ||
len(cf.SiafundInputs) != 0 ||
len(cf.SiafundOutputs) != 0 ||
len(cf.ArbitraryData) != 0 {
err = errors.New("whole transaction is set but not all fields besides signatures are empty")
err = errors.New("whole transaction flag is set but not all fields besides signatures are empty")
return
}
}
......@@ -84,6 +85,10 @@ func (t Transaction) validCoveredFields() (err error) {
if err != nil {
return
}
err = sortedUnique(cf.FileContractTerminations, len(cf.FileContractTerminations)-1)
if err != nil {
return
}
err = sortedUnique(cf.StorageProofs, len(cf.StorageProofs)-1)
if err != nil {
return
......@@ -110,7 +115,7 @@ func (t Transaction) validCoveredFields() (err error) {
}
// validSignatures takes a transaction and returns an error if the signatures
// are not all valid.
// are not all valid, or if any are missing.
func (s *State) validSignatures(t Transaction) (err error) {
// Check that all covered fields objects follow the rules.
err = t.validCoveredFields()
......@@ -134,30 +139,30 @@ func (s *State) validSignatures(t Transaction) (err error) {
}
sigMap[stringID] = inSig
}
for i, input := range t.SiafundInputs {
stringID := string(input.ParentID[:])
for i, termination := range t.FileContractTerminations {
stringID := string(termination.ParentID[:])
_, exists := sigMap[stringID]
if exists {
return errors.New("siafund output spent twice in the same transaction.")
return errors.New("file contract terminated twice in the same transaction.")
}
inSig := &InputSignatures{
RemainingSignatures: input.UnlockConditions.NumSignatures,
PossibleKeys: input.UnlockConditions.PublicKeys,
RemainingSignatures: termination.TerminationConditions.NumSignatures,
PossibleKeys: termination.TerminationConditions.PublicKeys,
Index: i,
}
sigMap[stringID] = inSig
}
for i, termination := range t.FileContractTerminations {
stringID := string(termination.ParentID[:])
for i, input := range t.SiafundInputs {
stringID := string(input.ParentID[:])
_, exists := sigMap[stringID]
if exists {
return errors.New("file contract terminated twice in the same transaction.")
return errors.New("siafund output spent twice in the same transaction.")
}
inSig := &InputSignatures{
RemainingSignatures: termination.TerminationConditions.NumSignatures,
PossibleKeys: termination.TerminationConditions.PublicKeys,
RemainingSignatures: input.UnlockConditions.NumSignatures,
PossibleKeys: input.UnlockConditions.PublicKeys,
Index: i,
}
sigMap[stringID] = inSig
......@@ -226,12 +231,3 @@ func (s *State) validSignatures(t Transaction) (err error) {
return nil
}
// ValidSignatures takes a transaction and determines whether the transaction
// contains a legal set of signatures, including checking the timelocks against
// the current state height.
func (s *State) ValidSignatures(t Transaction) error {
s.mu.RLock()
defer s.mu.RUnlock()
return s.validSignatures(t)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment