nim-abc/abc/txvalidation.nim

33 lines
721 B
Nim
Raw Normal View History

2021-06-30 09:23:04 +00:00
import ./txstore
func checkValue(store: TxStore, transaction: Transaction): bool =
var valueIn, valueOut = 0.u256
for (hash, owner) in transaction.inputs:
for output in store[hash].outputs:
if output.owner == owner:
valueIn += output.value
2021-06-30 09:23:04 +00:00
for (_, value) in transaction.outputs:
valueOut += value
2021-06-30 09:23:04 +00:00
valueIn == valueOut
func hasValidTx*(store: TxStore, txHash: Hash): bool =
if txHash == store.genesis:
2021-06-30 09:23:04 +00:00
return true
if not store.hasTx(txHash):
2021-06-30 09:23:04 +00:00
return false
let transaction = store[txHash]
2021-06-30 09:23:04 +00:00
if not transaction.hasValidSignature:
return false
for (hash, _) in transaction.inputs:
if not store.hasValidTx(hash):
return false
store.checkValue(transaction)