Commit a50b1c08 authored by David Vorick's avatar David Vorick

rename OutputID() to SiacoinOutputID()

parent a2d8ce89
......@@ -10,6 +10,11 @@ import (
// seg faults by throwing covered fields objects at the state which point to
// nonexistent objects in the transaction.
var (
InvalidSignatureErr = errors.New("signature is invalid")
MissingSignaturesErr = errors.New("transaction has inputs with missing signatures")
)
// Each input has a list of public keys and a required number of signatures.
// InputSignatures keeps track of which public keys have been used and how many
// more signatures are needed.
......@@ -168,10 +173,12 @@ func (s *State) validSignatures(t Transaction) (err error) {
sigHash := t.SigHash(i)
if !crypto.VerifyBytes(sigHash[:], decodedPK, decodedSig) {
return errors.New("signature did not verify")
return InvalidSignatureErr
}
default:
return errors.New("public key algorithm not recognized")
// If we don't recognize the identifier, assume that the signature
// is valid; do nothing. This allows more signature types to be
// added through soft forking.
}
// Subtract the number of signatures remaining for this input.
......@@ -181,7 +188,7 @@ func (s *State) validSignatures(t Transaction) (err error) {
// Check that all inputs have been sufficiently signed.
for _, reqSigs := range sigMap {
if reqSigs.RemainingSignatures != 0 {
return errors.New("some inputs are missing signatures")
return MissingSignaturesErr
}
}
......
......@@ -130,7 +130,7 @@ func (s *State) applyTransaction(t Transaction) (outputDiffs []OutputDiff, contr
// Sanity check - the output must not exist within the state, should
// have already been verified.
if DEBUG {
_, exists := s.unspentOutputs[t.OutputID(i)]
_, exists := s.unspentOutputs[t.SiacoinOutputID(i)]
if exists {
panic("applying a transaction with an invalid new output")
}
......@@ -138,10 +138,10 @@ func (s *State) applyTransaction(t Transaction) (outputDiffs []OutputDiff, contr
diff := OutputDiff{
New: true,
ID: t.OutputID(i),
ID: t.SiacoinOutputID(i),
Output: output,
}
s.unspentOutputs[t.OutputID(i)] = output
s.unspentOutputs[t.SiacoinOutputID(i)] = output
outputDiffs = append(outputDiffs, diff)
}
......
......@@ -244,10 +244,11 @@ func (t Transaction) FileContractID(i int) ContractID {
))
}
// OutputID gets the id of an output in the transaction, which is derived from
// marshalling all of the fields in the transaction except for the signatures
// and then appending the string "siacoin output" and the index of the output.
func (t Transaction) OutputID(i int) OutputID {
// SiacoinOutputID gets the id of an output in the transaction, which is
// derived from marshalling all of the fields in the transaction except for the
// signatures and then appending the string "siacoin output" and the index of
// the output.
func (t Transaction) SiacoinOutputID(i int) OutputID {
return OutputID(hash.HashAll(
SiacoinOutputIdentifier,
t.SiacoinInputs,
......
......@@ -131,18 +131,18 @@ func (tp *TransactionPool) addTransaction(t consensus.Transaction) {
// Sanity check - this output should not already exist in newOutputs or
// outputs.
if consensus.DEBUG {
_, exists := tp.newOutputs[t.OutputID(i)]
_, exists := tp.newOutputs[t.SiacoinOutputID(i)]
if exists {
panic("trying to add an output that already exists?")
}
_, exists = tp.outputs[t.OutputID(i)]
_, exists = tp.outputs[t.SiacoinOutputID(i)]
if exists {
panic("trying to add an output that already exists?")
}
}
tp.outputs[t.OutputID(i)] = output
tp.newOutputs[t.OutputID(i)] = ut
tp.outputs[t.SiacoinOutputID(i)] = output
tp.newOutputs[t.SiacoinOutputID(i)] = ut
}
tp.addTransactionToTail(ut)
......
......@@ -98,7 +98,7 @@ func (tp *TransactionPool) OutputDiffs() (diffs []consensus.OutputDiff) {
for i, output := range txn.SiacoinOutputs {
diff := consensus.OutputDiff{
New: true,
ID: txn.OutputID(i),
ID: txn.SiacoinOutputID(i),
Output: output,
}
diffs = append(diffs, diff)
......
......@@ -67,7 +67,7 @@ func (tp *TransactionPool) update() {
// Find any transactions in our set that are dependent on this
// transaction.
for i := range txn.SiacoinOutputs {
dependent, exists := tp.usedOutputs[txn.OutputID(i)]
dependent, exists := tp.usedOutputs[txn.SiacoinOutputID(i)]
if exists {
ut.dependents[dependent] = struct{}{}
dependent.requirements[ut] = struct{}{}
......
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