-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rahul0tripathi/ft-block-producer
Ft block producer
- Loading branch information
Showing
9 changed files
with
270 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package producer | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/rahul0tripathi/smelter/entity" | ||
) | ||
|
||
func NewTransactionContext(nonce uint64, msg ethereum.CallMsg) *types.Transaction { | ||
return types.NewTx(&types.LegacyTx{ | ||
Nonce: nonce, | ||
GasPrice: msg.GasPrice, | ||
Gas: msg.Gas, | ||
To: msg.To, | ||
Value: msg.Value, | ||
Data: msg.Data, | ||
}) | ||
} | ||
|
||
func MineBlockWithSignleTransaction( | ||
tx *types.Transaction, | ||
left uint64, | ||
prevBlockNumber *big.Int, | ||
prevBlockHash common.Hash, | ||
db postExecutionStateFetcher, | ||
txStore transactionStorage, | ||
blockStore blockStorage, | ||
) (common.Hash, *big.Int, error) { | ||
blockNumber := new(big.Int).Add(prevBlockNumber, new(big.Int).SetUint64(1)) | ||
receipt := &types.Receipt{ | ||
Type: tx.Type(), | ||
Status: 1, | ||
CumulativeGasUsed: tx.Gas() - left, | ||
// TODO: create logs bloom | ||
Bloom: types.Bloom{}, | ||
Logs: db.Logs(), | ||
TxHash: tx.Hash(), | ||
ContractAddress: *tx.To(), | ||
GasUsed: tx.Gas() - left, | ||
EffectiveGasPrice: tx.GasPrice(), | ||
BlockNumber: blockNumber, | ||
TransactionIndex: 0, | ||
} | ||
|
||
block := entity.NewBlock(prevBlockHash, blockNumber, types.Transactions{tx}, types.Receipts{receipt}) | ||
receipt.BlockHash = block.Hash() | ||
txStore.AddTransaction(tx) | ||
txStore.AddReceipt(receipt) | ||
blockStore.AddBlock(block) | ||
return block.Hash(), blockNumber, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package producer | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/rahul0tripathi/smelter/entity" | ||
) | ||
|
||
type transactionStorage interface { | ||
AddTransaction(tx *types.Transaction) | ||
AddReceipt(receipt *types.Receipt) | ||
} | ||
|
||
type postExecutionStateFetcher interface { | ||
Logs() entity.LogStorage | ||
} | ||
|
||
type blockStorage interface { | ||
AddBlock(block *types.Block) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.