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:
|
2021-06-30 10:37:33 +00:00
|
|
|
valueIn += output.value
|
2021-06-30 09:23:04 +00:00
|
|
|
|
2021-06-30 10:37:33 +00:00
|
|
|
for (_, value) in transaction.outputs:
|
|
|
|
valueOut += value
|
2021-06-30 09:23:04 +00:00
|
|
|
|
|
|
|
valueIn == valueOut
|
|
|
|
|
2021-06-30 15:09:01 +00:00
|
|
|
func hasValidTx*(store: TxStore, txHash: Hash): bool =
|
|
|
|
if txHash == store.genesis:
|
2021-06-30 09:23:04 +00:00
|
|
|
return true
|
|
|
|
|
2021-06-30 15:09:01 +00:00
|
|
|
if not store.hasTx(txHash):
|
2021-06-30 09:23:04 +00:00
|
|
|
return false
|
|
|
|
|
2021-06-30 15:09:01 +00:00
|
|
|
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)
|