|
|
@ -21,19 +21,19 @@ func (bc *Blockchain) FindUnspentTransactions(address string) []Transaction { |
|
|
|
|
|
|
|
|
|
|
|
BreakTransaction: |
|
|
|
BreakTransaction: |
|
|
|
for _, tx := range block.Transactions { |
|
|
|
for _, tx := range block.Transactions { |
|
|
|
txID := hex.EncodeToString(tx.id) |
|
|
|
txID := hex.EncodeToString(tx.ID) |
|
|
|
|
|
|
|
|
|
|
|
idx := -1 |
|
|
|
idx := -1 |
|
|
|
if spentTXOs[txID] != nil { |
|
|
|
if spentTXOs[txID] != nil { |
|
|
|
idx = 0 |
|
|
|
idx = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
for outIdx, txOutput := range tx.txOutput { |
|
|
|
for outIdx, txOutput := range tx.TxOutput { |
|
|
|
if idx >= 0 && spentTXOs[txID][idx] == outIdx { |
|
|
|
if idx >= 0 && spentTXOs[txID][idx] == outIdx { |
|
|
|
idx++ |
|
|
|
idx++ |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if txOutput.address == address { |
|
|
|
if txOutput.Address == address { |
|
|
|
unspentTXs = append(unspentTXs, *tx) |
|
|
|
unspentTXs = append(unspentTXs, *tx) |
|
|
|
continue BreakTransaction |
|
|
|
continue BreakTransaction |
|
|
|
} |
|
|
|
} |
|
|
@ -49,8 +49,8 @@ func (bc *Blockchain) FindUTXO(address string) []TXOutput { |
|
|
|
unspentTXs := bc.FindUnspentTransactions(address) |
|
|
|
unspentTXs := bc.FindUnspentTransactions(address) |
|
|
|
|
|
|
|
|
|
|
|
for _, tx := range unspentTXs { |
|
|
|
for _, tx := range unspentTXs { |
|
|
|
for _, txOutput := range tx.txOutput { |
|
|
|
for _, txOutput := range tx.TxOutput { |
|
|
|
if txOutput.address == address { |
|
|
|
if txOutput.Address == address { |
|
|
|
UTXOs = append(UTXOs, txOutput) |
|
|
|
UTXOs = append(UTXOs, txOutput) |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
@ -68,11 +68,11 @@ func (bc *Blockchain) FindSpendableOutputs(address string, amount int) (int, map |
|
|
|
|
|
|
|
|
|
|
|
Work: |
|
|
|
Work: |
|
|
|
for _, tx := range unspentTXs { |
|
|
|
for _, tx := range unspentTXs { |
|
|
|
txID := hex.EncodeToString(tx.id) |
|
|
|
txID := hex.EncodeToString(tx.ID) |
|
|
|
|
|
|
|
|
|
|
|
for outIdx, txOutput := range tx.txOutput { |
|
|
|
for outIdx, txOutput := range tx.TxOutput { |
|
|
|
if txOutput.address == address && accumulated < amount { |
|
|
|
if txOutput.Address == address && accumulated < amount { |
|
|
|
accumulated += txOutput.value |
|
|
|
accumulated += txOutput.Value |
|
|
|
unspentOutputs[txID] = append(unspentOutputs[txID], outIdx) |
|
|
|
unspentOutputs[txID] = append(unspentOutputs[txID], outIdx) |
|
|
|
|
|
|
|
|
|
|
|
if accumulated >= amount { |
|
|
|
if accumulated >= amount { |
|
|
|