-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
49 lines (37 loc) · 1.43 KB
/
transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package state
import (
"github.com/chokey2nv/blockchain/foundation/blockchain/database"
)
// UpsertWalletTransaction accepts a transaction from a wallet for inclusion.
func (s *State) UpsertWalletTransaction(signedTx database.SignedTx) error {
// CORE NOTE: It's up to the wallet to make sure the account has a proper
// balance and this transaction has a proper nonce. Fees will be taken if
// this transaction is mined into a block it doesn't have enough money to
// pay or the nonce isn't the next expected nonce for the account.
// Check the signed transaction has a proper signature, the from matches the
// signature, and the from and to fields are properly formatted.
if err := signedTx.Validate(s.genesis.ChainID); err != nil {
return err
}
const oneUnitOfGas = 1
tx := database.NewBlockTx(signedTx, s.genesis.GasPrice, oneUnitOfGas)
if err := s.mempool.Upsert(tx); err != nil {
return err
}
s.Worker.SignalShareTx(tx)
s.Worker.SignalStartMining()
return nil
}
// UpsertNodeTransaction accepts a transaction from a node for inclusion.
func (s *State) UpsertNodeTransaction(tx database.BlockTx) error {
// Check the signed transaction has a proper signature, the from matches the
// signature, and the from and to fields are properly formatted.
if err := tx.Validate(s.genesis.ChainID); err != nil {
return err
}
if err := s.mempool.Upsert(tx); err != nil {
return err
}
s.Worker.SignalStartMining()
return nil
}