Skip to content

Commit

Permalink
fix : lint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsharma committed Jun 18, 2023
1 parent 73a7fcd commit 33df2e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func NewBlockchain(c *config.Config) *Blockchain {
rpcServer := rpc.NewRPCServer(c.RPCPort, rpcDomains)

var txProcessor *executer.TxProcessor

if c.Mine && c.SignerPrivateKey != nil {
p := c.SignerPrivateKey.PublicKey
txProcessor = executer.NewTxProcessor(stateDB, c.MinFee, util.PublicKeyToAddress(&p))
Expand Down
5 changes: 5 additions & 0 deletions executer/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewTxProcessor(state *dbstore.DB, minFee *big.Int, signer *util.Address) *T
func (txp *TxProcessor) IsValid(tx *types.Transaction) bool {
from := tx.From
balance, err := txp.State.Get(dbstore.PrefixKey(dbstore.BalanceKey, from.String()))

if err != nil {
return false
}
Expand All @@ -44,6 +45,7 @@ func (txp *TxProcessor) IsValid(tx *types.Transaction) bool {
}

var nonceBig *big.Int

nonce, err := txp.State.Get(dbstore.PrefixKey(dbstore.NonceKey, from.String()))
if err != nil {
nonceBig = big.NewInt(0)
Expand Down Expand Up @@ -75,13 +77,15 @@ func (txp *TxProcessor) ProcessTx(tx *types.Transaction) error {
if err != nil {
return err
}

sendBalanceBig := new(big.Int).SetBytes(senderBalance)

// Get receiver balance.
receiverBalance, err := txp.State.Get(dbstore.PrefixKey(dbstore.BalanceKey, to.String()))
if err != nil {
return err
}

receiverBalanceBig := new(big.Int).SetBytes(receiverBalance)

// Update sender balance.
Expand All @@ -97,6 +101,7 @@ func (txp *TxProcessor) ProcessTx(tx *types.Transaction) error {
if err != nil {
return err
}

nonceBig := new(big.Int).SetBytes(nonce)
nonceBig.Add(nonceBig, big.NewInt(1))
dbBatch.Put([]byte(dbstore.PrefixKey(dbstore.NonceKey, from.String())), nonceBig.Bytes())
Expand Down
4 changes: 3 additions & 1 deletion txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (txp *TxPool) IsValid(tx *types.Transaction) bool {

from := tx.From
balance, err := txp.State.Get(dbstore.PrefixKey(dbstore.BalanceKey, from.String()))

if err != nil {
return false
}
Expand All @@ -60,6 +61,7 @@ func (txp *TxPool) IsValid(tx *types.Transaction) bool {
}

var nonceBig *big.Int

nonce, err := txp.State.Get(dbstore.PrefixKey(dbstore.NonceKey, from.String()))
if err != nil {
nonceBig = big.NewInt(0)
Expand Down Expand Up @@ -88,7 +90,7 @@ func (tp *TxPool) AddTx(tx *types.Transaction) {
}

func (tp *TxPool) AddTxs(txs []*types.Transaction) {
validTxs := make([]*types.Transaction, len(txs))
validTxs := make([]*types.Transaction, 0, len(txs))

for _, tx := range txs {
if tp.IsValid(tx) {
Expand Down

0 comments on commit 33df2e2

Please sign in to comment.