Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Might not be an issue, have a question (Part 4) #83

Open
Cijin opened this issue Mar 28, 2022 · 1 comment
Open

Might not be an issue, have a question (Part 4) #83

Cijin opened this issue Mar 28, 2022 · 1 comment

Comments

@Cijin
Copy link

Cijin commented Mar 28, 2022

Noticed something in the method Part 4: FindUnspentTransactions. Maybe I'm missing something obvious but can someone please correct me if I'm wrong.

In the block of code below, shouldn't we get the spent outputs before we loop through tx.Vout? Otherwise spentTXOs[txID] will always be nil?

for _, tx := range block.Transactions {
			txID := hex.EncodeToString(tx.ID)

		Outputs:
			for outIdx, out := range tx.Vout {
				// Was the output spent?
				if spentTXOs[txID] != nil {
					for _, spentOut := range spentTXOs[txID] {
						if spentOut == outIdx {
							continue Outputs
						}
					}
				}

				if out.CanBeUnlockedWith(address) {
					unspentTXs = append(unspentTXs, *tx)
				}
			}

			if tx.IsCoinbase() == false {
				for _, in := range tx.Vin {
					if in.CanUnlockOutputWith(address) {
						inTxID := hex.EncodeToString(in.Txid)
						spentTXOs[inTxID] = append(spentTXOs[inTxID], in.Vout)
					}
				}
			}
		}
@Cijin Cijin changed the title Might not be an issue, have a question Might not be an issue, have a question (Part 4) Mar 28, 2022
@Anmilover
Copy link

Anmilover commented Mar 28, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants