99 "sync"
1010 "time"
1111
12+ "github.com/ethereum/go-ethereum/chain/types"
1213 "github.com/ethereum/go-ethereum/crypto"
1314 "github.com/ethereum/go-ethereum/ethutil"
1415 "github.com/ethereum/go-ethereum/event"
@@ -69,7 +70,7 @@ type BlockManager struct {
6970 // The last attempted block is mainly used for debugging purposes
7071 // This does not have to be a valid block and will be set during
7172 // 'Process' & canonical validation.
72- lastAttemptedBlock * Block
73+ lastAttemptedBlock * types. Block
7374
7475 events event.Subscription
7576}
@@ -117,11 +118,11 @@ func (sm *BlockManager) ChainManager() *ChainManager {
117118 return sm .bc
118119}
119120
120- func (self * BlockManager ) ProcessTransactions (coinbase * state.StateObject , state * state.State , block , parent * Block , txs Transactions ) (Receipts , Transactions , Transactions , Transactions , error ) {
121+ func (self * BlockManager ) ProcessTransactions (coinbase * state.StateObject , state * state.State , block , parent * types. Block , txs types. Transactions ) (types. Receipts , types. Transactions , types. Transactions , types. Transactions , error ) {
121122 var (
122- receipts Receipts
123- handled , unhandled Transactions
124- erroneous Transactions
123+ receipts types. Receipts
124+ handled , unhandled types. Transactions
125+ erroneous types. Transactions
125126 totalUsedGas = big .NewInt (0 )
126127 err error
127128 )
@@ -159,8 +160,9 @@ done:
159160
160161 txGas .Sub (txGas , st .gas )
161162 cumulative := new (big.Int ).Set (totalUsedGas .Add (totalUsedGas , txGas ))
162- receipt := & Receipt {ethutil .CopyBytes (state .Root ()), cumulative , nil /*bloom*/ , state .Logs ()}
163- receipt .Bloom = CreateBloom (Receipts {receipt })
163+ receipt := types .NewReceipt (state .Root (), cumulative )
164+ receipt .SetLogs (state .Logs ())
165+ receipt .Bloom = types .CreateBloom (types.Receipts {receipt })
164166
165167 // Notify all subscribers
166168 go self .eth .EventMux ().Post (TxPostEvent {tx })
@@ -178,7 +180,7 @@ done:
178180 return receipts , handled , unhandled , erroneous , err
179181}
180182
181- func (sm * BlockManager ) Process (block * Block ) (td * big.Int , msgs state.Messages , err error ) {
183+ func (sm * BlockManager ) Process (block * types. Block ) (td * big.Int , msgs state.Messages , err error ) {
182184 // Processing a blocks may never happen simultaneously
183185 sm .mutex .Lock ()
184186 defer sm .mutex .Unlock ()
@@ -195,7 +197,7 @@ func (sm *BlockManager) Process(block *Block) (td *big.Int, msgs state.Messages,
195197 return sm .ProcessWithParent (block , parent )
196198}
197199
198- func (sm * BlockManager ) ProcessWithParent (block , parent * Block ) (td * big.Int , messages state.Messages , err error ) {
200+ func (sm * BlockManager ) ProcessWithParent (block , parent * types. Block ) (td * big.Int , messages state.Messages , err error ) {
199201 sm .lastAttemptedBlock = block
200202
201203 state := parent .State ().Copy ()
@@ -215,13 +217,13 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
215217 return
216218 }
217219
218- txSha := DeriveSha (block .transactions )
220+ txSha := types . DeriveSha (block .Transactions () )
219221 if bytes .Compare (txSha , block .TxSha ) != 0 {
220222 err = fmt .Errorf ("validating transaction root. received=%x got=%x" , block .TxSha , txSha )
221223 return
222224 }
223225
224- receiptSha := DeriveSha (receipts )
226+ receiptSha := types . DeriveSha (receipts )
225227 if bytes .Compare (receiptSha , block .ReceiptSha ) != 0 {
226228 err = fmt .Errorf ("validating receipt root. received=%x got=%x" , block .ReceiptSha , receiptSha )
227229 return
@@ -238,8 +240,8 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
238240 return
239241 }
240242
241- block .receipts = receipts // although this isn't necessary it be in the future
242- rbloom := CreateBloom (receipts )
243+ // block.receipts = receipts // although this isn't necessary it be in the future
244+ rbloom := types . CreateBloom (receipts )
243245 if bytes .Compare (rbloom , block .LogsBloom ) != 0 {
244246 err = fmt .Errorf ("unable to replicate block's bloom=%x" , rbloom )
245247 return
@@ -272,7 +274,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
272274 }
273275}
274276
275- func (sm * BlockManager ) ApplyDiff (state * state.State , parent , block * Block ) (receipts Receipts , err error ) {
277+ func (sm * BlockManager ) ApplyDiff (state * state.State , parent , block * types. Block ) (receipts types. Receipts , err error ) {
276278 coinbase := state .GetOrNewStateObject (block .Coinbase )
277279 coinbase .SetGasPool (block .CalcGasLimit (parent ))
278280
@@ -285,7 +287,7 @@ func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *Block) (rec
285287 return receipts , nil
286288}
287289
288- func (sm * BlockManager ) CalculateTD (block * Block ) (* big.Int , bool ) {
290+ func (sm * BlockManager ) CalculateTD (block * types. Block ) (* big.Int , bool ) {
289291 uncleDiff := new (big.Int )
290292 for _ , uncle := range block .Uncles {
291293 uncleDiff = uncleDiff .Add (uncleDiff , uncle .Difficulty )
@@ -311,7 +313,7 @@ func (sm *BlockManager) CalculateTD(block *Block) (*big.Int, bool) {
311313// Validates the current block. Returns an error if the block was invalid,
312314// an uncle or anything that isn't on the current block chain.
313315// Validation validates easy over difficult (dagger takes longer time = difficult)
314- func (sm * BlockManager ) ValidateBlock (block , parent * Block ) error {
316+ func (sm * BlockManager ) ValidateBlock (block , parent * types. Block ) error {
315317 expd := CalcDifficulty (block , parent )
316318 if expd .Cmp (block .Difficulty ) < 0 {
317319 return fmt .Errorf ("Difficulty check failed for block %v, %v" , block .Difficulty , expd )
@@ -337,7 +339,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *Block) error {
337339 return nil
338340}
339341
340- func (sm * BlockManager ) AccumelateRewards (state * state.State , block , parent * Block ) error {
342+ func (sm * BlockManager ) AccumelateRewards (state * state.State , block , parent * types. Block ) error {
341343 reward := new (big.Int ).Set (BlockReward )
342344
343345 knownUncles := ethutil .Set (parent .Uncles )
@@ -380,7 +382,7 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Blo
380382 return nil
381383}
382384
383- func (sm * BlockManager ) GetMessages (block * Block ) (messages []* state.Message , err error ) {
385+ func (sm * BlockManager ) GetMessages (block * types. Block ) (messages []* state.Message , err error ) {
384386 if ! sm .bc .HasBlock (block .PrevHash ) {
385387 return nil , ParentError (block .PrevHash )
386388 }
0 commit comments