Commit 69b4b3b0 authored by David Vorick's avatar David Vorick

last minute naming changes to types package

parent 30d5edcf
......@@ -18,9 +18,9 @@ func (ct *ConsensusTester) MineInvalidSignatureBlockSet(depth int) (blocks []typ
txn.MinerFees = append(txn.MinerFees, value)
// Invalidate the signature.
byteSig := []byte(txn.Signatures[0].Signature)
byteSig := []byte(txn.TransactionSignatures[0].Signature)
byteSig[0]++
txn.Signatures[0].Signature = types.Signature(byteSig)
txn.TransactionSignatures[0].Signature = types.Signature(byteSig)
// Mine a block with this transcation.
block := ct.MineCurrentBlock([]types.Transaction{txn})
......
......@@ -114,7 +114,7 @@ func NewConsensusTester(t *testing.T, s *State) (ct *ConsensusTester) {
t.Fatal(err)
}
uc := types.UnlockConditions{
NumSignatures: 1,
RequiredSignatures: 1,
PublicKeys: []types.SiaPublicKey{
types.SiaPublicKey{
Algorithm: types.SignatureEd25519,
......
......@@ -56,14 +56,14 @@ func (ct *ConsensusTester) AddSiacoinInputToTransaction(inputT types.Transaction
CoveredFields: types.CoveredFields{},
PublicKeyIndex: 0,
}
tsigIndex := len(t.Signatures)
t.Signatures = append(t.Signatures, tsig)
tsigIndex := len(t.TransactionSignatures)
t.TransactionSignatures = append(t.TransactionSignatures, tsig)
sigHash := t.SigHash(tsigIndex)
encodedSig, err := crypto.SignHash(sigHash, ct.SecretKey)
if err != nil {
ct.Fatal(err)
}
t.Signatures[tsigIndex].Signature = types.Signature(encodedSig[:])
t.TransactionSignatures[tsigIndex].Signature = types.Signature(encodedSig[:])
return
}
......
......@@ -248,7 +248,7 @@ func (h *Host) NegotiateContract(conn modules.NetConn) (err error) {
// Add the signatures from the renter signed transaction, and then sign the
// transaction, then submit the transaction.
for _, sig := range signedTxn.Signatures {
for _, sig := range signedTxn.TransactionSignatures {
_, _, err = h.wallet.AddSignature(txnID, sig)
if err != nil {
return
......
......@@ -15,8 +15,8 @@ func (w *Wallet) timelockedCoinAddress(unlockHeight types.BlockHeight) (coinAddr
return
}
unlockConditions = types.UnlockConditions{
Timelock: unlockHeight,
NumSignatures: 1,
Timelock: unlockHeight,
RequiredSignatures: 1,
PublicKeys: []types.SiaPublicKey{
types.SiaPublicKey{
Algorithm: types.SignatureEd25519,
......@@ -60,7 +60,7 @@ func (w *Wallet) coinAddress() (coinAddress types.UnlockHash, unlockConditions t
return
}
unlockConditions = types.UnlockConditions{
NumSignatures: 1,
RequiredSignatures: 1,
PublicKeys: []types.SiaPublicKey{
types.SiaPublicKey{
Algorithm: types.SignatureEd25519,
......
......@@ -93,11 +93,11 @@ func (w *Wallet) FundTransaction(id string, amount types.Currency) (t types.Tran
CoveredFields: coveredFields,
PublicKeyIndex: 0,
}
parentTxn.Signatures = append(parentTxn.Signatures, sig)
parentTxn.TransactionSignatures = append(parentTxn.TransactionSignatures, sig)
// Hash the transaction according to the covered fields.
coinAddress := input.UnlockConditions.UnlockHash()
sigIndex := len(parentTxn.Signatures) - 1
sigIndex := len(parentTxn.TransactionSignatures) - 1
secKey := w.keys[coinAddress].secretKey
sigHash := parentTxn.SigHash(sigIndex)
......@@ -107,7 +107,7 @@ func (w *Wallet) FundTransaction(id string, amount types.Currency) (t types.Tran
if err != nil {
return
}
parentTxn.Signatures[sigIndex].Signature = types.Signature(encodedSig[:])
parentTxn.TransactionSignatures[sigIndex].Signature = types.Signature(encodedSig[:])
}
// Add the exact output to the wallet's knowledgebase before releasing the
......@@ -296,8 +296,8 @@ func (w *Wallet) SignTransaction(id string, wholeTransaction bool) (txn types.Tr
for i := range txn.ArbitraryData {
coveredFields.ArbitraryData = append(coveredFields.ArbitraryData, uint64(i))
}
for i := range txn.Signatures {
coveredFields.Signatures = append(coveredFields.Signatures, uint64(i))
for i := range txn.TransactionSignatures {
coveredFields.TransactionSignatures = append(coveredFields.TransactionSignatures, uint64(i))
}
}
......@@ -309,11 +309,11 @@ func (w *Wallet) SignTransaction(id string, wholeTransaction bool) (txn types.Tr
CoveredFields: coveredFields,
PublicKeyIndex: 0,
}
txn.Signatures = append(txn.Signatures, sig)
txn.TransactionSignatures = append(txn.TransactionSignatures, sig)
// Hash the transaction according to the covered fields.
coinAddress := input.UnlockConditions.UnlockHash()
sigIndex := len(txn.Signatures) - 1
sigIndex := len(txn.TransactionSignatures) - 1
secKey := w.keys[coinAddress].secretKey
sigHash := txn.SigHash(sigIndex)
......@@ -323,7 +323,7 @@ func (w *Wallet) SignTransaction(id string, wholeTransaction bool) (txn types.Tr
if err != nil {
return
}
txn.Signatures[sigIndex].Signature = types.Signature(encodedSig[:])
txn.TransactionSignatures[sigIndex].Signature = types.Signature(encodedSig[:])
}
// Delete the open transaction.
......@@ -346,8 +346,8 @@ func (w *Wallet) AddSignature(id string, sig types.TransactionSignature) (t type
return
}
openTxn.transaction.Signatures = append(openTxn.transaction.Signatures, sig)
openTxn.transaction.TransactionSignatures = append(openTxn.transaction.TransactionSignatures, sig)
t = *openTxn.transaction
sigIndex = uint64(len(t.Signatures) - 1)
sigIndex = uint64(len(t.TransactionSignatures) - 1)
return
}
......@@ -66,8 +66,8 @@ func generateKeys(*cobra.Command, []string) {
// Generate the unlock conditions and add them to each KeyPair object.
uc := types.UnlockConditions{
Timelock: 0,
NumSignatures: uint64(config.Siakg.RequiredKeys),
Timelock: 0,
RequiredSignatures: uint64(config.Siakg.RequiredKeys),
}
for i := range keys {
uc.PublicKeys = append(uc.PublicKeys, types.SiaPublicKey{
......@@ -132,7 +132,7 @@ func generateKeys(*cobra.Command, []string) {
}
var j int
for j < config.Siakg.RequiredKeys {
txn.Signatures = append(txn.Signatures, types.TransactionSignature{
txn.TransactionSignatures = append(txn.TransactionSignatures, types.TransactionSignature{
PublicKeyIndex: uint64(i),
CoveredFields: types.CoveredFields{WholeTransaction: true},
})
......@@ -142,7 +142,7 @@ func generateKeys(*cobra.Command, []string) {
fmt.Println(err)
return
}
txn.Signatures[j].Signature = types.Signature(sig[:])
txn.TransactionSignatures[j].Signature = types.Signature(sig[:])
i++
j++
}
......@@ -152,7 +152,7 @@ func generateKeys(*cobra.Command, []string) {
fmt.Println(err)
}
// Delete all of the signatures for the next iteration.
txn.Signatures = nil
txn.TransactionSignatures = nil
}
fmt.Printf("Success, the address for this set of keys is: %x\n", uc.UnlockHash())
......@@ -167,6 +167,6 @@ func printKey(*cobra.Command, []string) {
return
}
fmt.Printf("Found a key for a %v of %v address.\n", kp.UnlockConditions.NumSignatures, len(kp.UnlockConditions.PublicKeys))
fmt.Printf("Found a key for a %v of %v address.\n", kp.UnlockConditions.RequiredSignatures, len(kp.UnlockConditions.PublicKeys))
fmt.Printf("The address is: %x\n", kp.UnlockConditions.UnlockHash())
}
......@@ -57,7 +57,7 @@ type (
SiafundOutputs []uint64
MinerFees []uint64
ArbitraryData []uint64
Signatures []uint64
TransactionSignatures []uint64
}
// A SiaPublicKey is a public key prefixed by a Specifier. The Specifier
......@@ -96,17 +96,17 @@ type (
// must have a height >= 'Timelock'.
//
// 'PublicKeys' specifies the set of keys that can be used to satisfy the
// UnlockConditions; of these, at least 'NumSignatures' unique keys must sign
// UnlockConditions; of these, at least 'RequiredSignatures' unique keys must sign
// the transaction. The keys that do not need to use the same cryptographic
// algorithm.
//
// If 'NumSignatures' == 0, the UnlockConditions are effectively "anyone can
// unlock." If 'NumSignatures' > len('PublicKeys'), then the UnlockConditions
// If 'RequiredSignatures' == 0, the UnlockConditions are effectively "anyone can
// unlock." If 'RequiredSignatures' > len('PublicKeys'), then the UnlockConditions
// cannot be fulfilled under any circumstances.
UnlockConditions struct {
Timelock BlockHeight
PublicKeys []SiaPublicKey
NumSignatures uint64
Timelock BlockHeight
PublicKeys []SiaPublicKey
RequiredSignatures uint64
}
// Each input has a list of public keys and a required number of signatures.
......@@ -124,7 +124,7 @@ type (
// UnlockConditions object. The leaves of this tree are formed by taking the
// hash of the timelock, the hash of the public keys (one leaf each), and the
// hash of the number of signatures. The keys are put in the middle because
// Timelock and NumSignatures are both low entropy fields; they can be
// Timelock and RequiredSignatures are both low entropy fields; they can be
// protected by having random public keys next to them.
func (uc UnlockConditions) UnlockHash() UnlockHash {
tree := crypto.NewTree()
......@@ -132,14 +132,14 @@ func (uc UnlockConditions) UnlockHash() UnlockHash {
for i := range uc.PublicKeys {
tree.PushObject(uc.PublicKeys[i])
}
tree.PushObject(uc.NumSignatures)
tree.PushObject(uc.RequiredSignatures)
return UnlockHash(tree.Root())
}
// SigHash returns the hash of the fields in a transaction covered by a given
// signature. See CoveredFields for more details.
func (t Transaction) SigHash(i int) crypto.Hash {
cf := t.Signatures[i].CoveredFields
cf := t.TransactionSignatures[i].CoveredFields
var signedData []byte
if cf.WholeTransaction {
signedData = encoding.MarshalAll(
......@@ -152,9 +152,9 @@ func (t Transaction) SigHash(i int) crypto.Hash {
t.SiafundOutputs,
t.MinerFees,
t.ArbitraryData,
t.Signatures[i].ParentID,
t.Signatures[i].PublicKeyIndex,
t.Signatures[i].Timelock,
t.TransactionSignatures[i].ParentID,
t.TransactionSignatures[i].PublicKeyIndex,
t.TransactionSignatures[i].Timelock,
)
} else {
for _, input := range cf.SiacoinInputs {
......@@ -186,8 +186,8 @@ func (t Transaction) SigHash(i int) crypto.Hash {
}
}
for _, sig := range cf.Signatures {
signedData = append(signedData, encoding.Marshal(t.Signatures[sig])...)
for _, sig := range cf.TransactionSignatures {
signedData = append(signedData, encoding.Marshal(t.TransactionSignatures[sig])...)
}
return crypto.HashBytes(signedData)
......@@ -218,7 +218,7 @@ func sortedUnique(elems []uint64, max int) bool {
// true, all fields except for 'Signatures' must be empty. All fields must be
// sorted numerically, and there can be no repeats.
func (t Transaction) validCoveredFields() error {
for _, sig := range t.Signatures {
for _, sig := range t.TransactionSignatures {
// convenience variables
cf := sig.CoveredFields
fieldMaxs := []struct {
......@@ -234,7 +234,7 @@ func (t Transaction) validCoveredFields() error {
{cf.SiafundOutputs, len(t.SiafundOutputs)},
{cf.MinerFees, len(t.MinerFees)},
{cf.ArbitraryData, len(t.ArbitraryData)},
{cf.Signatures, len(t.Signatures)},
{cf.TransactionSignatures, len(t.TransactionSignatures)},
}
// Check that all fields are empty if 'WholeTransaction' is set, except
......@@ -282,7 +282,7 @@ func (t *Transaction) validSignatures(currentHeight BlockHeight) error {
}
sigMap[id] = &inputSignatures{
remainingSignatures: input.UnlockConditions.NumSignatures,
remainingSignatures: input.UnlockConditions.RequiredSignatures,
possibleKeys: input.UnlockConditions.PublicKeys,
usedKeys: make(map[uint64]struct{}),
index: i,
......@@ -296,7 +296,7 @@ func (t *Transaction) validSignatures(currentHeight BlockHeight) error {
}
sigMap[id] = &inputSignatures{
remainingSignatures: termination.TerminationConditions.NumSignatures,
remainingSignatures: termination.TerminationConditions.RequiredSignatures,
possibleKeys: termination.TerminationConditions.PublicKeys,
usedKeys: make(map[uint64]struct{}),
index: i,
......@@ -310,7 +310,7 @@ func (t *Transaction) validSignatures(currentHeight BlockHeight) error {
}
sigMap[id] = &inputSignatures{
remainingSignatures: input.UnlockConditions.NumSignatures,
remainingSignatures: input.UnlockConditions.RequiredSignatures,
possibleKeys: input.UnlockConditions.PublicKeys,
usedKeys: make(map[uint64]struct{}),
index: i,
......@@ -318,7 +318,7 @@ func (t *Transaction) validSignatures(currentHeight BlockHeight) error {
}
// Check all of the signatures for validity.
for i, sig := range t.Signatures {
for i, sig := range t.TransactionSignatures {
// check that sig corresponds to an entry in sigMap
inSig, exists := sigMap[crypto.Hash(sig.ParentID)]
if !exists || inSig.remainingSignatures == 0 {
......
......@@ -16,7 +16,7 @@ func TestUnlockHash(t *testing.T) {
Key: "fake key",
},
},
NumSignatures: 3,
RequiredSignatures: 3,
}
_ = uc.UnlockHash()
......@@ -34,7 +34,7 @@ func TestSigHash(t *testing.T) {
SiafundOutputs: []SiafundOutput{SiafundOutput{}},
MinerFees: []Currency{Currency{}},
ArbitraryData: []string{"one", "two"},
Signatures: []TransactionSignature{
TransactionSignatures: []TransactionSignature{
TransactionSignature{
CoveredFields: CoveredFields{
WholeTransaction: true,
......@@ -51,7 +51,7 @@ func TestSigHash(t *testing.T) {
SiafundOutputs: []uint64{0},
MinerFees: []uint64{0},
ArbitraryData: []uint64{0},
Signatures: []uint64{0},
TransactionSignatures: []uint64{0},
},
},
},
......@@ -106,7 +106,7 @@ func TestTransactionValidCoveredFields(t *testing.T) {
SiafundOutputs: []SiafundOutput{SiafundOutput{}},
MinerFees: []Currency{Currency{}},
ArbitraryData: []string{"one", "two"},
Signatures: []TransactionSignature{
TransactionSignatures: []TransactionSignature{
TransactionSignature{
CoveredFields: CoveredFields{
WholeTransaction: true,
......@@ -121,7 +121,7 @@ func TestTransactionValidCoveredFields(t *testing.T) {
// Second check has CoveredFields object where 'WholeTransaction' is not
// set.
txn.Signatures = append(txn.Signatures, TransactionSignature{
txn.TransactionSignatures = append(txn.TransactionSignatures, TransactionSignature{
CoveredFields: CoveredFields{
SiacoinOutputs: []uint64{0},
MinerFees: []uint64{0},
......@@ -136,7 +136,7 @@ func TestTransactionValidCoveredFields(t *testing.T) {
// Add signature coverage to the first signature. This should not violate
// any rules.
txn.Signatures[0].CoveredFields.Signatures = []uint64{1}
txn.TransactionSignatures[0].CoveredFields.TransactionSignatures = []uint64{1}
err = txn.validCoveredFields()
if err != nil {
t.Error(err)
......@@ -145,15 +145,15 @@ func TestTransactionValidCoveredFields(t *testing.T) {
// Add siacoin output coverage to the first signature. This should violate
// rules, as the fields are not allowed to be set when 'WholeTransaction'
// is set.
txn.Signatures[0].CoveredFields.SiacoinOutputs = []uint64{0}
txn.TransactionSignatures[0].CoveredFields.SiacoinOutputs = []uint64{0}
err = txn.validCoveredFields()
if err != ErrWholeTransactionViolation {
t.Error("Expecting ErrWholeTransactionViolation, got", err)
}
// Create a SortedUnique violation instead of a WholeTransactionViolation.
txn.Signatures[0].CoveredFields.SiacoinOutputs = nil
txn.Signatures[0].CoveredFields.Signatures = []uint64{1, 2}
txn.TransactionSignatures[0].CoveredFields.SiacoinOutputs = nil
txn.TransactionSignatures[0].CoveredFields.TransactionSignatures = []uint64{1, 2}
err = txn.validCoveredFields()
if err != ErrSortedUniqueViolation {
t.Error("Expecting ErrSortedUniqueViolation, got", err)
......@@ -184,7 +184,7 @@ func TestTransactionValidSignatures(t *testing.T) {
Algorithm: SignatureEntropy,
},
},
NumSignatures: 2,
RequiredSignatures: 2,
}
// Create a transaction with each type of spendable output.
......@@ -203,7 +203,7 @@ func TestTransactionValidSignatures(t *testing.T) {
txn.SiafundInputs[0].ParentID[0] = 2 // can't overlap with other objects
// Create the signatures that spend the output.
txn.Signatures = []TransactionSignature{
txn.TransactionSignatures = []TransactionSignature{
// First signatures use cryptography.
TransactionSignature{
Timelock: 5,
......@@ -222,10 +222,10 @@ func TestTransactionValidSignatures(t *testing.T) {
TransactionSignature{PublicKeyIndex: 1},
TransactionSignature{PublicKeyIndex: 1},
}
txn.Signatures[1].ParentID[0] = 1
txn.Signatures[2].ParentID[0] = 2
txn.Signatures[4].ParentID[0] = 1
txn.Signatures[5].ParentID[0] = 2
txn.TransactionSignatures[1].ParentID[0] = 1
txn.TransactionSignatures[2].ParentID[0] = 2
txn.TransactionSignatures[4].ParentID[0] = 1
txn.TransactionSignatures[5].ParentID[0] = 2
sigHash0 := txn.SigHash(0)
sigHash1 := txn.SigHash(1)
sigHash2 := txn.SigHash(2)
......@@ -241,9 +241,9 @@ func TestTransactionValidSignatures(t *testing.T) {
if err != nil {
t.Fatal(err)
}
txn.Signatures[0].Signature = Signature(sig0[:])
txn.Signatures[1].Signature = Signature(sig1[:])
txn.Signatures[2].Signature = Signature(sig2[:])
txn.TransactionSignatures[0].Signature = Signature(sig0[:])
txn.TransactionSignatures[1].Signature = Signature(sig1[:])
txn.TransactionSignatures[2].Signature = Signature(sig2[:])
// Check that the signing was successful.
err = txn.validSignatures(10)
......@@ -253,21 +253,21 @@ func TestTransactionValidSignatures(t *testing.T) {
// Corrupt one of the sigantures.
sig0[0]++
txn.Signatures[0].Signature = Signature(sig0[:])
txn.TransactionSignatures[0].Signature = Signature(sig0[:])
err = txn.validSignatures(10)
if err == nil {
t.Error("Corrupted a signature but the txn was still accepted as valid!")
}
sig0[0]--
txn.Signatures[0].Signature = Signature(sig0[:])
txn.TransactionSignatures[0].Signature = Signature(sig0[:])
// Fail the validCoveredFields check.
txn.Signatures[0].CoveredFields.SiacoinInputs = []uint64{33}
txn.TransactionSignatures[0].CoveredFields.SiacoinInputs = []uint64{33}
err = txn.validSignatures(10)
if err == nil {
t.Error("failed to flunk the validCoveredFields check")
}
txn.Signatures[0].CoveredFields.SiacoinInputs = nil
txn.TransactionSignatures[0].CoveredFields.SiacoinInputs = nil
// Double spend a SiacoinInput, FileContractTermination, and SiafundInput.
txn.SiacoinInputs = append(txn.SiacoinInputs, SiacoinInput{UnlockConditions: UnlockConditions{}})
......@@ -290,23 +290,23 @@ func TestTransactionValidSignatures(t *testing.T) {
txn.SiafundInputs = txn.SiafundInputs[:len(txn.SiafundInputs)-1]
// Add a frivilous signature
txn.Signatures = append(txn.Signatures, TransactionSignature{})
txn.TransactionSignatures = append(txn.TransactionSignatures, TransactionSignature{})
err = txn.validSignatures(10)
if err != ErrFrivilousSignature {
t.Error(err)
}
txn.Signatures = txn.Signatures[:len(txn.Signatures)-1]
txn.TransactionSignatures = txn.TransactionSignatures[:len(txn.TransactionSignatures)-1]
// Replace one of the cryptography signatures with an always-accepted
// signature. This should get rejected because the always-accepted
// signature has already been used.
tmpTxn0 := txn.Signatures[0]
txn.Signatures[0] = TransactionSignature{PublicKeyIndex: 1}
tmpTxn0 := txn.TransactionSignatures[0]
txn.TransactionSignatures[0] = TransactionSignature{PublicKeyIndex: 1}
err = txn.validSignatures(10)
if err != ErrPublicKeyOveruse {
t.Error(err)
}
txn.Signatures[0] = tmpTxn0
txn.TransactionSignatures[0] = tmpTxn0
// Fail the timelock check for signatures.
err = txn.validSignatures(4)
......@@ -315,12 +315,12 @@ func TestTransactionValidSignatures(t *testing.T) {
}
// Try to spend an entropy signature.
txn.Signatures[0] = TransactionSignature{PublicKeyIndex: 2}
txn.TransactionSignatures[0] = TransactionSignature{PublicKeyIndex: 2}
err = txn.validSignatures(10)
if err != ErrEntropyKey {
t.Error(err)
}
txn.Signatures[0] = tmpTxn0
txn.TransactionSignatures[0] = tmpTxn0
// Insert a malformed public key into the transaction.
txn.SiacoinInputs[0].UnlockConditions.PublicKeys[0].Key = "malformed"
......@@ -331,16 +331,16 @@ func TestTransactionValidSignatures(t *testing.T) {
txn.SiacoinInputs[0].UnlockConditions.PublicKeys[0].Key = string(pk[:])
// Insert a malformed signature into the transaction.
txn.Signatures[0].Signature = "malformed"
txn.TransactionSignatures[0].Signature = "malformed"
err = txn.validSignatures(10)
if err == nil {
t.Error(err)
}
txn.Signatures[0] = tmpTxn0
txn.TransactionSignatures[0] = tmpTxn0
// Try to spend a transaction when not every required signature is
// available.
txn.Signatures = txn.Signatures[1:]
txn.TransactionSignatures = txn.TransactionSignatures[1:]
err = txn.validSignatures(10)
if err != ErrMissingSignatures {
t.Error(err)
......
......@@ -57,7 +57,7 @@ type (
SiafundOutputs []SiafundOutput
MinerFees []Currency
ArbitraryData []string
Signatures []TransactionSignature
TransactionSignatures []TransactionSignature
}
// A SiacoinInput consumes a SiacoinOutput and adds the siacoins to the set of
......
......@@ -418,10 +418,10 @@ func TestTransactionStandaloneValid(t *testing.T) {
txn.SiacoinInputs = nil
// Violate validSignatures
txn.Signatures = []TransactionSignature{TransactionSignature{}}
txn.TransactionSignatures = []TransactionSignature{TransactionSignature{}}
err = txn.StandaloneValid(0)
if err == nil {
t.Error("failed to trigger validSignatures error")
}
txn.Signatures = nil
txn.TransactionSignatures = nil
}
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